[REBOL] Re: Binding problem with 'do
From: volker:nitsch:gmai:l at: 31-Jul-2005 18:41
Hi Ladislav, Tim, all ;)
On 7/31/05, Ladislav Mecir <[lmecir--mbox--vol--cz]> wrote:
> Hi Tim,
> >I'm working with a switch that has a lot of repetitive patterns:
[snip stuff about generating code-strings and doing them]
> 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
Disclaimer: "beginners" does not mean "programming beginners" or
Tims code surely produces the results he wants :)
Means "not experts in the deeper tricks of rebol".
I can understand "Beginners" doing it the string way.
To do it the "professional way", one needs some knowledge about some functions.
Like 'in and 'to and 'compose (/only /deep) and 'reduce (/only)
subtleties with pathes:
did/do not work everywhere, like in parse or get etc. "joined" words do.
How to get a function out of a path? :a-function works. :a/function executes it.
Building a string works fine until you you use own contexts.
Which "beginners" don't do anyway. And a
rejoin ["append output to-" type]
may be easier to read as
compose[append output (to-word join "to-" type)]
(Hint hint hint: Don't read those sources, add a 'probe, run it, look
Which is the first way they would try, before restructuring the data
as in your example.
Problems come when you get deeper.
Start using contexts or strive for performance.
Or just want to do it "right" ;)
Maybe we need some Tutorial how to join code the "right" way?
Maybe some people who join strings could post some examples,
and us syntax-gurus try to explain improvements?
With some explanation what they archive
("picking things from somewhere by name")
Any problem in computer science can be solved with another layer of
indirection. But that usually will create another problem.