-
Notifications
You must be signed in to change notification settings - Fork 0
User Guide
For now, you can read the original announcement on SCN to get started with the interpreter: http://scn.sap.com/community/abap/blog/2015/06/24/a-lisp-interpreter-in-abap.
Copy the source from ZLIB_LISP.abap
into an include (type 'I') program of the same name (i.e. "ZLIB_LISB"). Copy the source from ZUSR_LISP_REPL.abap
into an executable program (type '1').
ZUSR_LISP_REPL
provides you with a very basic REPL (Read-Eval-Print loop) with which you can evaluate expressions. For examples, see the article at the above link. Or look at the source of program ZUSR_LISP_TESTS
for more examples.
ABAP Lisp follows the Scheme convention for defining functions. There is a shorthand built into define
which looks as follows:
(define (my-function x y z) (+ x y z))
When the first input to define
is a list, the first element of the list is taken as the symbol against which the function is stored. The elements following the symbols are the arguments. The elements following the function and signature are the body that will be evaluated when the function is called (though we don't say that functions are called in Lisp, everything is evaluated). (Currently only the first element of the function body is evaluated; see issue 2.
You can use the ABAP Lisp interpreter in your own program by including the interpreter and creating an instance of LCL_LISP_INTERPRETER. Then you can feed Lisp code straight to the interpreter. Here is an example:
include zlib_lisp.
data: lr_int type ref to lcl_lisp_interpreter.
data: lv_result type string.
create object lr_int. "Instantiate the interpreter
lv_result = lr_int->eval_source( '(define a 20) a' ).
write: / lv_result. "Or whatever you want to do with the output
The interpreter class maintains the state of the Lisp interpreter (i.e. everything you define etc. is stored as you evaluate more code). If you recreate the interpreter instance or exit the program your state is lost.