Question
Phillip Wu · Aug 7

Basic ObjectScript not working in Linux Command Line

I’m a complete novice with ObjectScript.

I’m trying to write some Object Script directly into command line interface on Linux using some examples on the internet

 

sudo -u irisowner iris session SCRTC

Username: superuser

Password: ************

AUMHSCRTC:USER>a SET x=1

AUMHSCRTC:USER> WHILE x<10 {

AUMHSCRTC:USER> WRITE !," Looping",x

AUMHSCRTC:USER> SET x=x+1

AUMHSCRTC:USER> }

AUMHSCRTC:USER> WRITE !,"DONE"

AUMHSCRTC:USER>do a

 Looping1

 Looping2

 Looping3

 Looping4

 Looping5

 Looping6

 Looping7

 Looping8

 Looping9

DONE

That seems to work!

 

How if I put these commands into a file:

cat > /tmp/a.scr

superuser

xyz

a SET x=1

 WHILE x<10 {

  WRITE !," Looping",x

  SET x=x+1

 }

 WRITE !,"DONE"

do a

 

Then:

cat /tmp/a.scr|sudo -u irisowner iris session SCRTC

 

DOES NOT work.

 

Why?

 

Also “routine” or “class” code in Wikipedia - https://en.wikipedia.org/wiki/Cach%C3%A9_ObjectScript these examples do not work either directly or in a file:

hello // hello world routine

    write "hello world"

end quit  // end

DO ^hello

 

AND

 

Class User.Helloworld

{

  ClassMethod HelloWorld()

  {

    // Write to console

    Write "Hello World"

    Quit

  }

}

DO ##class(User.Helloworld).HelloWorld()

Why?

Thanks for any help

0
0 371
Discussion (16)2
Log in or sign up to continue

you are mixing things.
#1) working:
1.1 yo talk to login + authentication
1.2 you talk to command prompt that stores your code locally. 
#2) not working
 authentication from script is not supported, the rest goes nowhere
#3) not working examples
both assume that
3.1 you enter the code in Studio, VSCode, ...and COMPILE  it.
3.2 you call the compiled code from the command line

Some ObjectScript does not require compiling eg. write

BUT some code does need compiling which are the examples that do not work.
What is the rule that says whether code needs compiling?

ALL code needs compiling. You just don't recognize it.
<tab> as the first separator indicates that you to want to store a local commandline.

WRITE<space>123 executes immediately while

WRITE<tab>123  stores a line labeled WRITE with a nonsense code 123

WRITE<tab>WRITE<apace>123  creates a useful command line that you may run by

DO<space>WRITE

This just explains what is happening. But this is not a programming tutorial.

Thanks.

I can program well in both compiled and scripted languages.

The reason for my previous query is that iris command tool can accept certain objectscript commands but others have to be submitted via iris studio

I don't understand how you get the first sample working. I'm getting expected <SYNTAX> error

USER>a SET x = 1 

A SET x = 1 
^
<SYNTAX>

that's because the browser or this horrible web editor converts <tab> to <blank>
this is just core MUMPS style for writing .INT code


AUMHSCRTC:USER>a<tab>SET x=1
AUMHSCRTC:USER><tab>WHILE x<10 {
AUMHSCRTC:USER><tab>WRITE !," Looping",x
AUMHSCRTC:USER><tab>SET x=x+1
AUMHSCRTC:USER><tab>}
AUMHSCRTC:USER><tab>WRITE !,"DONE"

AUMHSCRTC:USER>do a

Thanks for all the input.

Why is tab for IRIS terminal different from other whitespace like spaces?

It's an ages-old story dating back almost 50 years.
At that time code was not compiled but interpreted (as Python shell today)
the code was kept in the local partition and <tab> signaled that this is to be kept and not executed immediately.  Also, somelabel<tab> worked like that.

Today it is compiled undercover, but not kept.  Similar to the origin.

USER>SET X = 1 

It will assign a value to X variable 

USER>a SET x=1 it must be a typo error of 'a' that is why it gives syntax error