How to get the full name of a variable with ⎕REFS
3 posts
• Page 1 of 1
How to get the full name of a variable with ⎕REFS
In the following example:
⎕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.
∇ 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.
-
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
First note that the problem is fundamentally impossible until runtime:
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:
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
-
Adam|Dyalog - Posts: 137
- Joined: Thu Jun 25, 2015 1:13 pm
Re: How to get the full name of a variable with ⎕REFS
Merci beaucoup Adam, this is answering my question.
You are very good.
You are very good.
-
PGilbert - Posts: 436
- Joined: Sun Dec 13, 2009 8:46 pm
- Location: Montréal, Québec, Canada
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: Bing [Bot] and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group