f



Assignment to a variable variable

Sometimes I want to assign a value to a variable whose name is a
parameter. For example

     =E2=88=87 GetVar
varname
[1]
slot=E2=86=90DIR=E2=8D=B3varname
[2]    =E2=8D=8Evarname,'=E2=86=90=E2=8E=95FREAD 1
slot'
     =E2=88=87

Line [2] is unpleasant, as execute often is. The awkward part is that
the language forces me to execute a whole statement -- to artificially
construct a character version of some code -- including the assignment
arrow.

Here's a proposed language enhancement that seems natural to me:

(=E2=8D=8Evarname)=E2=86=90=E2=8E=95FREAD 1 slot

Pro: The construct is consistent with the idea that approximate
meaning of =E2=8D=8E is to unquote. It is more natural in that it lets me
execute only the part that really needs executing.

Con: It's not directly analogous to selection assignment such as
(1 0 1/varname)=E2=86=90 ...
because 1 0 1/varname has a value but =E2=8D=8Evarname by itself is a VALUE
ERROR.

Rebuttal: It's the rule anyway, not even the exception, that
expressions to the left of assignment are handled differently than
those to the right. For example, A[ 2 ; 3]=E2=86=90 does not involve
evaluating A[2;3]. Also, asdf=E2=86=904 works fine even if asdf by itself i=
s a
VALUE ERROR.

Conclusion: Execute assignment is not a generalization of selection
assignment, but it's a consistent extension of assignment and a
plausible extension of execute.

Charles
0
Charles
5/1/2009 5:48:41 PM
comp.lang.apl 1696 articles. 0 followers. Post Follow

2 Replies
296 Views

Similar Articles

[PageSpeed] 58

Charles Brenner wrote:
> Sometimes I want to assign a value to a variable whose name is a
> parameter. For example
> 
>      ∇ GetVar
> varname
> [1]
> slot←DIR⍳varname
> [2]    ⍎varname,'←⎕FREAD 1
> slot'
>      ∇
> 
> Line [2] is unpleasant, as execute often is. The awkward part is that
> the language forces me to execute a whole statement -- to artificially
> construct a character version of some code -- including the assignment
> arrow.
> 
> Here's a proposed language enhancement that seems natural to me:
> 
> (⍎varname)←⎕FREAD 1 slot
> 
> Pro: The construct is consistent with the idea that approximate
> meaning of ⍎ is to unquote. It is more natural in that it lets me
> execute only the part that really needs executing.
> 
> Con: It's not directly analogous to selection assignment such as
> (1 0 1/varname)← ...
> because 1 0 1/varname has a value but ⍎varname by itself is a VALUE
> ERROR.
> 
> Rebuttal: It's the rule anyway, not even the exception, that
> expressions to the left of assignment are handled differently than
> those to the right. For example, A[ 2 ; 3]← does not involve
> evaluating A[2;3]. Also, asdf←4 works fine even if asdf by itself is a
> VALUE ERROR.
> 
> Conclusion: Execute assignment is not a generalization of selection
> assignment, but it's a consistent extension of assignment and a
> plausible extension of execute.

indeed

one problem is: how do you set varname to be a pointer to whatever?

is it a literal (i.e, a name stored as a literal), or a reference (e.g, 
an absolute machine address)?

if it's a literal, there are problem concerning localisation (which at 
the moment, would resolve to the most local reference, which may not be 
what you want)

if it's a reference, you need additional syntax to initialise varname
varname ← A  won't work, because that will pass a value
varname ← &A will work in C (IIRC)
what did you have in mind for APL?

and what happens if A is updated after the pointer is set?

I can sympathize with your need  --  APL's rule of dereferencing 
everything as far as possible makes things easier to understand, but 
there are times when a little more complexity would allow a little more 
efficiency

it's a problem worth solving -- if there is a solution consistent with 
existing syntax   . . .   /phil


