Execute in namespace
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
3 posts
• Page 1 of 1
Execute in namespace
I'm in the process of converting an application from bog-standard old-style non-OO APL to the latest Unicode version with all the bells and whistles, and I came across a problem where I want to set the value of a property, where the property name is held in a variable.
So I have this situation
REC is an instance of a class
P is the variable that contains the property name
X is the new value
To get the existing property value is simple: it is REC⍎M
However, I want to set the new value, so my first thought is to code (REC⍎P)←X
Silly me! That doesn't work! I have to code it as ⍎'REC.',P,'←X' which is a bit inelegant.
Is it possible to add an enhancement to APL that would make (REC⍎P)←X work?
(This sort of thing used to crop up often when I was using A+, where they had a solution called "execute in context", which used the % character. The solution to my problem there would be (REC%M)←X. Maybe that's what got me thinking along these lines.)
So I have this situation
REC is an instance of a class
P is the variable that contains the property name
X is the new value
To get the existing property value is simple: it is REC⍎M
However, I want to set the new value, so my first thought is to code (REC⍎P)←X
Silly me! That doesn't work! I have to code it as ⍎'REC.',P,'←X' which is a bit inelegant.
Is it possible to add an enhancement to APL that would make (REC⍎P)←X work?
(This sort of thing used to crop up often when I was using A+, where they had a solution called "execute in context", which used the % character. The solution to my problem there would be (REC%M)←X. Maybe that's what got me thinking along these lines.)
Jane
-
Budgie - Posts: 36
- Joined: Thu Nov 26, 2009 9:22 am
- Location: Beckenham
Re: Execute in namespace
As usual, dfns come to the rescue:
. . . P REC.{⍎⍺,'←⍵'}X
At least it doesn't require the key element names to be quoted.
Alternatively if you want all elements to be arguments to the function:
. . . REC{⍺.{⍎⍺,'←⍵'}/⍵}P X
In the latter case the dfn can be named:
. . . assign←{⍺.{⍎⍺,'←⍵'}/⍵}
. . . REC assign P X
. . . P REC.{⍎⍺,'←⍵'}X
At least it doesn't require the key element names to be quoted.
Alternatively if you want all elements to be arguments to the function:
. . . REC{⍺.{⍎⍺,'←⍵'}/⍵}P X
In the latter case the dfn can be named:
. . . assign←{⍺.{⍎⍺,'←⍵'}/⍵}
. . . REC assign P X
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: Execute in namespace
Another alternative syntactically closer to the thing being emulated:
. . . assign←{⍵{⍵ ⍺.{⍎⍺,'←⍵'}⍺⍺}/⍺{⍺}'space name assign value'}
. . . assign←{⍵{⍵ ⍺.{⍎⍺,'←⍵'}⍺⍺}/⍺{⍺}'space name assign value'}
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group