RexxLA / NetRexx

Other
6 stars 0 forks source link

JSR223 jrunscript NetRexx shell runs only one-liners (was NETREXX-113) #13

Open rvjansen opened 2 years ago

rvjansen commented 2 years ago
$ jrunscript -cp $CLASSP ATH js> var saluton = 'Saluton!'; js> print(saluton);
Saluton!
The Python engine (Jython) running as shell:
$ jrunscript -cp jython-standalone-2.5.3.jar -l python python> saluton = 'Saluton!'
python> print saluton
Saluton!
The NetRexx engine:
jrunscript -cp $CLASSP ATH -l netrexx NetRexx> saluton = 'Saluton!'
It "fails" at this point: "W arning: Variable is set but not used".
NetRexx> say saluton
And "fails" again: "Error: Unknown variable". The intermediate source code used by the NetRexx engine is printed in each "failed" execution. JRuby also shares this behaviour:
$ jrunscript -cp jruby-complete-1.7.13.jar -l ruby ruby> saluton = 'Saluton!'
Saluton!
ruby> print saluton
NameError: undefined local variable or method `saluton' for main:Object
(root) at <STDIN>:1
script error: org.jruby .embed.EvalFailedException: (NameError) undefined loc al variable or method `saluton' for main:Object
rvjansen commented 2 years ago

Comment by Kermit Kiser [ 10/Jul/14 ] This seems like a "philosophy" question: Is the engine interpreting a statement or a program when a line is passed? Since jrunscript is a simple verification tool to see what is available and working or so it seems to me, I recommend doing nothing about this except perhaps documenting that each line in that environment is a separate program with it's own context. Multiple statements can be placed on a single line if needed.  

rvjansen commented 2 years ago

Comment by rvjansen [ 16/Feb/15 ] I would like this to work the same way other REPLS do this. - see Ruby's IR

rvjansen commented 2 years ago

Comment by Kermit Kiser [ 27/Apr/15 ] jrunscript passes each line separately to the jsr223 interface. I tested this and it cannot be altered even with option "-f -". jrunscript is a program in the Java sdk provided by Oracle and cannot be changed by the NetRexx team. By design NetRexx only translates and interprets complete programs not individual lines of code. Rather than making a mess out of the NetRexx JSR223 interface I suggest replacing the jrunscript program with the following NetRexx program which should act more like desired I think:


/* This program reads NetRexx statements from the command line and passes them to the NetRexx interpreter via the jsr223 interface. Enter a null line to execute the statements previously entered or to exit if no statements were entered since the last execute. */
import javax.script.
import org.netrexx.
br =BufferedReader(InputStreamReader(System.in))
nrEngine = ScriptEngineManager().getEngineByName("NetRexx")
loop foreverbr.mark(1024)
  input=br.readLine()
  if input="" then return br.reset()
   sb=StringBuilder(1024)

  loop forevernew=br.readLine()
  if new="" then do 
    nrEngine.put("result",null)
   say nrEngine.eval(sb.toString())
   leave
  end
  else sb.append(Rexx(new"\n").toString())
 end
end

 ```