1

Consider:

>> print max 5 6 7 8
6
== 8

The documentation states that max only takes two arguments, so I understand the first line. But from the second line it looks like the interpreter is still able to find the max of an arbitrary number of args.

What's going on here? What is the difference between the two results returned? Is there a way to capture the second one?

4

2 回答 2

5

I don't really know Rebol but what I do notice is that you're using print inside of th REPL. The first output is from print, which is outputting the result of max 5 6. The second output is from the REPL, which is outputting the value of your whole expression — which is maybe just the last item in the list? If you changed the order of your inputs, I bet you would see a different result.

于 2013-03-30T16:11:25.497 回答
2

max is an abbreviation for maximum. As @hobbs correctly guessed, it takes two arguments, and what you're seeing is just the evaluator's logic of turning the crank...and becoming equal to the last value in the expression. In this case you're not using that result, so the interpreter shows it to you with "==". But you could have assigned that whole expression to a variable (for instance).

What you were intending is something that gets the maximum value out of a series. In the DO dialect all functions have fixed arity, and the right way to design such a beast would be to make it take one argument...the series.

Such a thing does exist, though there isn't an abbreviation...

>> print maximum-of [5 6 7 8]
8
于 2013-03-30T17:13:10.357 回答