[REBOL] Re: Binding problem with 'do
From: tim::johnsons-web::com at: 31-Jul-2005 8:46
* Ladislav Mecir <[lmecir--mbox--vol--cz]> [050731 02:18]:
> > 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?
Hi Ladislav:
Boy am I behind in docs! What I have doesn't have any gotchas.
Can you point me to those docs?
> 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]
That's almost pythonistic in it's engineering (from me that's a
complement) :-). However, if I understand you correctly, it would
be as large and repetitive as the original switch.
> 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
I would upon recoding, place all type handlers in a context with
the same name as the type.
;Then replace
append output do type name layout
;; with
append output type-handler/:type name layout
Or even create a 'name and 'layout member for the type-handler
context - to cut down on the interface specs for the methods.
For the time being, the solution was to use
do compose[append output (to-word join "do-" type) name layout]]
;; but a formal type-handler context is more professional, methinks
Regards
tim
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.alaska-internet-solutions.com