Hi Ladislav,
let me introduce my twin cousins, Tom and Sam:
>> source tom
tom: [func [x] [print "OK"]]
>> source sam
sam: [func [x][print "OK"]]
>> type? do tom
== function!
>> type? do sam
** Script Error: none is missing its x argument.
** Where: func [x][print "OK"]
Why? Here's the explanation:
You wrote:
>And, please, don't explain to me, that a function shall be evaluated. It
>shall not:
>probe third block2
>func [x][print "OK"]
>(a function, no evaluation, no missing argument...)
>
Look, Ladisalv, what REBOL says:
>> help probe
Prints a molded, unevaluated value and returns the same value.
Arguments:
value --
Note the word *unevaluated*! Always helps to know what you're doing ... ;-)
>Evaluation is in doc's reserved for words not for other datatypes.
Oh, really?
Note that the help text for probe spoke of unevaluated VALUES.
>
>Cf:
>
>"The most common way to get the value of a word is to evaluate it (execute
>it or get its value). "
>You see? WORD is the data that is evaluated, not FUNCTION!
Yes, the word evaluation may be used while referring to words! That does
NOT mean that the word evaluation is RESERVED for use with words.
Evaluation is the word used to describe what REBOL does with expressions
for instance: REBOL evaluates expressions. The idea that expressions are
evaluated is not exclusive to REBOL. Other - notably functional programming
functions - use the same terminology. It's not all that exotic and I am
surprised you are not familiar with the usage.
For instance, given the expression:
f: func [x] [print "OK"]
REBOL *evaluates* the expression func [x] [print "OK"].
At the center of your problem is the fact REBOL uses the same identical
notation for two things:
1. as an expression to create functions
2. as the representation of functions that have already been created.
Looking at the sequence of symbols:
func [x] [print "OK"]
we cannot tell, whether
1. this is an expression, which, when evaluated, will return a new
function, or whether
2. this is the representation of an existing, already previously created
function, which, when evaluated will consume its argument and complain, if
no argument is provided.
That is the explanation why the twins tom and sam even though they look
alike, can (and in my example do) behave differently.
Repeat in slow motion:
1. func is a REBOL word. When the REBOL word func is evaluated, it does the
following:
>> source func
func: func [
"Defines a user function with given spec and body." [catch]
spec [block!] {Help string (opt) followed by arg words (and opt type
and string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
En passant, note that func is defined as a func
func: func [ ...
Ever stopped to wonder how a word can be defined by evaluating that same
word being defined itself? How can func be defined AS a func?
Easy, the word 'func on the left is not being defined. It's value is being
reported. The word func on the right is part of the notation describing
func's value as a function.
What the REBOL word 'func does is, it evaluates the expression
make function! spec body
which in turn returns a function.
Thus, when I do the following:
>> f: func [x] [ print "OK"]
what happens is that REBOL dereferences the word func, encounters a
function, namely the function referenced by the word 'func and ...
2. ... whenever a function is encountered, the expressions contained in the
body of the function are evaluated. I use the abbreviated form "the
function is evaluated" to express that the expressions contained in the
function's body are evaluated. (At times I use the expression "the function
is evaluated", when the function being evaluated is the one referenced by
the word 'func. You'll have to figure that one out by context.
So at times the function being evaluated may be the function referenced by
the word 'func, at other times the function being evaluated may be the
function that was returned by the function referenced by the word func, in
either case "function is evaluated" means that the expressions in the
function's body are evaluated. Enough of this.)
As a result of evaluating the expresssion
>> f: func [x] [ print "OK" ]
REBOL creates a function. When I now say:
>> probe :f
func [x][print "OK"]
REBOL displays func [x] [print "OK"]
Comments:
>> f: func [x] [ print "OK" ]
1. Here func [x] [ print "OK" ] is an expression.
2. The expression func [x] [ print "OK" ] will be evaluated.
3. The word 'func will be dereferenced.
4. The word evaluates to the function
func [
"Defines a user function with given spec and body." [catch]
spec [block!] {Help string (opt) followed by arg words (and opt type
and string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
5. The expression in the body of this function will be evaluated, after the
arguments in the argument block have been bound.
6. The expression being evaluated is
make function! spec body
which returns a function.
7. f will be assigned as a reference to that function.
>> f: func [x] [ print "OK" ]
>> probe :f
func [x][print "OK"]
Comment:
1. Note that in my input I used spaces between the opening and the closing
brackets: [ print "OK" ].
2. Note that these spaces are not duplicated in the output provided by probe.
3. Let's compare:
>> f: make function! [x] [ print "OK " ]
>> probe :f
func [x][print "OK "]
Note that here I did not use the word func to create a function and instead
used the word make in combination with the datatype designator function!.
Probe again returned
func [x] [print "OK"]
That is because probe is not duplicating my input. It uses the same
notation, commonly used to implement an *expression* that evaluates to a
function, it uses that same notation to display the value referenced by f,
which is a function, which has already been created.
My argument here is that by looking at REBOL's dislay, you cannot
distinguish whether func [] [something or other] is an expression
constructing a function before that expression has been evaluated,
therefore before the function has been constructed, or whether it is the
notation used to represent a function - *after* the expression creating
that function was already *previously* evaluated.
What is this:
func [x] [print "OK"]
1. An expression, whose evaluation will construct a function by using the
word make in conjunction with the type designator function!?
2. Or is it a representation of the function, after the word 'func was
dereferenced, after the expression make function! was already evaluated?
do [ func [x] [print "OK"] ]
What will happen when the expression do [ func[x] [print "OK"] ]
instruction is executed?
1. func [x] is an expression. Func will be dereferenced. It will evaluate
to the function
func: func [
"Defines a user function with given spec and body." [catch]
spec [block!] {Help string (opt) followed by arg words (and opt type
and string)}
body [block!] "The body block of the function"
][
throw-on-error [make function! spec body]
]
and therefore do will return a newly constructed function.
2. func [x] [print "OK"] is the representation of a function that was
already previously constructed. That function will be evaluated, i.e. the
expressions in the body of the function will be evaluated, after the
argument x of the function is bound to an argument.
If it's 1 the expression will succeed. If it's 2 the expression will fail
because we do not provide an argument:
Hope this helps and stop yelling at me,
Elan