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.*

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.

Reply via email to