[REBOL] Re: Binding problem with 'do
From: tim::johnsons-web::com at: 1-Aug-2005 8:19
* Ladislav Mecir <[lmecir--mbox--vol--cz]> [050801 02:38]:
> Ladislav Mecir napsal(a):
>
> >I think, that it is necessary to articulate the "rule of thumb"
> >regarding string execution:
> >
> >*Do not transform Rebol code to string, if you are going to evaluate it*.
> >
> >Let's have a look at the original code:
> >
> > code: load rejoin["append output do-" type " name layout"]
> > ?? code ;; see code "dump" below
> > do code
> >
> >So, what is wrong about it? The wrong part is, that there is a
> >transformation of legal Rebol code [append output do-type name layout]
> >to string and back again, while the only thing that had to be
> >transformed was the do-type part and it had to be transformed *from*
> >string, i.e. in the opposite direction.
> >
> >Is that understandable enough for less experienced readers?
> >
> >-L
> >
> >
> Appendix: the code above is a wrong way, so what is the "right
> beginner's way" of doing things in this case?
>
> Here is the simplest way I came to:
>
> ; transform the type string to a word and get the value of it
> do-type: get to word! join "do-" type
> ; evaluate the code
> append output do-type name layout
>
> *Warning! because the do-type "translation" uses TO WORD!, the word
> created this way will be global, while the original intention of the
> programmer might have been to use e.g. 'do-checkbox word, which was
> meant to be local.*
It should be noted in this case that all of the do-* subroutines
*are* global. Makes it moot in this case, but your attention to this
issue is very well taken, and I hope that this can be used as further
examples to illustrate the many subtleties in rebol evaluation.
I note that rebol and Common Lisp have much in common. In fact, Carl
states that Lisp is an influence on rebol. And part of the
similarities is the great variety of ways that sympols and lists
(blocks) of symbols can be evaluated. Lisp, however, has a larger
variety of 'operators' and also has a larger code base. There is more
documentation and more of example code base available.
In sum evaluation is the "agony and ecstasy of rebol" and probably
needs more attention in documentation and illustration.
newbies (and that's me after 5 years) could be well advised to
analyze the dynamically composed code closely and look out for
"leaks" such as could be created in this example because they
can raise bloody hell somewhere down the execution path.
Thanks
Good thread
tim
> How to make the code more "bulletproof", i.e. not being "caught" by the
> fact, that TO WORD! creates globals? Here is an improvement:
>
> ; transform the type string to a do-... word in the same context as
> the 'do-radio word is and get its value
> do-type: get bind to word! join "do-" type 'do-radio
> ; evaluate the code
> append output do-type name layout
>
> Hope it will be of some use.
>
> -Ladislav
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com