Page 1 of 1

VGET

PostPosted: October 22nd, 2018, 1:16 am
by Ajay Askoolum
I'd like the scope of []vget extended so that it can return the value of built-up expressions in order to avoid execute in code.

Code: Select all
      var←(,['']⊂[2]last_name),⊂[2]first_name     
      ⍴var
1000 2
      first←,1
      ⎕vget 'var[;first]'
DOMAIN ERROR
At present, I can execute the expression - would like to avoid this and use []vget instead
Code: Select all
      ⍴⍎ 'var[;first]'
1000 1
Generalize VGET to mean value get rather than variable get.

Re: VGET

PostPosted: October 22nd, 2018, 1:33 am
by Davin Church
Personally, I always wanted something like VGET that could return values at any level of the )SI, not just local and global. It seems to me that some version (perhaps APL2?) had a dyadic form of {execute} that took a left argument indicating the depth of the stack at which the expression was executed. Of course, that has complications if you try to execute a branch at a lower level of stack, and things like that. And {execute} is what you're trying to avoid with VGET, but perhaps you see my line of thinking.

Re: VGET

PostPosted: October 22nd, 2018, 2:01 am
by brent hildebrand
While on the topic of []VGET: The syntax is:
[]VGET 'varname' [default value]

the [default value] is executed no matter if varname is defined or not. It would seem [default value] be ignored if varname is defined. Here is an extreme example.
Code: Select all
      ⎕def 'ret←DefaultValue' '⎕dl 3 ⍝ simulate long calculation' 'ret←⎕ai'
DefaultValue

      ⎕vget 'var' DefaultValue
3.001
1 73.571 0 0
      var←1 2 3
      ⎕vget 'var' DefaultValue
3
1 2 3

Re: VGET

PostPosted: October 22nd, 2018, 3:32 am
by Ajay Askoolum
My scenario is quite simple.

Imagine that you have just read an Excel worksheet into an APL variable using COM. The Excel source had column names in the first row. If follows that the APL variable has rows in the first row also.

I am attempting to index the APL variable by the name of the column.

(var[1;]) {comes from} {iota} {shape} var[1;]

If var[1;] had Name Gender Salary, I should get values out using var[;,Gender] etc.

[]VGET should evaluate an expression and if that fails, it should return the default value. Right now, it appears to look up the symbol table to figure out what to return.

(I don't have APL on this PC, hence the names of symbols and not the symbols themselves.)

PS: I looked at []eval - frankly, given the way it works, its purpose is lost on me.

Re: VGET

PostPosted: October 22nd, 2018, 11:33 am
by Davin Church
Ajay Askoolum wrote:PS: I looked at []eval - frankly, given the way it works, its purpose is lost on me.

IIRC, []EVAL was entirely about allowing extremely long arguments.