0
phil
5/1/2009 11:33:26 PM
On May 1, 4:33=C2=A0pm, phil chastney
<phil.hates.s...@amadeus.munged.eclipse.co.uk> wrote:
> Charles Brenner wrote:
> > Sometimes I want to assign a value to a variable whose name is a
> > parameter. For example
>
> > =C2=A0 =C2=A0 =C2=A0=E2=88=87 GetVar
> > varname
> > [1]
> > slot=E2=86=90DIR=E2=8D=B3varname
> > [2] =C2=A0 =C2=A0=E2=8D=8Evarname,'=E2=86=90=E2=8E=95FREAD 1
> > slot'
> > =C2=A0 =C2=A0 =C2=A0=E2=88=87
>
> > Line [2] is unpleasant, as execute often is. The awkward part is that
> > the language forces me to execute a whole statement -- to artificially
> > construct a character version of some code -- including the assignment
> > arrow.
>
> > Here's a proposed language enhancement that seems natural to me:
>
> > (=E2=8D=8Evarname)=E2=86=90=E2=8E=95FREAD 1 slot
>
> > Pro: The construct is consistent with the idea that approximate
> > meaning of =E2=8D=8E is to unquote. It is more natural in that it lets =
me
> > execute only the part that really needs executing.
>
> > Con: It's not directly analogous to selection assignment such as
> > (1 0 1/varname)=E2=86=90 ...
> > because 1 0 1/varname has a value but =E2=8D=8Evarname by itself is a V=
ALUE
> > ERROR.
>
> > Rebuttal: It's the rule anyway, not even the exception, that
> > expressions to the left of assignment are handled differently than
> > those to the right. For example, A[ 2 ; 3]=E2=86=90 does not involve
> > evaluating A[2;3]. Also, asdf=E2=86=904 works fine even if asdf by itse=
lf is a
> > VALUE ERROR.
>
> > Conclusion: Execute assignment is not a generalization of selection
> > assignment, but it's a consistent extension of assignment and a
> > plausible extension of execute.
>
> indeed
>
> one problem is: how do you set varname to be a pointer to whatever?
>
> is it a literal (i.e, a name stored as a literal), or a reference (e.g,
> an absolute machine address)?
>
> if it's a literal, there are problem concerning localisation (which at
> the moment, would resolve to the most local reference, which may not be
> what you want)
>
> if it's a reference, you need additional syntax to initialise varname
> varname =E2=86=90 A =C2=A0won't work, because that will pass a value
> varname =E2=86=90 &A will work in C (IIRC)
> what did you have in mind for APL?

My idea is the simpler -- what you call "literal". I'm not trying to
do anything that I can't do already, but just to do it in a more
natural way.

What I am proposing can be described as a class of identities such as,
for example,

(=E2=8D=8E'Abc[2;4]')=E2=86=90expression
means the same as
Abc[2;4]=E2=86=90expression

In short, =E2=8D=8E to the left of assignment simply strips quotes.
Consistently, instead of

(=E2=8D=8E'Abc[2;4]')=E2=86=90expression
it would of course be equivalent to write
var=E2=86=90'Abc[2;4]'
(=E2=8D=8Evar)=E2=86=90expression

In summary --
This idea adds nothing fundamental. It doesn't do any violence to the
language.
There are various advantages --
1. more natural notation, let's you say closer to what you mean
2. faster execution
3. easier to analyze with analysis tools. For example, tokens are
found through a normal token search. No need to "search within quotes"
with the concomitant complications that the search becomes harder and
may find more than you want to find
-- but nothing earthshaking.

Charles
0
Charles
5/2/2009 4:03:56 AM
Reply:

Similar Artilces:

Variable variables
I'm having trouble creating dynamic variables: for (year=1968:2001) load (myfile<year>); value_<year> = foo; close (myfile<year>); How do I loop through a large number of annual files and create distinguishable matrices commonly-named variables? In other words, I need to create variable variables. Thanks! Bruce: <SNIP several ML evergreens... two hints: <http://www.mit.edu/%7Epwb/cssm/matlab-faq_4.html#loopoverfiles> <http://www.mit.edu/~pwb/cssm/matlab-faq_4.html#evalcell> us In article <ef58d33.-1@webcrossing.raydaftYaTP>, Bruce <for...

Variable into a variable
I don't know if I'm saying this right but is it possible to pass a variable into a variable in matlab? For example in php you can have a variable named something and by writting < $that = 'something'.$number; > you can use change the variable $number with any number you want and put for example the variable something1 into $that. "Iraklis Markelis" <it00139@uom.gr> wrote in message news:hgs1mrxsczak@legacy... > I don't know if I'm saying this right but is it possible to pass a > variable into a variable in matlab? > For example in ...

