-
Notifications
You must be signed in to change notification settings - Fork 5
Features
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.
-
#fis false, everything else is true in an expression -
#tis true
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
Reals are mapped to the decfloaf34 type.
TYPES tv_real TYPE decfloat34.
Example of rational numbers:
1/3
(+ 3/5 0.4)
-
nilis supported as the empty list'()for compatibility, but it is NOT true #t is Scheme. eof-object
-
(define <variable> <expression>)binds one identifier to an expression. -
(define (<func> <params>) <body>)defines a procedure (lambda) and binds one identifier to the function.
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.
-
define-syntaxnot 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-macroCommon-Lisp style macros -
macroexpand -
gensym
-
call-with-current-continuationandcall/ccare reserved special forms not implemented yet
-
do -
(let <bindings> <body>)The binding constructslet,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 aletexpression, the initial values are computed before any of the variables become bound; -
in a
let*expression, the bindings and evaluations are performed sequentially; -
in
letrecandletrec*expressions, all bindings are in effect while their initial values are being computed, thus allowing mutually recursive definitions.
-
ifEvaluates 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#fthen#fis 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#tis 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 <key> <clause_1> <clause_2> ...)can be any expression. Each clause has the form((<datum_1> ...) <expression_1> <expression_2> ...). Alternatively, a<clause>can be of the form((<datum_1> ...) => <expression>). The last<clause>can be an else clause, which has one of the forms(else <expression_1> <expression_2> ...)or(else => <expression>).(case (* 2 3) ((2 3 5 7) 'prime) ((1 4 6 8 9) 'composite)) ; => composite (case (car '(c d)) ((a) 'a) ((b) 'b)) ; => unspecified '() (case (car '(c d)) ((a e i o u) 'vowel) ((w y) 'semivowel) (else => (lambda (x) x))) ; => c
Guarded Evaluation:
-
(unless <test> <expression_1> <expression_2> ...)If expression<test>evaluates to#f, then the expressions are evaluated in order. The value of the last expression is returned, or'(). -
(when <test> <expression_1> <expression_2> ...)If expression<test>evaluates to a true value, the expressions are evaluated in order. The value of the last expression is returned, or'().
-
beginis 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
-
lambda,do,named let
-
quoteReturns the argument verbatim, without evaluating it -
quasiquote(nested quasiquoting not supported yet) -
unquote, -
unquote-splicing,@
-
(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 theset!expression or else globally. The result of theset!expression is unspecified.
- not implemented yet
-
read -
newline -
display -
write(WiP) -
not -
apply -
(map proc list1 list2 ... )It is an error ifprocdoes not accept as many arguments as there are lists and return a single value. Themapprocedure appliesprocelement-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 ifprocdoes not accept as many arguments as there are lists. The arguments tofor-eachare like the arguments tomap, butfor-eachcallsprocfor its side effects rather than for its values. Unlikemap,for-eachis guaranteed to callprocon the elements of the lists in order from the first element(s) to the last, and the value returned byfor-eachis unspecified. If more than one list is given and not all lists have the same length,for-eachterminates when the shortest list runs out.
-
listmakes a list out of all given arguments -
(make-list m)returns a list of length n and every atom is an empty list -
lengthlength 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-copyreturns 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. -
constakes 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) -
carreturns 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 -
cdrreturns 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! -
appendpure/functional append - Creates a new list by append the last element to the concatenation of all previous lists -
append!unsafe append, faster -
reversereverse list -
(memq obj list)return the first sublist of list whosecarisobj, 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.memquseseq?to compare obj with the elements of list -
memvuseseqv?to compare obj with the elements of list -
memberusesequal?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 whosecarfield isobj, and returns that pair. If no pair inalisthasobjas itscar, then#f(not the empty list) is returned.assquseseq?to compareobjwith thecarfields of the pairs inalist, whileassvuseseqv?andassocusesequal? -
assv -
assoc
make-vectorvectorvector-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) andEnd(exclusive) are optional
-
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>=? -
char-ci=? -
char-ci<? -
char-ci>? -
char-ci<=? -
char-ci>=?
-
nil?same alsnull?(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 aseqv?when applied to booleans, symbols, numbers, (WiP characters, ports,) procedures, and the empty list. If two objects areeqv?, they must beequal?as well. In all other cases,equal?may return either#tor#f. Even if its arguments are circular data structures,equal?must always terminate.
-
string? -
hash? -
number? -
integer? -
list? -
vector? -
pair? -
procedure? -
symbol? -
boolean? -
boolean=?accepts a list as argument -
vector? -
alist?
>>=<<==
-
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?
-
make-hashCreate a hash -
hash-getGet an element from a hash -
hash-insertInsert an element into a hash -
hash-removeRemove an element from a hash hash-keys
-
string -
make-string -
number->string -
(string->number string)(string->number "100") ; => 100 (string->number "1e2") ; => 100.0 -
(string->number string radix)(WiP) Returns a number of the maximally precise representation expressed by the given string. It is an error if radix is not 2, 8, 10, or 16.(string->number "100" 16) ; => 256 -
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>=?
-
+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
=zero?positive?negative?odd?even?
-
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-queryADBC execute SQL -
define-queryADBC prepare SQL