Skip to content

Features

Jacques Nomssi edited this page Apr 15, 2018 · 46 revisions

Adapted from the Revised Report on the Algorithmic Language Scheme

Scheme is a statically scoped and properly tail recursive dialect of the Lisp programming language invented by Guy Lewis Steele Jr. and Gerald Jay Sussman. It was designed to have exceptionally clear and simple semantics and few different ways to form expressions.

Special Symbols

Boolean

  • #f is false, everything else is true in an expression
  • #t is true

Integer

Integers are mapped to ABAP type i. If you are on a newer Netweaver stack, Change the ABAP Code Definition to use type int8 in include YY_LIB_LISP

  TYPES tv_int TYPE i.            " integer data type, use int8 if available

Real

Reals are mapped to the decfloaf34 type.

  TYPES tv_real TYPE decfloat34.

Rational

Example of rational numbers:

1/3
(+ 3/5 0.4)

Special Symbols

  • nil is supported as the empty list '() for compatibility, but it is NOT true #t is Scheme.
  • eof-object

Definition

  • (define <variable> <expression>) binds one identifier to an expression.
  • (define (<func> <params>) <body>) defines a procedure (lambda) and binds one identifier to the function.

Procedure

A lambda expression (lambda <formals> <body>) evaluates to an anonymous procedure;

  • <formals> a list of formal parameters (arguments list)
  • <body> a sequence of zero or more definitions followed by one or more expressions to be evaluated
  • The environment in effect when the lambda expression was evaluated is remembered as part of the procedure.

When the procedure is later called with some actual arguments, the environment in which the lambda expression was evaluated will be extended by binding the variables in the formal argument list to fresh locations, and the corresponding actual argument values will be stored in those locations. (A fresh location is one that is distinct from every previously existing location.)

Next, the expressions in the body of the lambda expression (which, if it contains definitions, represents a letrec* form) will be evaluated sequentially in the extended environment.

The results of the last expression in the body will be returned as the results of the procedure call.

Syntactic extension

  • define-syntax not implemented yet

Hygienic macros are not implemented yet, but the keyword define-syntax is reserved. Support for non-hygienic macros is implemented with the special forms:

  • define-macro Common-Lisp style macros

  • macroexpand

  • gensym

Continuations

  • call-with-current-continuation and call/cc are reserved special forms not implemented yet

Other Binding constructs

  • do

  • (let <bindings> <body>) The binding constructs let, let*, letrec, letrec* give Scheme a block structure. The syntax is identical, but they differ in the regions they establish for their variable bindings. In a let expression, the initial values are computed before any of the variables become bound;

  • in a let* expression, the bindings and evaluations are performed sequentially;

  • in letrec and letrec* expressions, all bindings are in effect while their initial values are being computed, thus allowing mutually recursive definitions.

Conditional evaluation

  • if Evaluates the first argument. If true, the second argument is evaluated. If not, a third argument is evaluated, otherwise nil (false) is returned

  • (cond <clause1> <clause2> . . . ) The last <clause> can be an else clause, (else <expression1> <expression2> ... ).

  • (and <test1> ... ) The <test> expressions are evaluated from left to right, and if any expression evaluates to #f then #f is returned. Any remaining expressions are not evaluated. If all the expressions evaluate to true values, the values of the last expression are returned. If there are no expressions, then #t is returned.

  • (or <test1> ... ) The <test> expressions are evaluated from left to right, and the value of the first expression that evaluates to a true value is returned. Any remaining expressions are not evaluated. If all expressions evaluate to #f or if there are no expressions, then #f is returned.

  • case

  • unless

  • when

Sequential evaluation

  • begin is a sequencing construct: evaluates all arguments as expressions from left to right, and the value of the last expressio is returnd; a nice way to string a lot of expressions together to be executed

Iteration

  • lambda, do, named let

Quoting

  • quote Returns the argument verbatim, without evaluating it
  • quasiquote (nested quasiquoting not supported yet)
  • unquote ,
  • unquote-splicing ,@

Assignment

  • (set! <variable> <expression>) assigment. <Expression> is evaluated, and the resulting value is stored in the location to which <variable> is bound. It is an error if <variable> is not bound either in some region enclosing the set! expression or else globally. The result of the set! expression is unspecified.

Delayed evaluation

  • not implemented yet

Native Functions

  • read

  • newline

  • display

  • write (WiP)

  • not

  • apply

  • (map proc list1 list2 ... ) It is an error if proc does not accept as many arguments as there are lists and return a single value. The map procedure applies proc element-wise to the elements of the lists and returns a list of the results, in order. If more than one list is given and not all lists have the same length, map terminates when the shortest list runs out.

  • (for-each proc list1 list2 ... ) It is an error if proc does not accept as many arguments as there are lists. The arguments to for-each are like the arguments to map, but for-each calls proc for its side effects rather than for its values. Unlike map, for-each is guaranteed to call proc on the elements of the lists in order from the first element(s) to the last, and the value returned by for-each is unspecified. If more than one list is given and not all lists have the same length, for-each terminates when the shortest list runs out.

