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

[REBOL] Re: Diversion

From: joel:neely:fedex at: 4-Mar-2002 23:36

Hi, Patrick, pat665 wrote:
> ... I would like to know more about bind and use. If anyone has > examples, explanations, even raw material ? >
Here's a starter, with mild apologies for the length: http://www.escribe.com/internet/rebol/m19482.html This was from a previous discussion, but note the parts about each REBOL word belonging to a context and FUNC changing contexts of words. You can have words with the same "name", but which are different words because they belong to different contexts. (Think of the fact that "George" is a different person, depending on whether you're in the Clooney house, the White House, or the Jungle.) Now consider this transcript:
>> fee: "phi" == "phi" >> fie: "phei" == "phei" >> foe: "pho" == "pho" >> fum: [fee fie foe] == [fee fie foe] >> print fum -> phi phei pho
FUM contains three words, which belong to the global context.
>> some-object: make object! [
[ fee: $25.00 [ fie: "shame" [ foe: "opponent" [ tunnel: func [b [block!]] [bind b 'self] [ ] SOME-OBJECT also has three words with those same names, but they are in a different context, so...
>> print fum
phi phei pho ...FUM still refers to the original (global) three words. Now let's tunnel into the context of SOME-OBJECT...
>> some-object/tunnel fum == [fee fie foe]
FUM still refers to three words with the same names, but now they live in a different house...
>> print fum -> $25.00 shame opponent
but
>> print [fee fie foe] -> phi phei pho
So that bind foo 'baz (where FOO is a block of words) says "for each word reference in FOO, if there is a synonym for that word in the context that contains 'BAZ, make that reference in FOO be to the synonym in 'BAZ 's context." HTH! -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" ;