Variable variables?
I have a situation which I 'think' I need to use variable variables and not sure how to go about it. I have several <select multiple> elements on a search form with their names created dynamically and the options created dynamically. $parent holds the name such as "Women", "Mens" etc.. $c_id holds category_id and is sent off as the 'value' of the option. This form is self calling and an array is created for the multiple option selected. Women => array([0]=>20,[1]=>21,...) Mens => array([0]=>32,[1]=>35,...) I a...

Variable in a variable
Hi, I would like to print a variable into a variable for ex. n = 1; x=[('frame'),n,('.png')]; Result : frame.png expected: frame1.png Is there anyway i could do this by any method. Awaiting for your reply "Bejoy Thomas" <bejoy.thomas@yahoo.in> wrote in message news:h4k998$2cj$1@fred.mathworks.com... > Hi, I would like to print a variable into a variable for ex. > > n = 1; > x=[('frame'),n,('.png')]; > > Result : frame.png expected: frame1.png > > Is there anyway i could do this by any method. Use SPRINTF or NUM2S...

Variable Variables
I came across the interesting notion of $a and $$a, which in turns uses the string in $a as a $-suffix to make a new dynamic variable. Can someone illustrate a practical use out of it? I will be very curious to see one (webdesign related) example of its usage. Thanks, Animesh ..oO(Animesh K) >I came across the interesting notion of $a and $$a, which in turns uses >the string in $a as a $-suffix to make a new dynamic variable. > >Can someone illustrate a practical use out of it? I will be very curious >to see one (webdesign related) example of its usage. There's hard...

Variable in Variable
Is it possible to print the the value of a variable in a variable what i mean: Declare @test varchar(255) Declare @foo varchar(255) Declare @strSQL varchar(255) set @test = 'Hallo' Set @foo = '@test' Print @foo Set @strSQL = 'SELECT ' + @foo --Expected result is 'Hallo' exec master..sp_ExecuteSQL @strSQL How doess it work? I hope you understand my problem Thanks "Michi Albatross" <alber@netdot.ch> wrote in message news:67ae724b.0410080410.5c8ccb59@posting.google.com... > Is it possible to print the the value of a variable in a variable ...

Variable in variable?
Hello, I think that what I'm trying to do is impossible, but before I give up I thought I'd try and pick a few more knowledgeable brains than my own. I have any array of user defined type variables. I need to loop through the array (doing certain calculations) on a particular member variable. I then want to loop through the array again on a different member variable doing very similar calculations. I only need to change a couple things in the loop, otherwise the loop is identical from one member to the other. In a nutshell, what I'm trying to do is use a variable, that will c...

