Question
· Apr 23

Internal of ObjectScript -- source code of Standard Library

Hello,

I am interested about reading the source code of the primitives of the system.  For example, I want to see how WRITE is implemented.

Can you help me to get a reflexive interrogation of the system ?

 

Kind regards,

 

Alin C Soare.

$ZV: IRIS 2024.1 for Windows 10
Discussion (9)4
Log in or sign up to continue

Hi,

The WRITE command, when passed no argument, does a reflexion on the system. I am not particularly interested about WRITE, but  I want to learn how to do self-reflection on the system, to find out the system status, and for this the best source of inspiration could be the system itself.  Apart from that, the source code of the system could be a source of inspiration for my own programs as well...  Something like that Lisp or Smalltalk programmers do all the time...

The WRITE command, when passed no argument, does a reflexion on the system.

Well, it simply list/write all defined variables in current stack level, something you can perform using standard Object Script commands and functions, no need to look at Write source code.

To do that you can use $order,  $query, and indirection, with some trick needed for the variables you use to perform the listing, or, maybe simpler, you can use output redirection (to a string for example) and then...well, an argument less Write command 😊

Some hint for the first option:

USER>set a=1,b=2,b(1)=3,x=""
 
USER>set x=$order(@x)
 
USER>write x
a
USER>set x=$order(@x)
 
USER>write x
b
USER>set x=$query(@x)
 
USER>w x
b(1)

For output redirection, see IO Redirect in ObjectScript in Open Exchange.