Vitaliy Serdtsev · Feb 14, 2019 go to post

Still another option:

<FONT COLOR="#000080">Class dc.test Extends %Persistent
</FONT><FONT COLOR="#000000">{

</FONT><FONT COLOR="#000080">Property </FONT><FONT COLOR="#000000">JSONData </FONT><FONT COLOR="#000080">As list Of %String </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">SqlListType </FONT><FONT COLOR="#000000">= SUBNODE ];

</FONT><FONT COLOR="#000080">ClassMethod </FONT><FONT COLOR="#000000">Test() {   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">..</FONT><FONT COLOR="#0000ff">%KillExtent</FONT><FONT COLOR="#000000">()      </FONT><FONT COLOR="#0000ff">f </FONT><FONT COLOR="#800000">l</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"apple"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"pear"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"plum"</FONT><FONT COLOR="#000000">),</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Kyle"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%ToJSON</FONT><FONT COLOR="#000000">(),</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Evgeny"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%ToJSON</FONT><FONT COLOR="#000000">()) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=..</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">JSONData</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">InsertList</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">l</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Save</FONT><FONT COLOR="#000000">()   </FONT><FONT COLOR="#800080">}

  </FONT><FONT COLOR="#0000ff">zw </FONT><FONT COLOR="#000000">@</FONT><FONT COLOR="#0000ff">$system</FONT><FONT COLOR="#008080">.Dictionary</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">comMemberKeyGet</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$this</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$cCLASSstorage</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$nameDefaultStorageNameGet</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$cSDEFdatalocation</FONT><FONT COLOR="#000000">)      </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%SQL.Statement</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ExecDirect</FONT><FONT COLOR="#000000">(,</FONT><FONT COLOR="#008000">"select distinct json_arrayagg(JSONData %foreach(test)) from dc.test_JSONData"</FONT><FONT COLOR="#000000">)   </FONT><FONT COLOR="#0000ff">while </FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Next</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">jsonStr</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">rs</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%GetData</FONT><FONT COLOR="#000000">(1),       </FONT><FONT COLOR="#800000">json</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#ff00ff">[]</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%FromJSON</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">jsonStr</FONT><FONT COLOR="#000000">)

    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#000000">!,</FONT><FONT COLOR="#800000">jsonStr</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">", %Size()="</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">json</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">%Size</FONT><FONT COLOR="#000000">(),!   </FONT><FONT COLOR="#800080">} </FONT><FONT COLOR="#000000">}

}</FONT>

Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">dc.test</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Test</FONT><FONT COLOR="#000000">()</FONT>
<FONT COLOR="#000000">^dc.testD=2
</FONT><FONT COLOR="#000000">^dc.testD(1)=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">)=3
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,1)=</FONT><FONT COLOR="#008000">"apple"
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,2)=</FONT><FONT COLOR="#008000">"pear"
</FONT><FONT COLOR="#000000">^dc.testD(1,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,3)=</FONT><FONT COLOR="#008000">"plum"
</FONT><FONT COLOR="#000000">^dc.testD(2)=</FONT><FONT COLOR="#0000ff">$lb</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">)
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">)=2
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,1)=</FONT><FONT COLOR="#008000">"{""Name"":""Kyle""}"
</FONT><FONT COLOR="#000000">^dc.testD(2,</FONT><FONT COLOR="#008000">"JSONData"</FONT><FONT COLOR="#000000">,2)=</FONT><FONT COLOR="#008000">"{""Name"":""Evgeny""}"</FONT>

