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

[REBOL] Re: 'Foreach questions

From: tim:johnsons-web at: 21-Dec-2002 15:23

Thanks to Gerard and Matt: I think I'm finding a work-around. What I really want to do is maintain a close syntactical link between data requested and data retrieved. What I might need is a function called 'form-block ; take a block of words and returns a block of strings form-block: func[blk[block!]][ blk1: make block! length? blk foreach b blk[append blk1 form b] blk1 ] columns: [exp_date first_name last_name age]
>> form-block columns
== ["exp_date" "first_name" "last_name" "age"] data: db[select (form-block columns) from table where "ID" eq ID] ; untested of course ;returns for example date data: [[1 2 3 4] [5 6 7 8] [9 10 11 12]]
>> foreach row data[set columns row print [exp_date first_name last_name age]]
1 2 3 4 5 6 7 8 9 10 11 12 ; that should get me going... thanks! -tj- * Gerard Cote <[gerardcote--sympatico--ca]> [021221 14:50]:
> Hi Tim, > > here is my second attempt to answer your problem : > > >> foreach row data[ > [ set 'col-names row > [ prin mold row print col-names] > [1 2 3 4]1 2 3 4 > [5 6 7 8]5 6 7 8 > [9 10 11 12]9 10 11 12 > >> > > Hope that helps! > Regards, > Gerard > > P.S. I'm currently coming back to real life ... > > ----- Original Message ----- > From: "Tim Johnson" <[tim--johnsons-web--com]> > To: <[rebol-list--rebol--com]> > Sent: Saturday, December 21, 2002 3:29 PM > Subject: [REBOL] 'Foreach questions > > > Fellow Rebols: > > I'm trying to use the same block of words in both a query > > and in parsing data from the query. To illustrate here's some > > test data, some results and some results I'm looking for... > > ; need some words set to literal values > > >> col-names: set [a b c d] ["one" "two" "three" "four"] > > == ["one" "two" "three" "four"] > > ; now some test data. Let's pretend that this data is retrieved > > ; by a query using col-names above > > >> data: [[1 2 3 4] [5 6 7 8] [9 10 11 12]] > > == [[1 2 3 4] [5 6 7 8] [9 10 11 12]] > > ; now I want to fetch each inner block in 'data and > > ; automagically set each word in 'col-names to each successive > > ; item in the inner block > > >> foreach row data[set 'col-names row > > prin mold col-names prin mold a > > prin mold b prin mold c print mold d > > ] > > [1 2 3 4]"one""two""three""four" > > [5 6 7 8]"one""two""three""four" > > [9 10 11 12]"one""two""three""four" > > ; alas, I've failed to get what I wanted. What I wanted to see is: > > [1 2 3 4] 1 2 3 4 > > [5 6 7 8] 5 6 7 8 > > [9 10 11 12] 9 10 11 12 > > ; where each 'word originally in col-names would be set to > > ; a return value > > > > Any ideas on how I can make this work for me in a similar > > fashion. > > > > TIA > > -- > > Tim Johnson <[tim--johnsons-web--com]> > > http://www.alaska-internet-solutions.com > > http://www.johnsons-web.com > > -- > > To unsubscribe from this list, please send an email to > > [rebol-request--rebol--com] with "unsubscribe" in the > > subject, without the quotes. > > > > > > -- > To unsubscribe from this list, please send an email to > [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