Hi Ladislav,

Are you trying to get a free online tutorial in REBOL? Be my guest:

you wrote:
>let me introduce another example:
>
>f1: func [x] [:x]
>f2: :type?
>block1: append copy [do func [x] [print "OK"]] :f1
>== [do func [x] [print "OK"] func [x][:x]]
>block2: append copy [do func [x] [print "OK"]] :f2
>== [do func [x] [print "OK"] native]
>do block1
>** Script Error: none is missing its x argument.
>** Where: do func [x] [print "OK"] func [x][:x]
>do block2
>OK

Now, why on earth does block2 not fail with an error message demanding an
argument? Because type? accepts no argument as an argument and returns the
type unset!:

Here is the REBOL console responding to type? without an argument:

>> type?
== unset!

Since type? accepts no argument and simply returns unset!, your function
f2, which you assigned as a reference to type's native function does not
break down in tears when you do block2.

Are you getting any of this?

I may invent a test for you and issue you a REBOL programmer certificate
based on our dialogs if you pass! Be warned!

Elan

>
>> Hi Ladislav,
>>
>> let me introduce my twin cousins, Tom and Sam:
>>
>
>[L]
>(my guess):
>
>tom: [func [x] [print "OK"]]
>sam: reduce tom
>[/L]
>
>> >> 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 ...
>;-)
>
>[L]
>>> source probe
>probe: func [
>    {Prints a molded, unevaluated value and returns the same value.}
>    value
>][
>    print mold :value :value
>]
>
>Now I can see, what's unevaluated: the word VALUE in the PROBE's code. There
>are no means in Rebol how to unevaluate other datatypes, just words have the
>means.
>
>(compare these):
>
>word
>:word
>
>or, more complicated:
>
>do func ['arg] [print "OK"] word
>
>Where WORD surely doesn't get evaluated, but I was informed, that the latter
>is considered a bad practice and should be eliminated, because there is a
>lot of hard to detect bugs that can be hidden behind similar code...
>
>If I do this:
>
>probe a
>>> probe a
>** Script Error: a has no value.
>** Where: probe a
>
>I see a trial to evaluate the word A
>
>and:
>
>mold first tom
>== "func"
>mold first sam
>== {func [x][print "OK"]}
>
>Even though we get a FUNCTION! datatype, it doesn't get evaluated, evaluated
>are only the words FIRST and SAM
>
>{
>For those, who are interested:
>
>There is an uneasy terminology problem. If speaking about PRINT, there is
>nothing wrong to say:
>
>"PRINT is a function, such that..." But see this code (not suggested to use
>regularly!):
>
>otherword: :print
>print: 17
>
>Would you still say PRINT is a function...? Of course, not, even though the
>printing function, originally named as PRINT has neither disappeared, nor
>has been copied (although one is frequently tempted to use that terminologic
>nonsense to describe what happened...).
>
>What happened?
>
>>From the perspective of words OTHERWORD and PRINT you can say that they just
>changed their meaning.
>
>>From the perspective of the printing function you can say that it:
>1) took another name OTHERWORD (so the function had two names: PRINT and
>OTHERWORD)
>2) lost the name PRINT (so now it has only the name OTHERWORD)
>}
>[/L]
>
>>
>> >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.
>
>[L]
>in fact, not values, but the argument-word VALUE of the type WORD! in the
>body of PROBE is unevaluated
>[/L]
>
>>
>> >
>> >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 datatype 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.
>
>[L]
>I would suggest not to mix apples and pears
>
>expression is surely not a datatype...
>[/L]
>
>> 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]
>> ]
>>
>
>[L]
>deleted En passant...
>[/L]
>
>> >> 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 ...
>
>[L]
>I would describe it as follows:
>what happens is that Rebol evaluates a word FUNC. (Nothing more or less),
>which means, that if it is a name for a function (i.e. FUNCTION! datatype),
>it *do* -es it, where *do* is actually a C (or machine code, if you prefer)
>representation of DO
>[/L]
>
>>
>> 2. ... whenever a function is encountered, the expressions contained in
>the
>> body of the function are evaluated.
>
>[L]
>if that would have been true, I wouldn't have any means to stop the
>FUNCTION! datatype values from evaluation..., but, fortunately for me,
>things are not that bad...
>[/L]
>
>
>> 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?
>
>[L]
>That is a question I prefer not to be forced to ask and that is why I call
>the unexpected evaluation a bug...
>[/L]
>
>>
>> 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
>>
>
>thanks for the discussion
>
>Ladislav
>
>
>
>

Reply via email to