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

Newest Dillema.

 [1/6] from: edanaii:cox at: 6-Mar-2003 11:13


OK, Given the following:
>> Test: [ a: "b" "Test me" ]
== [SetMe: "b" "Test me"] How do I get around this:
>> ForEach Item Test [ Print Mold Item ]
** Script Error: SetMe needs a value ** Near: Print Item I've tried to-lit-value, to-word, to-set-word, mold, and everything else I can think of. So, how do I get the following results?
>> ForEach Item Test [ Print Magic-Function Mold Item ]
a: b Test me -- Sincerely, | I support the president. Martin Sheen should stick Ed Dana | to fantasy and let our elected officials deal with Software Developer | reality. If you agree, spread the word and visit: Oracle Tools Cons. | Citizens Against Celebrity Pundits, below. ========= http://www.ipetitions.com/campaigns/hollywoodceleb/ ==========

 [2/6] from: greggirwin:mindspring at: 6-Mar-2003 13:10


Hi Ed, ED> >> Test: [ a: "b" "Test me" ] ... ED> So, how do I get the following results? ED> >> ForEach Item Test [ Print Magic-Function Mold Item ] ED> a: ED> "b" ED> "Test me"
>> test: [ a: "b" "Test me" ]
== [a: "b" "Test me"]
>> foreach item test [print mold :item]
a: b Test me -- Gregg

 [3/6] from: edanaii:cox at: 6-Mar-2003 15:01


Gregg Irwin wrote:
>>>test: [ a: "b" "Test me" ] >>>
<<quoted lines omitted: 6>>
>"b" >"Test me"
Excellent. Thank you Greg. What's the significance of the placement of the colon? I always understood it to be a type of pointer operation, placing the colon before meant "give me the contents of" rather than "give me the value of". So, how does placing the colon before make it possible for me to get the set-word out of the block with out an error? A little confused. :) -- Sincerely, | I support the president. Martin Sheen should stick Ed Dana | to fantasy and let our elected officials deal with Software Developer | reality. If you agree, spread the word and visit: Oracle Tools Cons. | Citizens Against Celebrity Pundits, below. ========= http://www.ipetitions.com/campaigns/hollywoodceleb/ ==========

 [4/6] from: joel::neely::fedex::com at: 6-Mar-2003 17:38


Hi, Ed, Let me suggest a different model that might help... Ed Dana wrote:
> >>>test: [ a: "b" "Test me" ] > >>>foreach item test [print mold :item]
<<quoted lines omitted: 9>>
> So, how does placing the colon before make it possible for me > to get the set-word out of the block with out an error?
Think first of the more obvious case of a function. onemore: func [x [number!]] [x + 1] Now that ONEMORE is set to a FUNCTION! value, we might want to do two distinct things: - GET the function without evaluating it (e.g. to pass it as an argument to another function), or - APPLY the function itself to some argument. The design of REBOL makes both things possible (functions are first- class values), but the notation has to allow us to indicate which one we mean. The REBOL notation assumes that we're more often wanting to do the second (apply) than the first (get without applying). When the word ONEMORE appears (undecorated by any punctuation) in an expression, REBOL will get its associated value, see that it is a FUNCTION! value, and immediately try to apply that function to the next value in the expression. So, in the expression print onemore 3 + 2 the function value is applied to the following value (5) and we get 6 printed on the console. Sometimes we really want to just get the function without (yet) applying it, as in the following higher-order function adjust7: func [f [any-function!]] [f 7] which takes any function as an argument and applies it to seven. In that case, we must explicitly say that we don't want the value of the word to be evaluated/applied (yet). Using a GET-WORD! instead of a WORD! is the way we mention the function without using it. Therefore this fails
>> adjust7 square-root
** Script Error: square-root expected value argument of type: number ** Where: halt-view ** Near: adjust7 square-root because REBOL is trying to APPLY the function, but this succeeds
>> adjust7 :square-root
== 2.64575131106459 because we've asked to fetch it (and pass the unevaluated function to ADJUST7) instead. Now apply this to SET-WORD! values, which also assume that you want to take the action whenever they occur. Here's a transcript that shows that behavior:
>> a: b: 0
== 0
>> print [a b]
0 0
>> stuff-to-set: [a: b:]
== [a: b:]
>> foreach set-this stuff-to-set [set-this 17]
== 17
>> print [a b]
17 17 Inside this FOREACH loop, each use of SET-THIS evaluates to a SET-WORD! which tries to do its thing immediately (just as functions do). If we want to suppress that behavior, we must GET but not EVALUATE the uses of SET-THIS instead:
>> foreach set-this stuff-to-set [print [type? :set-this :set-this]]
set-word a set-word b This way of looking at it (for me at least) seems to help keep things straight without thinking about concepts (e.g. "pointers") that aren't really part of REBOL. HTH! -jn- -- ---------------------------------------------------------------------- Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446 Counting lines of code is to software development as counting bricks is to urban development.

 [5/6] from: atruter:labyrinth:au at: 7-Mar-2003 16:19


> Let me suggest a different model that might help...
Hey, I actually understood that! ;) Just a reminder that folks on the sidelines are appreciative of both the question(s) and the answer(s). Regards, Ashley

 [6/6] from: edanaii:cox at: 7-Mar-2003 8:02


Joel Neely wrote:
>Hi, Ed, > >Let me suggest a different model that might help... >
Hey, I never said my "pointer" model was the right one, just that that's how I understood the "placement of the colon" to be. :)
>which takes any function as an argument and applies it to seven. In >that case, we must explicitly say that we don't want the value of the
<<quoted lines omitted: 8>>
> >> adjust7 :square-root > == 2.64575131106459
The net effect being:
>> Square-Root 7
Gotcha!
>This way of looking at it (for me at least) seems to help keep things >straight without thinking about concepts (e.g. "pointers") that aren't >really part of REBOL. > >HTH! >
It helped. Thanks Joe. :) -- Sincerely, | I support the president. Martin Sheen should stick Ed Dana | to fantasy and let our elected officials deal with Software Developer | reality. If you agree, spread the word and visit: Oracle Tools Cons. | Citizens Against Celebrity Pundits, below. ========= http://www.ipetitions.com/campaigns/hollywoodceleb/ ==========

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted