[REBOL] Re: Binding problem with 'do
From: tim::johnsons-web::com at: 30-Jul-2005 10:23
* Volker Nitsch <[volker--nitsch--gmail--com]> [050730 09:39]:
> On 7/30/05, Tim Johnson <[tim--johnsons-web--com]> wrote:
> >
> > 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
> > ]
> > ]
> > code: [append output do-text name layout ] ;; dump from ?? code
> > ;; some abbreviation of code here, of course
> > ;; with the second method, rebol stops me with the following error
> > ;; message:
> > output has no value
> > ;; say what? I thought 'load was supposed to bind words to global
> > ;; context!
> >
>
> This works:
> !>> do probe load rejoin["pri" "nt 1" " + 1"]
> [print 1 + 1
> ]
> 2
>
> So either you have 'output local, or the error-message is misleading.
> Because here lurks trouble:
> foreach [name layout] ;; makes the words implicitely local
> and then
> "append output do-" type " name layout" ;; uses global words.
>
> Some thinks coming to my mind:
> try
> do bind code 'output
> that should change the error-message, see above ;)
> code: compose[append output (to-word join "do-" type) name layout]
> that keeps more bindings.
> I would think about splitting the "do-something" in some kind of path too,
> like
> actions: [ "something" [.. ] "something-else" [..] ]
> code: compose[append output (actions/:type) name layout]
> do code
> and from there, why composing first?
> repend output[actions/:type name layout]
> Or, if you don't want to change all the "do-*",
> repend output [ to-word join "do-" type name layout ]
>
> ( I hope i made no mistakes, nothing tested.. )
You nailed it!
I had to bind 'layout as well. Dunno why.
;; ......
code: load cat["append output do-" type " name layout"
bind code 'output
bind code 'layout
Thanks very much.
tim
> > any help would be appreciated. I'd hate to do all that 'switch coding.
> > thanks
> > tim
> >
> >
> > --
> > Tim Johnson <[tim--johnsons-web--com]>
> > http://www.alaska-internet-solutions.com
> > --
> > To unsubscribe from the list, just send an email to
> > lists at rebol.com with unsubscribe as the subject.
> >
> >
>
> --
> -Volker
>
> "Any problem in computer science can be solved with another layer of
> indirection. But that usually will create another problem." David
> Wheeler
> --
> 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