<FONT COLOR="#ff00ff">[</FONT><FONT COLOR="#008000">"apple"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"pear"</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#008000">"plum"</FONT><FONT COLOR="#ff00ff">]</FONT>, %Size()=3

<FONT COLOR="#ff00ff">[{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Kyle"</FONT><FONT COLOR="#ff00ff">}</FONT><FONT COLOR="#808080">,</FONT><FONT COLOR="#ff00ff">{</FONT><FONT COLOR="#008000">"Name"</FONT><FONT COLOR="#808080">:</FONT><FONT COLOR="#008000">"Evgeny"</FONT><FONT COLOR="#ff00ff">}]</FONT>, %Size()=2

Doc:
Vitaliy Serdtsev · Jan 16, 2019 go to post
if I call giveMeAFalseMe from Cache when it's returning "true" or "false", Cache will translate "true" into a truthy %Boolean return value, right?

No, it does zenBool, which is on the client side.

The important thing is that #server()# always returns a string, for example:

<script language="cache" method="giveMeAFalse" arguments="" procedureblock='1' returntype="%Integer">return 4</script>var bool #server(..giveMeAFalse())#;
console.log("bool = " bool);
console.log("typeof bool = "typeof bool);

Result:
bool = 4
typeof bool =  string
PS: you can further explore the sources of the #server()# -> cspHttpServerMethod() -> cspProcessResponse(), which are in the file cspxmlhttp.js.
Vitaliy Serdtsev · Jan 15, 2019 go to post

See zenConvertType() [///Converts a typed value returned from the server to an appropriate JS type] from zenutils.js.

Try this:

<script src="zenutils.js"></script>

<script language="javascript">
function isItActuallyFalse() {

var bool zenConvertType('BOOLEAN',#server(..giveMeAFalse())#);

...
}

</script>

<script language="cache" method="giveMeAFalse" arguments="" returntype="%Boolean" procedureblock='1'>return $$$NO</script>
or
var bool zenBool(#server(..giveMeAFalse())#);

... <<FONT COLOR="#ff0000">script </FONT><FONT COLOR="#000080">language</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"cache" </FONT><FONT COLOR="#000080">method</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"giveMeAFalse" </FONT><FONT COLOR="#000080">arguments</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"" </FONT><FONT COLOR="#000080">returntype</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">"%Boolean" </FONT><FONT COLOR="#000080">procedureblock</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800080">'1'</FONT><FONT COLOR="#000000">></FONT><FONT COLOR="#0000ff">return </FONT><FONT COLOR="#008000">"false"</FONT><FONT COLOR="#000000"></</FONT><FONT COLOR="#ff0000">script</FONT><FONT COLOR="#000000">></FONT>

Vitaliy Serdtsev · Dec 31, 2018 go to post
tags=$lb("a","b","c"),
  str="c,a1,d,b,f"
   
l=$lfs(str),ptr=0
while $listnext(tags,ptr,tag{
  w:$lf(l,tagtag,!
}
Result

b c

Vitaliy Serdtsev · Nov 2, 2018 go to post

No. If you beware to use %occLibrary, you may look into side %Regex.Matcher

Here is another documented solution:

<FONT COLOR="#0000ff">#include </FONT><FONT COLOR="#000000">%systemInclude
  </FONT><FONT COLOR="#0000ff">n
  try</FONT><FONT COLOR="#800080">{

    </FONT><FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">TAB </FONT><FONT COLOR="#0000ff">$c(9)          s </FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"""ABC,"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(10)</FONT><FONT COLOR="#008000">" Company,"",""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901,""Anytown"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#0000ff">$$$TAB</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">"DC"""

    </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%DeepSee.TermList</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%ParseCSVRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">,.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">)

    </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">csv</FONT><FONT COLOR="#000000">,!!,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">WriteCSVRecord</FONT><FONT COLOR="#000000">(.</FONT><FONT COLOR="#800000">arr</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$$$TAB</FONT><FONT COLOR="#000000">)

  </FONT><FONT COLOR="#800080">}</FONT><FONT COLOR="#0000ff">catch</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">)</FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"Error "</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">ex</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayString</FONT><FONT COLOR="#000000">(),!   </FONT><FONT COLOR="#800080">}

</FONT><FONT COLOR="#ff0000">WriteCSVRecord</FONT><FONT COLOR="#000000">(&pRecord, pDelim=</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">, pEncode=</FONT><FONT COLOR="#0000ff">$$$YES</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{   </FONT><FONT COLOR="#008000">// made on the basis of the method %WriteCSVRecord   </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">""   </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$O</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">))   </FONT><FONT COLOR="#0000ff">While </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">'=</FONT><FONT COLOR="#008000">""</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800080">{     </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">tValue </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$G</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">Set</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#0000ff">$G</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pEncode</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#800000">tValue </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$ZCVT</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"O"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"UTF8"</FONT><FONT COLOR="#000000">) 

    </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000"> </FONT><FONT COLOR="#0000ff">$S</FONT><FONT COLOR="#000000">((</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#008000">""""</FONT><FONT COLOR="#000000">)||(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">)||(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#800000">pDelim</FONT><FONT COLOR="#000000">):</FONT><FONT COLOR="#0000ff">$$$quote</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">),1:</FONT><FONT COLOR="#800000">tValue</FONT><FONT COLOR="#000000">)     </FONT><FONT COLOR="#0000ff">Set </FONT><FONT COLOR="#800000">k </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#0000ff">$O</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">pRecord</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">))     </FONT><FONT COLOR="#0000ff">Set</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">k</FONT><FONT COLOR="#000000">'=</FONT><FONT COLOR="#008000">"" </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#000000"> </FONT><FONT COLOR="#800000">pDelim   </FONT><FONT COLOR="#800080">}   </FONT><FONT COLOR="#0000ff">Quit </FONT><FONT COLOR="#800000">r </FONT><FONT COLOR="#800080">}</FONT>

Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^dc</FONT>
"ABC,
Company,","123 Main St, Ste 102","Anytown, DC",10001,234-567-8901,"Anytown        DC"

"ABC, Company," "123 Main St, Ste 102" "Anytown, DC" 10001 234-567-8901 "Anytown DC"

Vitaliy Serdtsev · Nov 1, 2018 go to post
#include %systemInclude

    csv="ABC Company,""123 Main St, Ste 102"",""Anytown, DC"",10001,234-567-8901"
    list=$$CSVtoList^%occLibrary(csv)

    i=1:1:$ll(lists:$li(list,i)["," $li(list,i)=$$$quote($li(list,i))
        
    csv,!,$lts(list,$c(9))
Result:
USER>^test

ABC Company,"123 Main St, Ste 102","Anytown, DC",10001,234-567-8901 ABC Company "123 Main St, Ste 102" "Anytown, DC" 10001 234-567-8901

Vitaliy Serdtsev · Nov 1, 2018 go to post

Maybe the name of the topic to specify a CSV-string instead of string ?

After clarification, the question became more clear.

Vitaliy Serdtsev · Nov 1, 2018 go to post

<FONT COLOR="#0000ff">$tr</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">str</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9))</FONT> or <FONT COLOR="#0000ff">$replace</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">str</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$c</FONT><FONT COLOR="#000000">(9))</FONT>

Vitaliy Serdtsev · Nov 1, 2018 go to post

I was looking at the generated INT code for <FONT COLOR="#800080">&sql(</FONT><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#008000">n</FONT><FONT COLOR="#800080">)</FONT>

Unfortunately, for COS at the moment I have not found an analogue LPADSQL. Can you offer a documented LPADCOS ?

Vitaliy Serdtsev · Oct 30, 2018 go to post

Once upon a time promised to make Server-Side JavaScript alongside with Caché ObjectScript and Caché Basic:

I found a JS Runtime Shell that uses Node.JS & esprima:

SAMPLES><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%CPT.JS.Runtime.Shell</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">Run</FONT><FONT COLOR="#000000">()</FONT>

JRS> ?

.L CLASS - load javascript methods from CLASS into JS global namespace .LV var,.. - load the given COS public vars into JS global namespace

.S FUNC - list the source of the method which implements function FUNC - FUNC must be in the global namespace - the whole implementing method is shown, even for an inner function - this will also work for non-javascript methods .M - list MAC code from latest compilation .I - list INT code from latest compilation .T - show latest tree

.G - list global symbols

.N CODE - execute JS on node.js .N - execute the last-entered line of JS on node.js

.CONFIG ... - passed to %CPT.CalloutShell 'CONFIG' command

.SET ... - passed to %CPT.CalloutShell 'SET' command .CLEAR ... - passed to %CPT.CalloutShell 'CLEAR' command .SHOW ... - passed to %CPT.CalloutShell 'SHOW' command

!COS - execute a line of COS

Anything else is interpreted as JS. :-

  • if preceded by "=" it must be a single function definition
  • otherwise it can be either a single expression or a sequence of statements separated by ";"s

Either way it will be compiled into a function body and :-

  • if preceded by "==" it is stored as a JS global with the new function's name
  • otherwise it will just be executed

\n can be used to represent a newline.

You can also take input from a file :- <FILE - read JS from FILE and compile+execute it <=FILE - read JS from FILE and compile+store it

The result of the execution is shown and also stored in global variable '_'.

For a global variable, set it without using 'var' (this will be fixed)

JRS> .N <FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">obj </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">{ name: </FONT><FONT COLOR="#800000">"John"</FONT><FONT COLOR="#000000">, age: </FONT><FONT COLOR="#000080">30</FONT><FONT COLOR="#000000">, city: </FONT><FONT COLOR="#800000">"New York" </FONT><FONT COLOR="#000000">}; JSON.stringify(obj);</FONT> {result: "{""name"":""John"",""age"":30,""city"":""New York""}"}

JRS> .N Math.random() {result: .5670654247514904}

JRS> .N <FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">fruits </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">[</FONT><FONT COLOR="#800000">"Banana"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Orange"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Apple"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">"Mango"</FONT><FONT COLOR="#000000">]; fruits.sort();</FONT> {result: ["Apple", "Banana", "Mango", "Orange", 1: "Apple", 2: "Banana", 3: "Mango", 4: "Orange"]}

JRS> q

SAMPLES>

Vitaliy Serdtsev · Oct 30, 2018 go to post

If you do universal LPAD, it is best $$lpad^%qarfunc, because for certain arguments may produce an incorrect result, for example:

<FONT COLOR="#0000ff">#define </FONT><FONT COLOR="#000000">lpad(%s,%len,%pad) </FONT><FONT COLOR="#0000ff">$tr($j(%s,%len),</FONT><FONT COLOR="#008000">" "</FONT><FONT COLOR="#0000ff">,%pad)
   
s </FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"a b"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">=8,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"0"
   
</FONT><FONT COLOR="#0000ff">w $$$lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">lpad</FONT><FONT COLOR="#000000">^%qarfunc(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">pad</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$$lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">),!
 ,</FONT><FONT COLOR="#0000ff">$$</FONT><FONT COLOR="#ff0000">lpad</FONT><FONT COLOR="#000000">^%qarfunc(</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">len</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">s</FONT><FONT COLOR="#000000">),!</FONT>
Result:
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT>
<FONT COLOR="red">00000a0b</FONT>
<FONT COLOR="green">00000a b</FONT>
<FONT COLOR="red">aaaaaaab</FONT>
<FONT COLOR="green">a ba a b</FONT>
Vitaliy Serdtsev · Oct 29, 2018 go to post

Also LPADSQL
USER><FONT COLOR="#0000ff">d $system</FONT><FONT COLOR="#008080">.SQL</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Shell</FONT><FONT COLOR="#000000">()</FONT>
SQL Command Line Shell

The command prefix is currently set to: <>. Enter q to quit, ? for help. USER>><FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#008000">n</FONT>

  1.  <FONT COLOR="#0000ff">select&nbsp;</FONT><FONT COLOR="#008000">lpad</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">'1'</FONT><FONT COLOR="#000000">,4,</FONT><FONT COLOR="#008080">'0'</FONT><FONT COLOR="#000000">)&nbsp;</FONT><FONT COLOR="#008000">n</FONT>
    

n 0001

1 Rows(s) Affected

Vitaliy Serdtsev · Oct 29, 2018 go to post

The functions from %qarfunc are actively used in system classes, so I don't think ^%qarfunc will be removed in the near future, otherwise everything will stop working.

Vitaliy Serdtsev · Oct 19, 2018 go to post

Try

<FONT COLOR="#000080">ClientMethod </FONT><FONT COLOR="#000000">changeParams() [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ]
{
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">query </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'categorieBeneficiaire'</FONT><FONT COLOR="#000000">);
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">param1 </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'catBParam1'</FONT><FONT COLOR="#000000">);
  </FONT><FONT COLOR="#008080">var </FONT><FONT COLOR="#000000">param2 </FONT><FONT COLOR="#000080">= </FONT><FONT COLOR="#000000">zen(</FONT><FONT COLOR="#800000">'catBParam2'</FONT><FONT COLOR="#000000">);

  param1.value</FONT><FONT COLOR="#000080">=</FONT><FONT COLOR="#800000">'OS'</FONT><FONT COLOR="#000000">;   param2.value</FONT><FONT COLOR="#000080">=</FONT><FONT COLOR="#800000">'NSAL'</FONT><FONT COLOR="#000000">;   query.refreshContents(); }</FONT>

<FONT COLOR="#000080">/// This client event, if present, is fired when the page is loaded. ClientMethod </FONT><FONT COLOR="#000000">onloadHandler() [ </FONT><FONT COLOR="#000080">Language </FONT><FONT COLOR="#000000">= javascript ] {   zenPage.changeParams(); }</FONT>

Vitaliy Serdtsev · Oct 17, 2018 go to post

or <FONT COLOR="#0000ff">w $zcvt</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">x</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"I"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"HTML"</FONT><FONT COLOR="#000000">)</FONT>

Vitaliy Serdtsev · Oct 9, 2018 go to post

Another variants:

USER><FONT COLOR="#0000ff">k  s </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">=3,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(1)=</FONT><FONT COLOR="#008000">"-h"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(2)=21,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(3)=</FONT><FONT COLOR="#008000">"community.intersystems.com" </FONT><FONT COLOR="#0000ff">do $system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Net.Remote.Utility</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">RunCommandViaCPIPE</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"tracert"</FONT><FONT COLOR="#000000">,,.</FONT><FONT COLOR="#800000">output</FONT><FONT COLOR="#000000">,,900,.</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">)) </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">output</FONT>

or

USER><FONT COLOR="#0000ff">k  s </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">=3,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(1)=</FONT><FONT COLOR="#008000">"-h"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(2)=21,</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">(3)=</FONT><FONT COLOR="#008000">"community.intersystems.com" </FONT><FONT COLOR="#0000ff">do $system</FONT><FONT COLOR="#008080">.OBJ</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">DisplayError</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Net.Remote.Utility</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">RunCommandViaZF</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"tracert"</FONT><FONT COLOR="#000000">,,.</FONT><FONT COLOR="#800000">output</FONT><FONT COLOR="#000000">,,900,,.</FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">)) </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">output</FONT>

Vitaliy Serdtsev · Oct 2, 2018 go to post

Changed a bit and added new code:

<FONT COLOR="#000080">/// d ##class(Scratch.test).ClassVsInst()
ClassMethod </FONT><FONT COLOR="#000000">ClassVsInst(</FONT><FONT COLOR="#ff00ff">N </FONT><FONT COLOR="#000000">= {1e6}) [ </FONT><FONT COLOR="#000080">ProcedureBlock </FONT><FONT COLOR="#000000">= 0, </FONT><FONT COLOR="#000080">PublicList </FONT><FONT COLOR="#000000">= st ]
{
   </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">xClass</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">xInst</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">st
   
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"пропоывшыщзшвыщшв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"гшщыгвыовлдыовдьыовдлоыдлв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"widuiowudoiwudoiwudoiwud"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"прпроыпворыпворыпворыпв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"uywyiusywisywzxbabzjhagjЭ"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"пропоывшыщзшвыщшв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"гшщыгвыовлдыовдьыовдлоыдлв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"widuiowudoiwudoiwudoiwud"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"прпроыпворыпворыпворыпв"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"uywyiusywisywzxbabzjhagjЭ"
    
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xClass</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"(args...) f i=1:1:N s sc=##class(Scratch.test).%1(args...)"
    </FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xInst</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"(args...) f i=1:1:N s sc=st.%1(args...)"
   
   
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">st</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">Scratch.test</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">()
   
   </FONT><FONT COLOR="#0000ff">w $p</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$zv</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"(Build"</FONT><FONT COLOR="#000000">),!!
   
   </FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#ff0000">runClassmethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass10"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass10"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInst10"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runClassmethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass5"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass5"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInst5"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runClassmethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClassNull"</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClassNull"</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInstNull"</FONT><FONT COLOR="#000000">)
   
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass10"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xClass</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInst10"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xInst</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p6</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p7</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p8</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p9</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p10</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClass5"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xClass</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInst5"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xInst</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p1</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p2</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p3</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p4</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">p5</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyClassNull"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xClass</FONT><FONT COLOR="#000000">)
    ,</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"dummyInstNull"</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">xInst</FONT><FONT COLOR="#000000">)
  
</FONT><FONT COLOR="#ff0000">runMethod</FONT><FONT COLOR="#000000">(methodname,args...)
   </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">sc
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">sc</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$method</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">st</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">...)
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh</FONT><FONT COLOR="#000000">-</FONT><FONT COLOR="#800000">t </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000">,?16,</FONT><FONT COLOR="#008000">"total time = "</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,?38,</FONT><FONT COLOR="#008000">"avg time = "</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">/</FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">),!
   </FONT><FONT COLOR="#0000ff">q
</FONT><FONT COLOR="#ff0000">runClassmethod</FONT><FONT COLOR="#000000">(methodname,args...)
   </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">sc
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh f </FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">=1:1:</FONT><FONT COLOR="#800000">N </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">sc</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$classmethod</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">"Scratch.test"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">...)
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh</FONT><FONT COLOR="#000000">-</FONT><FONT COLOR="#800000">t </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#008000">"*"</FONT><FONT COLOR="#000000">,?16,</FONT><FONT COLOR="#008000">"total time = "</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,?38,</FONT><FONT COLOR="#008000">"avg time = "</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">/</FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">),!
   </FONT><FONT COLOR="#0000ff">q
</FONT><FONT COLOR="#ff0000">runX</FONT><FONT COLOR="#000000">(methodname,x,args...)
   </FONT><FONT COLOR="#0000ff">n </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">i</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">sc
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh
   x </FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$$$FormatText</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">x</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000">), </FONT><FONT COLOR="#800000">args</FONT><FONT COLOR="#000000">...)
   </FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#0000ff">$zh</FONT><FONT COLOR="#000000">-</FONT><FONT COLOR="#800000">t </FONT><FONT COLOR="#0000ff">w </FONT><FONT COLOR="#008000">"X"</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">methodname</FONT><FONT COLOR="#000000">,?16,</FONT><FONT COLOR="#008000">"total time = "</FONT><FONT COLOR="#000000"></FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">,?38,</FONT><FONT COLOR="#008000">"avg time = "</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">t</FONT><FONT COLOR="#000000">/</FONT><FONT COLOR="#800000">N</FONT><FONT COLOR="#000000">),!
   </FONT><FONT COLOR="#0000ff">q
</FONT><FONT COLOR="#000000">}</FONT>
Result:

USER>##class(Scratch.test).ClassVsInst()
Cache for Windows (x86-64) 2018.1
 
dummyClass10*   total time = .328227  avg time = .000000328227
dummyClass10    total time = .27655   avg time = .00000027655
dummyInst10     total time = .259913  avg time = .000000259913
dummyClass5*    total time = .286983  avg time = .000000286983
dummyClass5     total time = .25666   avg time = .00000025666
dummyInst5      total time = .240312  avg time = .000000240312
dummyClassNull* total time = .274406  avg time = .000000274406
dummyClassNull  total time = .250926  avg time = .000000250926
dummyInstNull   total time = .234486  avg time = .000000234486
XdummyClass10   total time = .312917  avg time = .000000312917
XdummyInst10    total time = .264871  avg time = .000000264871
XdummyClass5    total time = .286985  avg time = .000000286985
XdummyInst5     total time = .238557  avg time = .000000238557
XdummyClassNull total time = .278684  avg time = .000000278684
XdummyInstNull  total time = .236815  avg time = .000000236815
Vitaliy Serdtsev · Sep 17, 2018 go to post

Still can be so:

<FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">relation_name tablename</FONT><FONT COLOR="#000000">,
       </FONT><FONT COLOR="#008000">%Library</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">SQLCatalog_SQLClassname</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">relation_name</FONT><FONT COLOR="#000000">) </FONT><FONT COLOR="#008000">classname

</FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">%Library</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">SQLCatalog_SQLTables</FONT><FONT COLOR="#000000">()

-- where relation_name [ 'aaa'</FONT>

Vitaliy Serdtsev · Sep 14, 2018 go to post

I have a few comments.:

  1. your code finds by the class name, not the table name, which is confusing

    For example, for the next class, the method finds nothing:

    <FONT COLOR="#000080">Class dc.test Extends %Persistent </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#000080">SqlTableName </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">aaa </FONT><FONT COLOR="#000000">] { ... }</FONT>

    USER>##class(objectscript.findTable).test("aaa")
    ?
  2. according to the documentation, your code uses the deprecated API:
    proof The Caché Library set of class definitions classes has been superseded by the %Dictionary package. The %Library classes described here are maintained for compatibility with existing applications.

    New code should make use of the classes within the %Dictionary package.

  3. in fact, the search is done elementary:

    <FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">ClassName </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">%Dictionary</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">ClassDefinition_ClassIndex</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#008000">ClassName </FONT><FONT COLOR="#000000">[ </FONT><FONT COLOR="#008080">'test'</FONT>

    or

    <FONT COLOR="#0000ff">select </FONT><FONT COLOR="#008000">ClassName </FONT><FONT COLOR="#000080">from </FONT><FONT COLOR="#008000">%Dictionary</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#008000">ClassDefinition_ClassIndex</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#000080">where </FONT><FONT COLOR="#808000">nvl</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008000">SqlTableName</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">ClassName</FONT><FONT COLOR="#000000">) [ </FONT><FONT COLOR="#008080">'aaa'</FONT>