Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
nomssi
Active Contributor


Three years ago, Martin Ceronio published a LISP interpreter in ABAP.


Today I am announcing ABAP Scheme, a Lisp interpreter in ABAP targeting the Revised revised revised revised revised revised revised Report on the Algorithmic Language Scheme, aka R7RS.

I am also excited to share the availability of the ABAP Scheme Workbench, a programming environment for Scheme.

Scheme: The Elegant Dialect of Lisp


From Wikipedia, the free encyclopedia:
Scheme is a functional programming language and one of the two main dialects of the programming language Lisp. Unlike Common Lisp, the other main dialect, Scheme follows a minimalist design philosophy specifying a small standard core with powerful tools for language extension.

Scheme is one of the four living dialects of Lisp, the other being Common Lisp, Emacs and Clojure.

LogoScheme

Lisp is a 60 year old family of computer languages that represent both source code and data using a tree data structure (s-expressions).












S-Expression
s-expression for (* 2 (+ 3 4)) workbench view (* 2 (+ 3 4))


In constrast to ABAP, Scheme is lexically scoped with proper tail call optimization.

Any valid Scheme code is also a valid tree structure. You can assign program code to a variable and execute it. Code is data, data is code. It is a common pattern to use the quote command to say just don't execute this code yet, treat it as data. 

What can you use it for?


Scheme is impressive at symbolic manipulation of data.

  • Create you own DSL

  • Learn real functional programming: map, fold, closures

  • Prototype ideas, scheme code is expressive (like, really, really short). Check the sample code

    • Symbolic derivation

    • Simple games

    • Adventure Game engine






Try to write this game in ABAP:
(begin (display "Please enter a number between 1 - 100: ")
(do ((quit #f)
(guess 0)
(answer (+ 1 (random 100))) )
(quit)
(set! guess (read))
(cond ((and (number? guess) (< guess answer)) (display "Too low. Please guess again: ") )
((and (number? guess) (> guess answer)) (display "Too high. Please guess again: ") )
(else (set! quit #t) (if (number? guess) (display "Correct!")
(display "Good bye...") ) ) ) ) )

Scheme vs. ABAP: A Comparative Insight


Scheme's philosophy differs significantly from ABAP. It offers:

Unlimited Object Extent: All objects created in the course of a Scheme computation, including procedures and continuations, have unlimited extent. No Scheme object is ever destroyed. But implementations are permitted to reclaim the storage occupied by an object if they can prove that the object cannot possibly matter to any future computation.

Tail-Recursive Design: Implementations of Scheme are required to be properly tail-recursive. With this, iteration can be efficently expressed by a syntactically recursive procedure without stack overflow (constant space), special iteration constructs are useful only as syntactic sugar.

Scheme procedures are objects in their own right. Procedures can be created dynamically, stored in data structures, returned as results of procedures, and so on.

First Class Continuations: [not implemented in ABAP Scheme]. A continuation is a procedure that does not return. Continuations, which in most other languages are used behind the scene for implementing a wide variety of advanced control constructs, including non-local exits, backtracking and co-routines, have first-class status in Scheme

Arithmetic Tower: Scheme’s model of arithmetic is designed to remain as independent as possible of the particular ways in which numbers are represented within a computer. In Scheme, every integer is a rational number, every rational is a real, and every real is a complex number. Thus the distinction between integer and real arithmetic, so important to many programming languages, does not appear in Scheme. In its place is a distinction between exact  arithmetic, which corresponds to the mathematical ideal, and inexact arithmetic on approximations. Exact arithmetic is not limited to integers.

Some Conventions


A command is a procedure that does not return useful values to its continuation.

A thunk is a procedure that does not accept arguments.

By convention, ? is the final character of the names of procedures that always return a boolean value. Such procedures are called predicates. Predicates are generally understood to be side-effect free, except that they may raise an exception when passed the wrong type of argument.

Similarly, ! is the final character of the names of procedures that store values into previously allocated locations (e.g. set!). Such procedures are called mutation procedures. The value returned by a mutation procedure is unspecied.

By convention, -> appears within the names of procedures that take an object of one type and return an analogous object of another type. For example, list->vector takes a list and returns a vector whose elements are the same as those of the list.

Getting Started: Your Path to ABAP Scheme


ABAP Scheme is available from Github and can be installed using from https://github.com/nomssi/abap_scheme using abapGit.

  • the repository master branch was tested on Netweaver 7.4 SP09.

  • the branch Netweaver-7.02 was downported to Netweaver 7.02


 


The code released with an MIT License:
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  DEALINGS IN THE SOFTWARE. 

Features


Check out the Wiki for documentation and sample code/games code.


Integration


When used as a script language, a single include YY_LIP_LISP is needed. Class lcl_lisp_interpreter evaluates your code from a string code, e.g
DATA(response) = NEW lcl_lisp_interpreter( )->eval_source( code ).

Workbench


The ABAP Scheme Workbench is the programming environment where ABAP Scheme programs are written and evaluated. It offers an editor, a console view and useful tools.


Recent Innovations



  • Regression test suite with 500+ ABAP unit tests

  • Nested quasi quotation

  • Trace Viewer


 

  • Graphical S-Expression Viewer using PlantUML server


 

  • a lot of R7RS language features

  • option to enable new ABAP editor with LISP syntax highlighting properties

  • Use registry solution to store/restore state/code


Planned Innovations



  • Debugger Script enhancement to display S-Expressions

  • Specify limit for execution time of interpreter



Product Direction



  • ABAP integration in the language and in the workbench with easy to use patterns for function module calls, method calls and SQL queries.

  • Powerfull scripting language in ABAP with hygienic macros, seamless ABAP interoperability


Product Vision



  • Support third party libraries

  • Wiki documentation with easy-to-try sample code in the style of The Little Schemer or Learn You a Haskell for Great Good


Credits



Final Notes


2 Comments