[RPL/2] Please explain this behaviour

BERTRAND Joël joel.bertrand at systella.fr
Lun 17 Déc 10:25:44 CET 2007


Adrian Blake wrote:
> I should explain a little more about what I would like to do.
> 
> I would like to have a sub-program that is altered by the main program and then that sub-program is re-compiled or evaluated. My 
> though was to take lists which contain the sub-program, alter those then re-compile. The lists would be long and contain other lists.

	I don't understand why you try to use lists. A list is a complex object 
that has no structure. You can put all you want in a list without any 
particular structure. An expression (algebraic or RPN) is a list that 
has a particular syntax and that _can_ be evaluated. Example:

RPL/2> { DO UNTIL FALSE }

1: { DO
      UNTIL
      FALSE }

cannot be evaluated. Thus, RPL/2> << do until false >> returns a syntax 
error (END statement is missing).

	First point: you have to use RPN expression, not list. Second point, if 
you try to evaluate a list, you evaluate this object from right to lef, 
and an expression has to be evaluated from left to right.

> One approach would be to create a main program that edit a text file/s that are the sub-programs, then use system calls to execute 
> then sub-programs.

	You have seen that you can modify list object with LIST->, ->LIST, GET, 
GETI, PUT, PUTI, SORT, SUB and others statements that handle lists. You 
can modify expressions with OBSUB (object substitution) and EXSUB 
(expression substitution). Warning, there are two types of expressions:
1/ expressions that are directly evaluatable like your program and that 
have an entry point:

TEST // <- your entry point, address of this function
<<
	"Hello, World" disp
 >>

2/ expressions that can only be evaluated by EVAL, ->NUM or variable 
evaluation (if this expression is stored in a variable) like

TEST // <- your entry point
<<
	<< "Hello, World" disp >>
	eval
 >>

These last expression are pulled in stack before evaluation. You can 
only modify these expressions because first one are static.

Example:

#!/usr/local/bin/rpl -s

TEST
<<
                 << "Heelo, World" disp >>
                 -> EXPRESSION
                 <<
                         EXPRESSION eval
                         EXPRESSION 2 2 { "Hello, World" } exsub eval
                 >>
 >>

and...
fermat:[~/programmes/test] > ./test7.rpl
+++RPL/2 version 4.0.0.prerelease.3 (dimanche 16.12.2007, 10:09:32 CET)
+++Copyright (C) 1989 à 2006, 2007 BERTRAND Joël
Heelo, World
Hello, World
fermat:[~/programmes/test] >

	If you execute step by step this program, you can see that EXPRESSION 
is modified by exsub (you can add HALT statement before EXSUB to see 
modifications. If you stop a program with HALT, you can continue with 
CONT and execute step by step with SST). EXSUB takes four arguments:
4/ expression that shall be modified
3/ start position (in number of token)
2/ end position
1/ list that contains new token. Length of this list can be different 
than the lenght of subtitued subexpression.

> Any suggestions welcome.

	You're welcome,

	JKB


Plus d'informations sur la liste de diffusion RPL2