For Programmers: Free Programming Magazines  


Home > Archive > APL > January 2005 > Assigning values to lists of variables in APL+Win









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Assigning values to lists of variables in APL+Win
L Howell

2005-01-10, 8:55 pm

I'm trying to do the following in APL+Win:

for LIST defined to be list of variable names, eg. ('A')('B')('C') , I want
to loop on LIST[i] and assign values to the variables A, B, C. In
otherwords, after executing the looping function on LIST, the varibles A, B,
C will be created and have the values that are assigned to them in the
looping function. Is there a way to do this?

Hope this makes sense and thanks, Leonard


Eric Landau

2005-01-10, 8:55 pm

In article <41e2e25c$1_3@127.0.0.1>, "L Howell"
<leonard.w.howell@nasa.gov> wrote:

>I'm trying to do the following in APL+Win:
>
>for LIST defined to be list of variable names, eg. ('A')('B')('C') , I want
>to loop on LIST[i] and assign values to the variables A, B, C. In
>otherwords, after executing the looping function on LIST, the varibles A, B,
>C will be created and have the values that are assigned to them in the
>looping function. Is there a way to do this?


You want the execute primitive, AKA "hydrant" (uptack+jot). It executes
the contents of a character expression, so if list[i] is 'A', the
expression
{execute}list[i],'<-value'
gives the same effect as
A<-value


Eric Landau, APL Solutions, Inc.
"Sacred cows make the tastiest hamburger." - Abbie Hoffman
RAV

2005-01-10, 8:55 pm

On Mon, 10 Jan 2005 14:18:53 -0600, "L Howell"
<leonard.w.howell@nasa.gov> wrote:

>I'm trying to do the following in APL+Win:
>
>for LIST defined to be list of variable names, eg. ('A')('B')('C') , I want
>to loop on LIST[i] and assign values to the variables A, B, C. In
>otherwords, after executing the looping function on LIST, the varibles A, B,
>C will be created and have the values that are assigned to them in the
>looping function. Is there a way to do this?
>
>Hope this makes sense and thanks, Leonard
>


Note: I used ]APL2ASCII below; use ]ASCII2APL to convert back to APL
symbols.

I'm not sure why you have the variable names as strings in the first
place. If you didn't, you could simply strand assign them, i.e.:

values{<-}1 (2 2) (3 3 3)
(one two three){<-}values

But if they really are as strings in a nested vector, you COULD do it
in a loop, using execute, i.e.:

foo1;LIST;values;C
LIST{<-}'one' 'two' 'three'
values{<-}1 (2 2) (3 3 3)
:FOR C :IN {iota}{rho}LIST & {execute}(C{pick}LIST),'{<-}C{pick}values' & :ENDFOR

But you could do it in a non-looping way, too:

foo2;LIST;values
LIST{<-}'one' 'two' 'three'
values{<-}1 (2 2) (3 3 3)
{execute}'(',({enlist}LIST,{each}' '),'){<-}values'

Of course, I really don't know where you're getting the values from.
I just made an assumption they were also in a nested vector.
Björn Helgason

2005-01-10, 8:55 pm

www.jsoftware.com

j.apl

LIST=:'A';'B';'C'

(LIST)=: (1 2 3);'ajklsdf';1 2 3 4 566

LIST
+-+-+-+
|A|B|C|
+-+-+-+

A
1 2 3

B
ajklsdf

C
1 2 3 4 566

L Howell

2005-01-10, 8:55 pm

Thanks ... works great!


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com