On 7/30/05, Tim Johnson <[EMAIL PROTECTED]> wrote:
>=20
> 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!
>=20

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.=20
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=20
  actions: [  "something" [.. ] "something-else" [..]  ] =20
  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.. )


>  any help would be appreciated. I'd hate to do all that 'switch coding.
>  thanks
>  tim
>=20
>=20
> --
> Tim Johnson <[EMAIL PROTECTED]>
>       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.
>=20
>=20


--=20
-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.

Reply via email to