How to get the full name of a variable with ⎕REFS

General APL language issues

How to get the full name of a variable with ⎕REFS

Postby PGilbert on Sun Dec 12, 2021 12:24 am

In the following example:

      ∇ FOO;local;local2                                                            
[1]
[2] local←#.NS.var
[3] local2←#.NS.var2


⎕REFS 'FOO'
FOO
NS
local
local2
var
var2


⎕REFS is returning 'var' and 'var2' when I am looking to get the fully qualified variable name like '#.NS.var' and '#.NS.var2'. My ultimate goal is to check if all the variables of a function are valid variable names that exist. Is there an option in ⎕REFS to get the fully qualified names with their namespaces?

Thanks in advance.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada

Re: How to get the full name of a variable with ⎕REFS

Postby Adam|Dyalog on Sun Dec 12, 2021 5:02 am

First note that the problem is fundamentally impossible until runtime:
      b←×
∇ r←boo;a
[1] :If 1=?2
[2] a←+
[3] :Else
[4] a←⎕NS'b'
[5] :EndIf
[6] r←1 2 a.b 3 4

We cannot know if boo will use the global name b or not.

That said, some regex magic can get us most of the way there:
      ∇ Refs←{  ⍝ Like ⎕REFS but takes ⎕NR and returns vector of vectors                                      
[1] ⍺←0 ⍝ include sys-names?
[2] exSys←~⍺
[3] code←'''[^'']+''|(?:⍝|:(?:End)?Section|:Signature|:Attribute|:Require).*|:\w+'⎕R''⍠1⊢⍵
[4] code←':Access(?:\s+(?:public|private|instance|shared|webmethod|override|overridable))*'⎕R''⍠1⊢code
[5] code←':Implements\s+(?:constructor|destructor|method|trigger)'⎕R''⍠1⊢code
[6] inits←'A-Za-zÀ-ÖØ-Ýß-öø-üþⒶ-Ⓩ∆⍙_',exSys↓'⎕'
[7] sysNss←'⎕SE|⎕THIS|⎕BASE|⎕DMX'
[8] nsIds←'(?:',sysNss,')\.[',inits,']'
[9] code←nsIds'\.?⎕\w+'⎕R'&' ''⍣exSys⊢code
[10] names←'(?:##?|',sysNss,')?(?:\.?',exSys/'(?!⎕)'
[11] names,←'[',inits,'][',inits,'\d]*)+'
[12] list←∪names ⎕S'&'⊢code
[13] {⍵[⍋⍵]}list/⍣exSys⍨'⎕DMX'∘≢¨4↑¨list
[14] }

↑Refs⎕NR'FOO'
#.NS.var
#.NS.var2
FOO
local
local2
User avatar
Adam|Dyalog
 
Posts: 135
Joined: Thu Jun 25, 2015 1:13 pm

Re: How to get the full name of a variable with ⎕REFS

Postby PGilbert on Sun Dec 12, 2021 2:57 pm

Merci beaucoup Adam, this is answering my question.

You are very good.
User avatar
PGilbert
 
Posts: 436
Joined: Sun Dec 13, 2009 8:46 pm
Location: Montréal, Québec, Canada


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest