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

[bind] Use example

 [1/5] from: Christophe:Coussement:mil:be at: 23-Apr-2004 10:30

Hi list, 'bind could perhaps solve a context problem I'm facing. Could anyone give me some example of use of 'bind and 'bind/copy, and the reason to use this solution ? TIA ==christophe

 [2/5] from: nitsch-lists:netcologne at: 23-Apr-2004 16:54

On Freitag, 23. April 2004 10:30, Coussement Christophe wrote:
> Hi list, > > 'bind could perhaps solve a context problem I'm facing. > Could anyone give me some example of use of 'bind and 'bind/copy, and the > reason to use this solution ? >
You have a a: context[ b: 2 c: 3 : d: 4] You have a block of words, like block: [b c d] And you want this words looked up in this context. similar to a/b a/c etc. Then you say bind block in a 'b And now all words in the block are bound to 'a. (words not in 'a are unchanged.) So get first block returns 2. Note you give a reference-word in a context, not the context itself. that way you can also bind to function-argument, where you don't have a context-handle. (with newer betas for 1.3 you can also give the context directly, like bind block a ; instead of "in a 'b" or "in a 'self" ) This ist most usefull to execute code in a context, say you want to execute it using a special set of functions. Most of the time you are using 'bind implicitely, as 'func and "make object" use it automaticly. sometimes you want that feature without funcing or making, then 'bind can rescue you.
> TIA > > ==christophe

 [3/5] from: greggirwin::mindspring::com at: 23-Apr-2004 11:03

Hi Christophe, CC> 'bind could perhaps solve a context problem I'm facing. CC> Could anyone give me some example of use of 'bind and 'bind/copy, CC> and the reason to use this solution ? I'll just add to Volker's reply a bit. One of the places I've found BIND to be most useful is with dialects. For example, in the dialect I may parse the data and create an object (context) from it. If some of the things I process are blocks -- blocks that are evaluated as actions later, in the object -- BIND lets you "attach" them to the object you created dynamically, so they can be executed in the correct context. It's also very useful when you want to dynamically load code. Binding is very important when you think about REBOL as a messaging language, because messages may come from anywhere, and go anywhere, and need to be processed in the proper context no matter where they go. -- Gregg

 [4/5] from: reblist:codeconscious at: 24-Apr-2004 17:05

> 'bind could perhaps solve a context problem I'm facing. > Could anyone give me some example of use of 'bind and 'bind/copy, and the
reason to use this solution ? Below is a compressed script that defines a function I've been playing with off and on. The function creates a context and a result block every time it is run with the /meta refinement. I used Bind to bind words in the result block to the new context in a simple way. Thinking about alternatives to using Bind in my example... I could have used Context instead of Bind, but it could be a little tricky to return just the block. Using Use would mean that I would probably have to do some fancy things like appending blocks together. In the end using Bind, for this function, was to me the simplest for what I wanted. My function converts a string to a block. An example of this function.
>> my-string: {Some text [a block]^/A new line.}
== "Some text [a block]^/A new line."
>> b: load-rtext/meta my-string
== [text "Some text " block [a block] delimiter newline text "A new line."] Now, because I have used Bind and a special context, the words in this block have a defined meaning. So that I can do this:
>> rejoin b
== "Some text [a block]^/A new line." Which is cute. If you think my function is weird - yes it is. I was playing with the idea of embedding blocks inside strings in a fairly general way. It sort of complements a REBOL script which is like embedding strings inside blocks. :-) Another way to use Bind would be to simulate some sort of embedded contexts. For example compare context [ a: 1 b: 1 context[ b: 2 print ["Answer:" remold [a b]] ] ] with ctx: reduce [ context [a: 1 b: 1] context [b: 2] ] b: [print ["Answer:" remold [a b]]] foreach cx ctx [bind b in cx 'self] do b Regards, Brett. #{ 789CAD564B6FDC36103E4BBF622CA3B07D58AD9BF6A41C5CA7499100061238BD 0934C095465E3612299054368BB5FF7B66486AD76BB4A7EE1E2C69388F6FBE79 D0F71FDE7DBE833ACFFE56BEC70A8ADEC876613DFEF0459EFDA558F6CB4156DA 3CBB9DFCDA58527D67D17BF82875DBE396B47190AAAF60C5E23F1AD36263B46B 94995CD99821CF36B8AA60EDFD582D979BCDA6FC1795F7D253C037BF2D3A5C2D DE5C5FFF9E675F263B1AC7D0EE0806300AD828BF061C56D8B6D8C2AA37CD3757 16B9C8F303D40ABA49379CDA8E0D5DB4942EAA97F0E1D81CA445606B6C4BF8EA ADD28F0E9476AA45D83D87536F91E0B5D02B8F56F6FDB6CC1F16F0E7C7DB7BF0 DB1159BD550DA9C0A407E99B35E9366B696543FA0EB4B1035BC1E4E8C01B68B1 5783F27B00BA3DE4E42282F23987BA615F22CFA20CEAF83C23C9D268F257DC8E 236ACA504657F05DF61372AA4940D464CB01BD84E2538BDAAB4E115AC202960A F0A81503C21E073A73915CB71D56A67770D919DB9072887455C23DBAA9F7A088 4633E99086042A622077018DD4B04272FB8F519AB99D3C0C724BC43A04670684 CD9AD873A36CF0053701A0D2CA2BC9984288DAA1259867D04A2F99DF3341F0A3 0E0106BFC6A41AAC294FB2557AA4888F560E83B4890746A7F4840B3BF59867FE 875F70E4506CE2318881A5E165244CF1ADA70CE21B72951802A01973C13D452F 15EC1E960FCBE73CCFDEC2E27FFDD8C37BEC0203341027709867AA8350F29A2B 5751F34E287846D57E32023D82F81978C038ABEC12A9F86893654DFD8F9652A7 B99ECB52310F42D4B510576C302A6AB859313E42AF08EA770FA16B8EEC43D03C 2328A94A55082CF5363CB35041929D17BB029EE0BCA80B715CAA27563B94E9E9 45A19EF675241D11A2BC348DA12ED9FEA829485E85B82220E800AD35F686384B A032873EF1155B2C425A6AEEFA20085A4C4DC523B131B63D031A9D21B4CD0D54 296DFA8566DA7F8A14209A5E70631EB43A65DD4BFFAF416BA33140E63F57AF1B 9D847B9648993A162E5398B479A8D021CE059D5D31573391EC1B37FCF99F26E9 9CCD66CEC9AA31E3368D5D98F6FDB0CD6EC29E3850309BB34E051A1F797BF207 135EECEA876571A2F13A6C8E534D17F7F7BCB3EAD8DD55DCB7BC9A6741686C5E B5F5BCC76EE65118E4B77985C1AFD7D722BD8B1365FC85593C55B2233B5B721E E9169A772CB7EFD1D2E07E5CD14D3867A6F4FE7E48AD1E2EE758F17D57C59D94 56521DC745C4D10BF1E69DF5FA0E144C3D5F366963A4F3F3E2B9A0B3B77017EF EA74A30787A144B3BF7861D6A96CE46D307DFA97204E165C38EC3B5E27F55C1E 9A2C91FF040551CED039090000 }

 [5/5] from: Christophe:Coussement:mil:be at: 26-Apr-2004 13:21

Volker, Gregg and Brett Thanks a lot for the explanations. Now I understand a lot more ;-) For those interested, I found a tutorial (in French) which seems to be a good starting point: 'bind can indead solve my context problem. I just have to look how to use it in my scripts ... Thanks again ! ==christophe