Hi Tim,

>I'm working with a switch that has a lot of repetitive patterns:
>i.e.:
>switch/default type[
>    "button"    [append auto do-button name layout]
>    "checkbox"  [append auto do-checkbox name layout]
>    "time"      [append auto do-time name layout]
>    "hidden"    [append auto do-hidden name layout]
>    "radio"     [append auto do-radio name layout]
>;; ... which is tedious. But works
>;; Now I want to simplify using 'load and 'do.
>;; As in the following 
>    output: copy []
>    foreach plist glbs/plists[
>        foreach [name layout] plist[
>            type: select layout "type"
>            code: load rejoin["append output do-" type " name layout"]
>            ?? code   ;; see code "dump" below
>            do code
>        ]
>    ]
>  
>
...snip...

that load rejoin [...] is a "beginner's gotcha" described in the doc. It 
brings more problems that it can solve. Don't use "command strings" when 
you don't have to, always use blocks - it is faster, safer and simpler. 
What about this one?

type-handler: make object! [
    button: func [name layout] [print "this is do-button" 'do-button]
    checkbox: func [name layout] [print "this is do-checkbox" 'do-checkbox]
    time: func [name layout] [print "this is do-time" 'do-time]
    hidden: func [name layout] [print "this is do-hidden" 'do-hidden]
    radio: func [name layout] [print "this is do-radio" 'do-radio]
]

; usage:

output: copy []
foreach plist glbs/plists [
    foreach [name layout] plist [
       type: in type-handler to word! select layout "type"
       append output do type name layout
    ]
]

-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to