List functions

  • list makes a list out of all given arguments

  • (make-list m) returns a list of length n and every atom is an empty list

  • length length of given list

  • (list-tail list k) returns the subchain of list obtained by omitting the first k elements

  • (list-ref list k) returns the kth element of list.

  • list-copy returns a copy of a list.

  • (list->vector list) returns a newly created vector initialized to the elements of the list list. Order is preserved.

  • iota

  • null? Tests if the input is nil or not. returns #t if the object is the null list '(). It returns #t if the object is anything else.

  • cons takes two arguments and returns a new pair. The pair is list if the second argument is a list or the empty list. The first element is the head and the argument is the the tail.

     (cons '1 '2)          is   (1 . 2)
     (cons '1 '(2 3 4))      is   (1 2 3 4)
     (cons '(1 2 3) '(4 5 6))  is   ((1 2 3) 4 5 6)
    
  • car returns the first member of a list or a pair, or an exception is the argument is not a list or nil given an empty

     (car '(123 245 564 898))             is   123
     (car '(first second third))           is   first
     (car '(this (is no) more difficult))   is  this
    
  • cdr returns the tail of a list, which will be a list, or nil, given an empty list (or nil)

  • caar

  • cadr

  • cdar

  • cddr

  • set-car!

  • set-cdr!

  • append pure/functional append - Creates a new list by append the last element to the concatenation of all previous lists

  • append! unsafe append, faster

  • reverse reverse list

  • (memq obj list) return the first sublist of list whose car is obj, where the sublists of list are the non-empty lists returned by (list-tail list k) for k less than the length of list. If obj does not occur in list, then #f (not the empty list) is returned. memq uses eq? to compare obj with the elements of list

  • memv uses eqv? to compare obj with the elements of list

  • member uses equal? to compare obj with the elements of list

  • ( assq obj alist) association list (alist) must be a list of pairs: Find the first pair in alist whose car field is obj, and returns that pair. If no pair in alist has obj as its car, then #f (not the empty list) is returned. assq uses eq? to compare obj with the car fields of the pairs in alist, while assv uses eqv? and assoc uses equal?

  • assv

  • assoc

Vectors

  • make-vector
  • vector
  • vector-length
  • (vector-ref vector k)
  • (vector-set! vector k obj)
  • (vector->list vector start end) returns a newly allocated list of the objects contained in the elements of vector between start and end. Order is preserved. Start (inclusive) and End (exclusive) are optional

Chars

  • digit-value

  • char->integer

  • integer->char

  • char-uppercase

  • char-downcase

  • char-alphabetic?

  • char-numeric?

  • char-whitespace?

  • char-upper-case?

  • char-lower-case?

  • char=?

  • char<?

  • char>?

  • char<=?

  • char>=?

Predicates

  • nil? same als null? (alias added for compatibility with Common Lisp)

  • eq?

  • eqv?

  • equal? Tests if the given arguments are equal (either by symbol or number) or, in the case of a list, whether it is the same list. equal? returns the same as eqv? when applied to booleans, symbols, numbers, (WiP characters, ports,) procedures, and the empty list. If two objects are eqv?, they must be equal? as well. In all other cases, equal? may return either #t or #f. Even if its arguments are circular data structures, equal? must always terminate.

Type predicates

  • string?

  • hash?

  • number?

  • integer?

  • list?

  • vector?

  • pair?

  • procedure?

  • symbol?

  • boolean?

  • boolean=? accepts a list as argument

  • vector?

  • alist?

Comparison

  • >
  • >=
  • <
  • <=
  • =

Ports

  • current-input-port

  • current-output-port

  • current-error-port

  • open-input-string

  • open-output-string

  • get-output-string

  • close-input-port

  • close-output-port

  • close-error-port

  • input-port?

  • output-port?

  • textual-port?

  • binary-port?

  • input-port-open?

  • output-port-open?

  • eof-object?

Hash related

  • make-hash Create a hash
  • hash-get Get an element from a hash
  • hash-insert Insert an element into a hash
  • hash-remove Remove an element from a hash
  • hash-keys

Strings

  • string

  • make-string

  • number->string

  • string->number

  • string->list

  • string->symbol

  • symbol->string

  • string-append

  • string-length

  • string-copy

  • substring

  • string-set!

  • string=?

  • string-ci=?

  • string<?

  • string-ci<?

  • string>?

  • string-ci>?

  • string<=?

  • string-ci<=?

  • string>=?

  • string-ci>=?

Math

  • + add

  • - subtract

  • * multiply

  • / divide

  • abs

  • sin

  • cos

  • tan

  • asin

  • acos

  • atan

  • sinh

  • cosh

  • tanh

  • asinh

  • acosh

  • atanh

  • expt

  • exp

  • log

  • sqrt

  • floor

  • ceiling

  • truncate

  • round

  • remainder

  • modulo

  • quotient

  • random

  • max

  • min

  • gcd

  • lcm

Math Predicates

  • =
  • zero?
  • positive?
  • negative?
  • odd?
  • even?

ABAP Integration

  • ab-data

  • ab-function

  • ab-func-param

  • ab-table

  • ab-append-row (WiP)

  • ab-delete-row (WiP)

  • ab-get-row (WiP)

  • ab-get-value

  • ab-set-value

  • ab-get

  • ab-set

  • ab-sy

  • sql-query ADBC execute SQL

  • define-query ADBC prepare SQL

Clone this wiki locally