Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Speeding up code

From: joel:neely:fedex at: 20-Feb-2002 23:23

My sympathies! :-/ [SunandaDH--aol--com] wrote:
> I'm being punished for it now by having to reinstall everything > on the machine from the opsys upwards. I guess it got jealous > too and trashed itself. >
Been there. Done that. Don't want to go there again.
> There's some oddity going on here -- no doubt explained in the > core manual (which I didn't have backed up, and haven't yet > redownloaded). The "initialization" code gets executed and then > stripped out as part of building the object. The result of > making an object is a series of assignments only, > as this example shows: > > myobj1: make object! [ > var1: [] > print "initialize" > do [append var1 now/precise] > func1: [] [print "func1"] > ] > probe myobj1 > myobj2: make myobj1 [] > probe myobj2 > > The 'Do and 'Print are executed during > myobj1: make object! [...] > but do not survive into the object itself. So that code does not > get executed in > myobj2: make myobj1 [] > > That wasn't what I was expecting to see -- so thanks for pointing > it out. > There's no obvious workaround that I can see. >
According to http://www.rebol.com/docs/core23/rebolcore-10.html , The block is evaluated, so it can include any type of expression to compute the values of the variables: example: make object! [ var1: 10 var2: var1 + 10 var3: now/time ] I tend to think of MAKE OBJECT! [...] as "REDUCE with an attitude", as shown in the following example:
>> pond: [
[ frog: "Ribbit" [ duck: "Quack" [ fish: rejoin [ [ to-string #"S" to-char 112 [ lowercase "L" duck/3 [ "sh" [ ] [ ] == [ frog: "Ribbit" duck: "Quack" fish: rejoin [ to-string #"S" to-char 112 lowercase "L" duck/3 ...
>> puddle: copy/deep pond
== [ frog: "Ribbit" duck: "Quack" fish: rejoin [ to-string #"S" to-char 112 lowercase "L" duck/3 ... Just a block with some set-words and other expressions, until we do this:
>> wet-place: make object! pond >> source wet-place
wet-place: make object! [ frog: "Ribbit" duck: "Quack" fish: "Splash" ] All of the set-words at the top level of POND have been changed to belong to a new context.
>> frog: "Croak"
== "Croak" (just for verification).
>> get pond/1
== "Ribbit"
>> get pond/3
== "Quack"
>> get pond/5
== "Splash" Contrasted with
>> get puddle/1
== "Croak"
>> get puddle/3
** Script Error: duck has no value ** Near: get puddle/3
>> get puddle/5
** Script Error: fish has no value ** Near: get puddle/5 And, for another contrast
>> reduce pond
== ["Ribbit" "Quack" "Splash"] versus
>> reduce [frog: "Kneedep" duck: "Honk" fish: "Blubb"]
== ["Kneedep" "Honk" "Blubb"]
>> get puddle/1
== "Kneedep"
>> get puddle/3
== "Honk"
>> get puddle/5
== "Blubb" to prove that the words in POND are no longer in the global context. However, since the spec-block was essentially reduced to establish the values at the time the object/context was created, the expressions don't exist any more (as expressions) in the object itself. Now that I've tried to verbalize it, I'm not so sure that the words capture the idea, which seems so simple. Hmmmm. Maybe English is a foreign language to programmers! -jn- -- ; sub REBOL {}; sub head ($) {@_[0]} REBOL [] # despam: func [e] [replace replace/all e ":" "." "#" "@"] ; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"} print head reverse despam "moc:xedef#yleen:leoj" ;