variable of variable $$, ${ ...
hi, i m trying to find how to access a variable of variable (which is an image) i want to know the size of the picture the name of the picture is photo1 next one is photo2, next one is photo3 ... for ($i=1;$i<$MAX_PHOTOS;$i++) { $photo='photo'.$i; $$photo_size; //don t work } thx "cdt_sylvestre" <cdtEffacercAsly@relayeur.com> wrote in message news:3ff934d6$0$17130$626a54ce@news.free.fr... > hi, > > i m trying to find how to access a variable of variable (which is an image) > i want to know the size of the picture > the name of the picture is ...

Variable in a Variable
Hi All, I have a dataset data abc; input a b $ c d; datalines; 100 c 20 30 200 d 10 40 300 c 23 99 ; in this dataset variable b contains either c or d(other variable name) how can i get the value of c or d i.e 20 or 30 from first observation.... Please let me know thanks in advance On Feb 8, 1:32 pm, "sasguy" <addanki...@gmail.com> wrote: > Hi All, > I have a dataset > data abc; > input a b $ c d; > datalines; > 100 c 20 30 > 200 d 10 40 > 300 c 23 99 > ; > in this dataset variable b contains either c or d(other variable > name) > how can...

A variables variables
how can I declare a variable with another variable name? for example I will use PHP: $a= "hello"; $a_hello="baybay"; print ${'a_'.$a) //output: baybay how can i do it with no Arrays using python thanks! On Aug 23, 7:25=A0pm, Gandalf <goldn...@gmail.com> wrote: > how can I declare a variable with another variable =A0name? > > for example =A0I will use PHP: > > $a=3D "hello"; > > $a_hello=3D"baybay"; > > print ${'a_'.$a) =A0//output: baybay > > how can i do it with no Arrays using =A0python...

Variable Variable
Hi List, is there in python a variable variable like in PHP ($$var)? What I want to do is something like that: pc=["a","b","c"] for i in pc: i = anyclass() a.shutdown() b.update() Any Ideas? Many Thanks, m Tanteauguri wrote: > Hi List, is there in python a variable variable like in PHP ($$var)? > > What I want to do is something like that: > > pc=["a","b","c"] > > for i in pc: > i = anyclass() > > a.shutdown() > b.update() Use a dictionary: stuff = {} pc = ['a', 'b', ...

variable variables
Hello, is it possible to make first attr variable? some_object.attr.attr so instead of attr I could use self.foo which has value "attr" Thanks! En Fri, 18 Jun 2010 06:48:34 -0300, someone <petshmidt@googlemail.com> escribi�: > is it possible to make first attr variable? > > some_object.attr.attr > > so instead of attr I could use self.foo which has value "attr" I think you're looking for getattr: http://docs.python.org/library/functions.html#getattr name = "spam" getattr(some_object, name) == some_object...

Variables variable
Hi folks, Someone know how to make variables variable like in PHP? It's something like this: $a =3D 'hi' $$a =3D 'testing' echo $hi 'testing' Regards --=20 Adriano Monteiro Marques www.gopython.com.br py.adriano@gmail.com I'm FREE... Are you? (PYTHON powered) Adriano Monteiro wrote: > Hi folks, > > Someone know how to make variables variable like in PHP? > It's something like this: > > $a = 'hi' > $$a = 'testing' > echo $hi > 'testing' You are most certainly wanting to use dictionaries. Or, if you...

Variable for a Variable
I doubt this is possible, but thought to ask anyway. I have a situation where there are 30 arrays (of structures) all in one module. Each representing a separate tool within the application. Just for examples sake I'll make up a few: Hammer(iElements) Saw(iElements) Screwdriver(iElements) ... Drill(iElements) I have this Select Case that checks a Tool_ID and locates the correct tool to operate on. Select Case Tool_ID Case ID_Hammer Hammer(iElements).visible = false Case ID_Saw Saw(iElements)...

Web resources about - Assignment to a variable variable - comp.lang.apl

Assignment - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

HootSuite Rolls Out HootSuite Assignments Google Chrome Extension
Social-media-management platform HootSuite announced the release of HootSuite Assignments , a browser extension for Google Chrome that enables ...

The Art Assignment (@artassignment) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here The Art Assignment @ artassignment ...

TeacherKit - Class Organizer, Teacher Planner, Gradebook, Assignment List, Attendance and Student 's ...
Get TeacherKit - Class Organizer, Teacher Planner, Gradebook, Assignment List, Attendance and Student 's Grade Tracker on the App Store. See ...

Assignments - Flickr - Photo Sharing!
106/365 As you can see, I have a lot to work on this weekend. All of my assignments are due on Monday, so time to get crackin'. Oh, and when ...

Fits and Starts - An Art Assignment - YouTube
A short routine assembled and edited for The Art Assignment (https://www.youtube.com/user/theartassignment), set to an original track by Son ...

Animal of the Day: Mittens the Hermaphroditic Cat to Get Gender Assignment Surgery
Meanwhile in Canada… A cat born with both male and female genitalia in Newfoundland is about to go under the knife. Mittens was found in the ...

School assignments go high-tech
How much do you help your kids with their school projects? How much do you help your kids with their school projects? Remember when the pinnacle ...

Students enlist MyMaster website to write essays, assignments
Students from almost every university in NSW are paying up to $1000 to have their essays written by a Sydney-based company, undermining the academic ...

Snow Sky confirms spring assignment as England stayer enters quarantine - DailyTelegraph Search Search ...
ONE of the leading fancies for the Melbourne Cup, top English stayer Snow Sky has been confirmed as heading to our shores after entering quarantine ...

Resources last updated: 2/8/2016 12:43:35 AM