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

'get'ing a 'word from a block

 [1/6] from: tim::johnsons-web::com at: 31-Dec-2002 18:39


Hello Rebols: I have an example below where foreach sets a block of values, but I don't know how to retain those values within the block when I pass the block to another function:
>> d: [a b c]
== [a b c]
>> blk: [1 2 3 4 5 6 7 8 9]
== [1 2 3 4 5 6 7 8 9]
>> test: func[row[block!]][?? row ?? a] >> foreach :d blk[?? a ?? b ?? c test d]
a: 1 b: 2 c: 3 ; foreach sets the values in the block correctly row: [a b c] ; the words are passed in the block to 'test ** Script Error: a has no value ** Where: rejoin ** Near: mold name: get name ; alas, can't get the value What am I doing wrong here? TIA -- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [2/6] from: anton:lexicon at: 1-Jan-2003 16:54


Well, Your block d contains three words, a b c, whose context is... in that block... (I think). You need to bind the words in the d block into the foreach's context (which we can get to using 'a as an example word in that context.) Having bound the words in d to the foreach context, they are still simply [a b c], so you need to reduce the block get a block of values out. So a bit of binding and reducing and you are fixed: d: [a b c] blk: [1 2 3 4 5 6 7 8 9] test: func [row [block!]][?? row] foreach :d blk code: [ ?? a ?? b ?? c test reduce bind d 'a ] Anton.

 [3/6] from: tim:johnsons-web at: 31-Dec-2002 21:47


Thank you Anton! I forgot about 'bind. I'm still in the dark a bit though, because I really want to get the values for 'a 'b 'c in 'test If I rewrite test as : test: func [row [block!]][?? row ?? a]
>> foreach :d blk code: [
[ ?? a ?? b ?? c [ test reduce bind d 'a [ ] a: 1 b: 2 c: 3 row: [1 2 3] ** Script Error: a has no value ** Where: rejoin ** Near: mold name: get name If possible, I would want to get 'row as [a b c] and 'get 1 from a. Is this possible? And Happy New Year! -tim- * Anton <[anton--lexicon--net]> [021231 21:10]:
> Well, > Your block d contains three words, a b c, whose
<<quoted lines omitted: 45>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [4/6] from: al:bri:xtra at: 1-Jan-2003 20:00


Tim wrote:
> >> test: func[row[block!]][?? row ?? a]
I believe that 'a in the function body isn't bound to the contents of the block. This method seems to work OK for me:
>> blk: [1 2 3 4 5 6 7 8 9]
== [1 2 3 4 5 6 7 8 9]
>> d: [a b c]
== [a b c]
>> map blk func d [probe a probe b probe c]
1 2 3 4 5 6 7 8 9 == [3 6 9] And it seems easier to understand. Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [5/6] from: nitsch-lists:netcologne at: 1-Jan-2003 8:58


d: [a b c] blk: [1 2 3 4 5 6 7 8 9] test: func [row [block!]] [?? row ?? a probe reduce row] forskip blk length? d[ set d blk test d] blk: head blk ;if you need blk later == row: [a b c] a: 1 [1 2 3] row: [a b c] a: 4 [4 5 6] row: [a b c] a: 7 [7 8 9] Tim Johnson wrote:
>Thank you Anton! I forgot about 'bind. >I'm still in the dark a bit though, because
<<quoted lines omitted: 78>>
>>>Tim Johnson <[tim--johnsons-web--com]> >>>
-volker

 [6/6] from: tim:johnsons-web at: 1-Jan-2003 8:00


Thanks to all for helping me to find my solution! regards -tim- * Volker Nitsch <[nitsch-lists--netcologne--de]> [021231 23:10]:
> d: [a b c] > blk: [1 2 3 4 5 6 7 8 9]
<<quoted lines omitted: 106>>
> [rebol-request--rebol--com] with "unsubscribe" in the > subject, without the quotes.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

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