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-13, 8:56 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
| |
| L Howell 2005-01-14, 8:55 pm |
| Thanks ... works great!
| |
| Eric Landau 2005-01-14, 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
| |
| Björn Helgason 2005-01-15, 8:55 am |
| 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
| |
|
| 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.
| |
| Ted Edwards 2005-01-22, 8:55 pm |
| Björn Helgason wrote:
> www.jsoftware.com
> j.apl
> LIST=:'A';'B';'C'
> (LIST)=: (1 2 3);'ajklsdf';1 2 3 4 566
> ...
How cumbersome!!! In APL2
(A B C){is}(1 2 3)'ajklsdf'(1 2 3 4 566)
No wonder I find J so awkward.
Ted
| |
| Don Guinn 2005-01-23, 3:56 pm |
| Well, that's only one way to do the multiple name assignment in J.
There's a form that is more like the one in APL. Notice it's not
necessary to put the numeric vectors in parens.
'A B C'=: (1 2 3);'ajklsdf';1 2 3 4 566
Ted Edwards wrote:
> Björn Helgason wrote:
>
>
>
>
> How cumbersome!!! In APL2
> (A B C){is}(1 2 3)'ajklsdf'(1 2 3 4 566)
>
> No wonder I find J so awkward.
>
> Ted
>
>
| |
| Björn Helgason 2005-01-25, 8:55 am |
| As you may have seen in the original post then LIST was supposed to
contain the names of the nouns that would receive the values
Sorry that you have to miss out on the great opportunities available in
J
| |
| Bob Cain 2005-01-25, 8:55 pm |
|
Björn Helgason wrote:
> As you may have seen in the original post then LIST was supposed to
> contain the names of the nouns that would receive the values
>
> Sorry that you have to miss out on the great opportunities available in
Sorry J developers can't see the value of code that doesn't
look like cartoon "swearing".
Bob
--
"Things should be described as simply as possible, but no
simpler."
A. Einstein
|
|
|
|
|