Calysto Scheme is a real Scheme programming language, with full support for continuations, including call/cc. It can also use all Python libraries. Also has some extensions that make it more useful (stepper-debugger, choose/fail, stack traces), or make it better integrated with Python.
In Jupyter notebooks, because Calysto Scheme uses MetaKernel, it has a fully-supported set of "magics"---meta-commands for additional functionality. This includes running Scheme in parallel. See all of the MetaKernel Magics.
Calysto Scheme is written in Scheme, and then translated into Python (and other backends). The entire functionality lies in a single Python file: https://github.com/Calysto/calysto_scheme/blob/master/calysto_scheme/scheme.py However, you can easily install it (see below).
You can install Calysto Scheme with Python3:
pip3 install --upgrade calysto-scheme --user -U
python3 -m calysto_kernel install --user
or in the system kernel folder with:
sudo pip3 install --upgrade calysto-scheme -U
sudo python3 -m calysto_kernel install
Change pip3/python3 to use a different pip or Python. The version of Python used will determine how Calysto Scheme is run.
Use it in the console, qtconsole, or notebook with IPython 3:
ipython console --kernel calysto_scheme
ipython qtconsole --kernel calysto_scheme
ipython notebook --kernel calysto_scheme
In addition to all of the following items, Calysto Scheme also has access to all of Python's builtin functions, and all of Python's libraries. For example, you can use (complex 3 2)
to create a complex number by calling Python's complex function.
When you run Calysto Scheme in Jupyter (console, notebook, qtconsole, etc.) you get:
Calysto Scheme allows you to use LaTeX-style variables in code. For example, if you type:
\beta
with the cursor right after the 'a' in beta, and then press TAB, it will turn into the unicode character:
β
There are nearly 1300 different symbols defined (thanks to the Julia language) and documented here:
http://docs.julialang.org/en/release-0.4/manual/unicode-input/#man-unicode-input
Calysto Scheme may not implement all of those. Some useful and suggestive ones:
(define α 67)
α
67
(define i 2)
(define vectorᵢ (vector-ref (vector 0 6 3 2) i))
vectorᵢ
3
(import "calysto.display")
(calysto)
(calysto.display.HTML "This is <b>bold</b>, <i>italics</i>, <u>underlined</u>.")
(import "calysto.graphics")
(calysto)
(define canvas (calysto.graphics.Canvas))
(define ball (calysto.graphics.Circle '(150 150) 100))
(ball.draw canvas)
! ls /tmp
config-err-7810dL emacs1000 unity_support_test.0 uploads /home/dblank/Desktop/ProgLangBook config-err-7810dL emacs1000 unity_support_test.0 uploads
Here is what the debugger looks like:
It has breakpoints (click in left margin). You must press Stop to exit the debugger.
%%debug
(begin
(define x 1)
(set! x 2)
)
You can import and use any Python library in Calysto Scheme.
In addition, if you wish, you can execute expressions and statements in a Python environment:
(python-eval "1 + 2")
3
(python-exec
"
def mypyfunc(a, b):
return a * b
")
This is a shared environment with Scheme:
(mypyfunc 4 5)
20
You can use func
to turn a Scheme procedure into a Python function, and define!
to put it into the shared enviornment with Python:
(define! mypyfunc2 (func (lambda (n) n)))
(python-eval "mypyfunc2(34)")
34
choose
Calysto Scheme acts as if it has a call stack, for easier debugging. For example:
(define fact
(lambda (n)
(if (= n 1)
q
(* n (fact (- n 1))))))
(fact 5)
Traceback (most recent call last): File "In [5]", line 1, col 1, in 'fact' File "In [4]", line 5, col 17, in 'fact' File "In [4]", line 5, col 17, in 'fact' File "In [4]", line 5, col 17, in 'fact' File "In [4]", line 5, col 17, in 'fact' File "In [4]", line 4, col 12 RunTimeError: unbound variable 'q'
To turn off the stack trace on error:
(use-stack-trace #f)
That will allow infinite recursive loops without keeping track of the "stack".
SCHEMEPATH
("." "/usr/local/lib/python3.4/dist-packages/calysto_scheme/modules")
(set-cdr! (cdr SCHEMEPATH) (list "/var/modules"))
SCHEMEPATH
("." "/usr/local/lib/python3.4/dist-packages/calysto_scheme/modules" "/var/modules")
The following are implemented as macros and are syntactic sugar on simpler forms:
(% arg0 arg1): modulo procedure for two arguments (aliases mod and modulo)
(% 5 2)
1
(* ...): multiplication procedure; multiplies all arguments
(* 2 3 4 5)
120
(+ ...): addition procedure; adds all arguments
(+ 1 1 1)
3
(- ...): subtraction procedure; subtracts all arguments
(- 5 4 2)
-1
(/ ...): division procedure; divides all arguments
(/ 3 2)
3/2
(// arg0 arg1): quotient procedure for rationals/ints; divides arg0 by arg1 (aliases div and quotient)
(// 3 2)
1
(< arg0 arg1): less-than procedure for two arguments
(< 6 7)
#t
(<= arg0 arg1): less-than or equal procedure for two arguments
(<= 5.5 5)
#f
(= arg0 arg1): numeric equality procedure for two arguments
(= 7 8)
#f
(> arg0 arg1): greater-than procedure for two arguments
(> 8 6)
#t
(>= arg0 arg1): greater-than or equal procedure for two arguments
(>= 9 9)
#t
(abort) : aborts processing and returns to top level
(abort)
(abs value): absolute value procedure
(abs -67)
67
(and #f (/ 6 0))
#f
(append ...): append lists together into a single list
(append '(1 2 3) '(4 5))
(1 2 3 4 5)
(apply PROCEDURE '(args...)): apply the PROCEDURE to the args
(apply + '(1 2 3))
6
(assv KEY ((ITEM VALUE) ...)): look for KEY in ITEMs; return matching (ITEM VALUE) or #f if not found. Uses eq? to look for key.
(assq 'key '((apple 1)(key 2)))
(key 2)
(assq 'key '((apple 1)(banana 2)))
#f
(assv KEY ((ITEM VALUE) ...)): look for KEY in ITEMs; return matching (ITEM VALUE) or #f if not found. Uses eqv? to look for key.
(assv 'key '((apple 1)(key 2)))
(key 2)
(atom? ITEM): return #t if ITEM is a atom, #f otherwise
(atom? (cons 1 2))
#f
(atom? 'a)
#t
(boolean? ITEM): return #t if ITEM is a boolean value
(boolean? #t)
#t
caaaar LIST): return the caaaar of the LIST
(caaaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(hello there)
(caaadr LIST): return the caaadr of the LIST
(caaadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
in
(caaar LIST): return the caaar of the LIST
(caaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((hello there) this is a test)
(caadar LIST): return the caadar of the LIST
(caadar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((1 2 3) 4 5 6)
(caaddr LIST): return the caaddr of the LIST
(caaddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
the
(caadr LIST): return the caadr of the LIST
(caadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(in)
(caar LIST): return the caar of the LIST
(caar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(((hello there) this is a test) what is this)
(cadaar LIST): return the cadaar of the LIST
(cadaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
what
(cadadr LIST): return the cadadr of the LIST
(cadadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in) another) (the) list))
another
(cadar LIST): return the cadar of the LIST
(cadar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(((1 2 3) 4 5 6) 7 8 9)
(caddar LIST): return the caddar of the LIST
(caddar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
another
(cadddr LIST): return the cadddr of the LIST
(cadddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
list
(caddr LIST): return the (car (cdr (cdr LIST)))
(caddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(the)
(cadr LIST): return the (car (cdr LIST))
(cadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((in))
(call-with-current-continuation PROCEDURE):
See call/cc for examples.
(call/cc PROCEDURE): call-with-current-continuation
(* 10 (call/cc (lambda (k) 4)))
40
(* 10 (call/cc (lambda (k) (+ 1 (k 4)))))
40
(* 10 (call/cc (lambda (k)
(+ 1 (call/cc
(lambda (j)
(+ 2 (j (k 5)))))))))
50
(* 10 (call/cc (lambda (k)
(+ 1 (call/cc
(lambda (j)
(+ 2 (k (j 5)))))))))
60
(car LIST) returns the first element of LIST
(car '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((((hello there) this is a test) what is this) (((1 2 3) 4 5 6) 7 8 9) another item)
(case ...)
(case 'thing1 (thing2 1) (thing1 2))
2
(case 'thing1 (thing2 1) ((thing1 thing3) 2))
2
(case 'thingx (thing2 1) ((thing1 thing3) 2) (else 3))
3
(case 'banana
(apple 'no)
((cherry banana) 1 2 3)
(else 'no))
3
(cd [PATH]): get the current directory, or set it if PATH is given (alias current-directory)
(cd "/")
"/"
(cdaaar LIST): return the cdaaar of the LIST
(cdaaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(this is a test)
(cdaadr LIST): return the cdaadr of the LIST
(cdaadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
()
(cdaar LIST): return the cdaar of the LIST
(cdaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(what is this)
(cdadar LIST): return the cdadar of the LIST
(cdadar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(7 8 9)
(cdaddr LIST): return the cdaddr of the LIST
(cdaddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
()
(cdadr LIST): return the cdadr of the LIST
(cdadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
()
(cdar LIST): return the cdar of the LIST
(cdar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((((1 2 3) 4 5 6) 7 8 9) another item)
(cddaar LIST): return the cddaar of the LIST
(cddaar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(is this)
(cddadr LIST): return the cddadr of the LIST
(cddadr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in) some other) (the) list))
(other)
(cddar LIST): return the cddar of the LIST
(cddar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(another item)
(cdddar LIST): return the cdddar of the LIST
(cdddar '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(item)
(cddddr LIST): return the cddddr of the LIST
(cddddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
()
(cdddr LIST): return the cddr of the LIST
(cdddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(list)
(cddr LIST): return the cddr of the LIST
(cddr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
((the) list)
(cdr LIST) returns rest of LIST after (car LIST)
(cdr '(((((hello there) this is a test) what is this)
(((1 2 3) 4 5 6) 7 8 9) another item) ((in)) (the) list))
(((in)) (the) list)
(char->integer CHAR): return associated number of CHAR
(char->integer #\1)
49
(char->string CHAR): return the character as a string
(char->string #\a)
"a"
(char-alphabetic? CHAR): return #t if CHAR is an alphabetic character, #f otherwise
(char-alphabetic? #\1)
#f
(char-alphabetic? #\a)
#t
(char-numeric? CHAR): return #t if CHAR is a whitespace character, #f otherwise
(char-numeric? #\2)
#t
(char-whitespace? CHAR): return #t if CHAR is a whitespace character, #f otherwise
(char-whitespace? #\tab)
#t
(char=? CHAR1 CHAR2): return #t if CHAR1 has the same values as CHAR2, #f otherwise
(char=? #\1 #\2)
#f
(char? ITEM): return #t if ITEM is a character, #f otherwise
(char? "h")
#f
This is the main interface to the non-deterministic interface. Using (choose options) combined with (require BOOLEAN-TEST) you can go back and select another option.
(choose OPTIONS): pick one, with ability to go back and pick another later
(define x (choose 1 2 3))
x
1
(require #f)
x
2
(require #f)
x
3
(require #f)
"no more choices"
x
3
You can solve many problems in a concise manner with choose/require. The following puzzle (taken from Dinesman 1968) is typical of a large class of simple logic puzzles:
Baker, Cooper, Fletcher, Miller, and Smith live on different floors of an apartment house that contains only five floors. Baker does not live on the top floor. Cooper does not live on the bottom floor. Fletcher does not live on either the top or the bottom floor. Miller lives on a higher floor than does Cooper. Smith does not live on a floor adjacent to Fletcher's. Fletcher does not live on a floor adjacent to Cooper's. Where does everyone live?
(define floors2
(lambda ()
(let ((baker (choose 1 2 3 4 5)))
(require (not (= baker 5)))
(let ((fletcher (choose 1 2 3 4 5)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(let ((cooper (choose 1 2 3 4 5)))
(require (not (= cooper 1)))
(require (not (= (abs (- fletcher cooper)) 1)))
(let ((smith (choose 1 2 3 4 5)))
(require (not (= (abs (- smith fletcher)) 1)))
(let ((miller (choose 1 2 3 4 5)))
(require (> miller cooper))
(require (distinct? (list baker cooper fletcher miller smith)))
(list
(list 'baker: baker)
(list 'cooper: cooper)
(list 'fletcher: fletcher)
(list 'miller: miller)
(list 'smith: smith)))))))))
(define distinct?
(lambda (nums)
(or (null? nums)
(null? (cdr nums))
(and (not (member (car nums) (cdr nums)))
(distinct? (cdr nums))))))
(floors2)
((baker: 3) (cooper: 2) (fletcher: 4) (miller: 5) (smith: 1))
(cond CONDITIONS): CONDITIONS are composed of (TEST RETURN). cond will return the first RETURN where TEST is #t. else
is considered to be #t.
(cond
(#f 1)
(else 2))
2
(cons ITEM1 ITEM2): return a list with ITEM1 as car and ITEM2 as cdr (ITEM2 is typically a list)
(cons 1 2)
(1 . 2)
(contains DICTIONARY ITEM): returns #t if DICTIONARY contains ITEM
(contains (dict '((a 1) (b 2))) 'b)
#t
(current-directory [PATH]): get the current directory, or set it if PATH is given (alias cd)
(current-directory)
"/"
(cd "/tmp")
"/tmp"
(current-environment): returns the current environment
(current-environment)
#<environment>
(current-time): returns the current time as number of seconds since 1970-1-1
(current-time)
1470252063.6648307
(cut ARGS...): return to toplevel with ARGS
(cut 1 2 3)
(1 2 3)
(letrec ((loop (lambda (n)
(if (= n 0)
(set! var (cut 23))
(loop (- n 1)))))
(var 0))
(loop 10)
var)
(23)
(define my-odd? 'undefined)
(define my-even? 'undefined)
(letrec
((odd (lambda (n) (if (= n 0) #f (even (- n 1)))))
(even (lambda (n) (if (= n 0) #t (odd (- n 1))))))
(set! my-odd? odd)
(set! my-even? even))
(my-odd? 42)
#f
(my-even? 42)
#t
(my-odd? 43)
#t
(my-even? 43)
#f
(define SYMBOL VALUE): bind a symbol to a value in the top-level-environment
(define (SYMBOL ARGS) VALUE): the MIT-define
(define x 1)
x
1
(define (f a b) (+ a b)) ;; MIT-style (hidden lambda)
(f 5 6)
11
(define f
(lambda (a b)
(+ a b)))
(f 5 6)
11
(begin
(define y 2)
(print y)
)
(print y)
2 2
(define! myvar 42)
myvar
42
(python-eval "myvar")
42
(define-datatype TYPE TYPE-TEST-NAME COMPONENTS): define a new datatype. Creates the constructors and tests for the datatype and components. For use with cases
. See below for example.
(define-datatype lc-exp lc-exp?
(var-exp
(var symbol?))
(lambda-exp
(bound-var symbol?)
(body lc-exp?))
(app-exp
(rator lc-exp?)
(rand lc-exp?)))
(var-exp 'a)
(var-exp a)
(lambda-exp 'a (var-exp 'a))
(lambda-exp a (var-exp a))
(app-exp (lambda-exp 'a (var-exp 'a)) (var-exp 'a))
(app-exp (lambda-exp a (var-exp a)) (var-exp a))
(define un-parse
(lambda (exp)
(cases lc-exp exp
(var-exp (var) var)
(lambda-exp (bound-var body) (list bound-var body))
(app-exp (rator rand) (list rator rand)))))
(un-parse (var-exp 'a))
a
(un-parse (lambda-exp 'a (var-exp 'a)))
(a (var-exp a))
(un-parse (app-exp (lambda-exp 'a (var-exp 'a)) (var-exp 'a)))
((lambda-exp a (var-exp a)) (var-exp a))
(define-syntax NAME RULES): a method for creating macros
(define-syntax time
[(time ?exp) (let ((start (current-time)))
?exp
(- (current-time) start))])
(time (car '(1 2 3 4)))
0.0002892017364501953
;;---------------------------------------------------------------------
;; collect is like list comprehension in Python
(define-syntax collect
[(collect ?exp for ?var in ?list)
(filter-map (lambda (?var) ?exp) (lambda (?var) #t) ?list)]
[(collect ?exp for ?var in ?list if ?condition)
(filter-map (lambda (?var) ?exp) (lambda (?var) ?condition) ?list)])
(define filter-map
(lambda (f pred? values)
(if (null? values)
'()
(if (pred? (car values))
(cons (f (car values)) (filter-map f pred? (cdr values)))
(filter-map f pred? (cdr values))))))
(collect (* n n) for n in (range 10))
(0 1 4 9 16 25 36 49 64 81)
(collect (* n n) for n in (range 5 20 3))
(25 64 121 196 289)
(collect (* n n) for n in (range 10) if (> n 5))
(36 49 64 81)
;;---------------------------------------------------------------------
;; for loops
(define-syntax for
[(for ?exp times do . ?bodies)
(for-repeat ?exp (lambda () . ?bodies))]
[(for ?var in ?exp do . ?bodies)
(for-iterate1 ?exp (lambda (?var) . ?bodies))]
[(for ?var at (?i) in ?exp do . ?bodies)
(for-iterate2 0 ?exp (lambda (?var ?i) . ?bodies))]
[(for ?var at (?i ?j . ?rest) in ?exp do . ?bodies)
(for ?var at (?i) in ?exp do
(for ?var at (?j . ?rest) in ?var do . ?bodies))])
(define for-repeat
(lambda (n f)
(if (< n 1)
'done
(begin
(f)
(for-repeat (- n 1) f)))))
(define for-iterate1
(lambda (values f)
(if (null? values)
'done
(begin
(f (car values))
(for-iterate1 (cdr values) f)))))
(define for-iterate2
(lambda (i values f)
(if (null? values)
'done
(begin
(f (car values) i)
(for-iterate2 (+ i 1) (cdr values) f)))))
(define matrix2d
'((10 20)
(30 40)
(50 60)
(70 80)))
(define matrix3d
'(((10 20 30) (40 50 60))
((70 80 90) (100 110 120))
((130 140 150) (160 170 180))
((190 200 210) (220 230 240))))
(begin
(define hello 0)
(for 5 times do (set! hello (+ hello 1)))
hello
)
5
(for sym in '(a b c d) do (define x 1) (set! x sym) x)
done
(for n in (range 10 20 2) do n)
done
(for n at (i j) in matrix2d do (list n 'coords: i j))
done
(for n at (i j k) in matrix3d do (list n 'coords: i j k))
done
(define-syntax scons
[(scons ?x ?y) (cons ?x (lambda () ?y))])
(define scar car)
(define scdr
(lambda (s)
(let ((result ((cdr s))))
(set-cdr! s (lambda () result))
result)))
(define first
(lambda (n s)
(if (= n 0)
'()
(cons (scar s) (first (- n 1) (scdr s))))))
(define nth
(lambda (n s)
(if (= n 0)
(scar s)
(nth (- n 1) (scdr s)))))
(define smap
(lambda (f s)
(scons (f (scar s)) (smap f (scdr s)))))
(define ones (scons 1 ones))
(define nats (scons 0 (combine nats + ones)))
(define combine
(lambda (s1 op s2)
(scons (op (scar s1) (scar s2)) (combine (scdr s1) op (scdr s2)))))
(define fibs (scons 1 (scons 1 (combine fibs + (scdr fibs)))))
(define facts (scons 1 (combine facts * (scdr nats))))
(define ! (lambda (n) (nth n facts)))
(! 5)
120
(nth 10 facts)
3628800
(nth 20 fibs)
10946
(first 30 fibs)
(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040)
(dict '((KEY VALUE)...)): creates a Python dictionary (dict '((KEY : VALUE)...)): optional syntax
(dict '((a 1)(b 2)))
{a: 1, b: 2}
(dict '((a : 1)(b : 2)))
{a: 1, b: 2}
(dir [ITEM]): return items in environment, or, if ITEM is given, the items in module
(dir)
(! % * + - / // < <= = > >= SCHEMEPATH abort abs and app-exp append apply assq assv atom? boolean? caaaar caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr call-with-current-continuation call/cc car case cases cd cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr char->integer char->string char-alphabetic? char-numeric? char-whitespace? char=? char? collect combine cond cons contains current-directory current-environment current-time cut define-datatype dict dir display distinct? div eq? equal? eqv? error eval eval-ast even? exit fact facts fibs filter-map first float floors2 for for-each for-iterate1 for-iterate2 for-repeat format get get-stack-trace getitem globals hello import import-as import-from int integer->char iter? lambda-exp lc-exp? length let let* letrec list list->string list->vector list-ref list? load load-as make-set make-vector map matrix2d matrix3d max member memq memv min mod modulo my-even? my-odd? nats newline not nth null? number->string number? odd? ones or pair? parse parse-string print printf procedure? property python-eval python-exec quotient rac range rational rdc read-string record-case remainder require reset-toplevel-env reverse round scar scdr scons set-car! set-cdr! setitem smap snoc sort sqrt string string->list string->number string->symbol string-append string-length string-ref string-split string<? string=? string? substring symbol symbol->string symbol? time typeof un-parse unparse unparse-procedure use-lexical-address use-stack-trace use-tracing var-exp vector vector->list vector-length vector-ref vector-set! vector? void x y zero?)
(dir complex)
(__abs__ __add__ __bool__ __class__ __delattr__ __dir__ __divmod__ __doc__ __eq__ __float__ __floordiv__ __format__ __ge__ __getattribute__ __getnewargs__ __gt__ __hash__ __init__ __int__ __le__ __lt__ __mod__ __mul__ __ne__ __neg__ __new__ __pos__ __pow__ __radd__ __rdivmod__ __reduce__ __reduce_ex__ __repr__ __rfloordiv__ __rmod__ __rmul__ __rpow__ __rsub__ __rtruediv__ __setattr__ __sizeof__ __str__ __sub__ __subclasshook__ __truediv__ conjugate imag real)
(display ITEM): display the ITEM as output
(display "hello")
hello
(div arg0 arg1): quotient procedure for rationals/ints; divides arg0 by arg1 (aliases // and quotient)
(div 5 3)
1
(eq? ITEM1 ITEM2): return #t if ITEM1 is eq to ITEM2, #f otherwise
(eq? '(1 2) '(1 2))
#f
(equal? ITEM1 ITEM2): return #t if ITEM1 is equal to ITEM2, #f otherwise
(equal? '(1 2) '(1 2))
#t
(eqv? ITEM1 ITEM2): return #t if ITEM1 and ITEM2 have the same value
(eqv? '(1 2) '(1 2))
#f
(error NAME FORMATTED-MESSAGE ARGS...): create an exception in NAME with MESSAGE
(error "procedure-name" "What is ~a" 'huh?)
Traceback (most recent call last): File "In [130]", line 1, col 1, in 'error' File "In [130]", line 1, col 1 RunTimeError: Error in 'procedure-name': What is huh?
(eval LIST): evaluates the LIST as a Scheme expression
(eval '(+ 1 1))
2
(eval-ast AST): evaluates the Abstract Syntax Tree as a Scheme expression (see parse and parse-string)
(eval-ast (parse-string "(+ 1 2)"))
3
(even? NUMBER): returns #t if NUMBER is odd, #f otherwise
(even? 12121)
#f
(exit):
(exit)
(exiting the interpreter)
(float NUMBER): return NUMBER as a floating point value
(float 34)
34.0
(for-each PROCEDURE LIST): apply PROCEDURE to each item in LIST; like map
but don't return results
(for-each (lambda (n) (print n)) '(3 4 5))
3 4 5
(format STRING ITEM ...): format the string with ITEMS as arguments
(format "This uses formatting ~a ~s ~%" 'apple 'apple)
"This uses formatting apple apple \n"
(func (lambda (n) n))
<function dlr_func.<locals>.f at 0x7f7733b9c6a8>
(load-as "test_all.ss" 'test)
Scheme Unit tests ................................................................................................................................................................................................................................................ Results: right = 240 wrong = 0 Time: 4.101226091384888 seconds
((get 'test 'verify) "test-name" 1 = 1)
.
((get 'test '!) 5)
120
(get-stack-trace): return the current stack trace
(get-stack-trace)
((app-aexp (lexical-address-aexp 0 74 get-stack-trace ("In [141]" 1 2 2 1 16 16)) () ("In [141]" 1 1 1 1 17 17)))
(getitem DICTIONARY ITEM): returns the VALUE of DICTIONARY[ITEM]
(getitem vector ITEM): returns the VALUE of VECTOR[ITEM]
(getitem OBJECT "ATTRIBUTE"): return the Python ATTRIBUTE of an OBJECT
(getitem #(1 2 3) 0)
1
(getitem (dict '((a 100))) 'a)
100
(getitem (globals) "keys")
<built-in method keys of dict object at 0x7f0338b1e648>
(globals): get global Python environment
(define-syntax collect
[(collect ?exp for ?var in ?list)
(filter-map (lambda (?var) ?exp) (lambda (?var) #t) ?list)]
[(collect ?exp for ?var in ?list if ?condition)
(filter-map (lambda (?var) ?exp) (lambda (?var) ?condition) ?list)])
(define filter-map
(lambda (f pred? values)
(if (null? values)
'()
(if (pred? (car values))
(cons (f (car values)) (filter-map f pred? (cdr values)))
(filter-map f pred? (cdr values))))))
(collect x for x in (map (lambda (n) n) ((getitem (globals) "keys"))) if (string<? x "b"))
("apply_proc" "apply_prim" "GLOBALS" "assignment_q_hat" "apply_macro" "_staruse_stack_trace_star" "LessThan" "ap_reg" "assq_prim" "append_all" "ap1_reg" "association_q" "association_q_hat" "adatum_reg" "apply_action" "amacro_error" "append_prim" "action_reg" "__doc__" "abs_prim" "apair_q" "atom_tag" "_starreader_generates_annotated_sexps_q_star" "append" "_starneed_newline_star" "Symbol" "apply_cont2" "assv_prim" "application_q_hat" "aparse_sexps" "__spec__" "__version__" "REP_fail" "apply_fail" "Apply" "apply_star" "Range" "apply_cont" "abort_prim" "anything_q" "GreaterThanEqual" "DebugException" "__loader__" "GreaterThan" "Char" "apply_cont3" "__name__" "aparse" "PY3" "CHARS" "atom_q_prim" "__builtins__" "SYMBOLS" "apply_handler" "app_aexp" "SCHEMEPATH" "args_reg" "append2" "apply_sub_hat" "add_binding" "Vector" "apply_comparison" "annotated_q" "all_numeric_q" "avar_reg" "aclauses_reg" "_starlast_fail_star" "_startracing_on_q_star" "Map" "association_aexp" "_startokens_left_star" "assv" "_trace_pause" "apply_state" "_staruse_lexical_address_star" "annotate_cps" "__file__" "assq" "aparse_error" "atom_q" "ax_reg" "ENVIRONMENT" "assign_aexp" "Iterable" "apair2_reg" "REP_handler" "apply_cont4" "adatum_list_reg" "__package__" "aatom_q" "association" "REP_k" "_closure_depth" "and_transformer_hat" "List" "apair1_reg" "__cached__" "apply_handler2" "apattern_q" "ap2_reg" "aparse_all" "at_hat" "aunparse" "atom_q_hat" "all_char_q" "LessThanEqual" "_starstack_trace_star")
Use import, import-from, and import-as to load Python libraries. Use load and load-as to load Scheme files.
(import MODULE...): import host-system modules; MODULEs are strings
(try
(import "math")
(catch e e
(import "Graphics")))
(math)
(math.cos 0.6)
0.8253356149096783
Use import, import-from, and import-as to load Python libraries. Use load and load-as to load Scheme files.
(import-as MODULE NAME): import a host-system module; MODULE is a string, and NAME is a symbol or string. Use * for NAME to import into toplevel environment
(import-as "math" 'm)
(m)
(m.sin 0.6)
0.5646424733950354
Use import, import-from, and import-as to load Python libraries. Use load and load-as to load Scheme files.
(import-from MODULE NAME...): import from host-system module; MODULE is a string, and NAME is a symbol or string
(import-from "math" "sin" "cos")
(sin cos)
(sin .5)
0.479425538604203
(int NUMBER): return NUMBER as an integer
(int 4.5)
4
(integer->char INTEGER): return the assocated character of INTEGER
(integer->char 78)
#\N
(iter? ITEM): return #t if ITEM is a iterator, #f otherwise
(iter? 3)
#f
(define g (globals))
(iter? (g.keys))
#t
(lambda (VARIABLE...) BODY)
(lambda VARIABLE BODY) - called mu-lambda
(lambda (n) n) ;; identity function
#<procedure>
((lambda (i) i) 89)
89
((lambda x x) 1 2 3 4 5)
(1 2 3 4 5)
((lambda (x . y) (list x y)) 1 2 3 4 5)
(1 (2 3 4 5))
((lambda (a b . z) (list a b z)) 1 2 3 4 5)
(1 2 (3 4 5))
((lambda (a b . z) (list a b z)) 1 2 3)
(1 2 (3))
((lambda (a b . z) (list a b z)) 1 2)
(1 2 ())
(try ((lambda (a b . z) (list a b z)) 1)
(catch e e "not enough arguments given"))
"not enough arguments given"
(length LIST): returns the number of elements in top level of LIST
(length '(1 2 3 4))
4
(let ((VARIABLE VALUE)...) BODY): define variables with a scope in BODY
(let ((v (vector 1 2 3)))
(vector-set! v 2 'a)
v)
#3(1 2 a)
(try (let loop ((n 5))
n
(if (= n 0)
(raise 'blastoff!))
(loop (- n 1)))
(catch e e))
blastoff!
(let* ...)
(let* ((a 1) (b a))
b)
1
(letrec ...)
(letrec
((fact (lambda (n)
(if (= n 1)
1
(* (fact (- n 1)) n)))))
(fact 5))
120
(list ITEM ...): returns a list composed of all of the items
(list 1 2 3 4)
(1 2 3 4)
(list->string LIST): returns the LIST as a string
(list->string '(#\1 #\2))
"12"
(list->vector LIST): returns the LIST as a vector
(list->vector '(1 2 3))
#3(1 2 3)
(list-ref LIST INDEX): returns the item in LIST at INDEX (zero-based)
(list-ref '(1 2 3) 0)
1
(list? ITEM): return #t if ITEM is a list, #f otherwise
(list? 123)
#f
(load FILENAME...): loads the given FILENAMEs
(load "sllgen.ss")
sllgen.ss 2000-09-25 11:48
(load-as FILENAME MODULE-NAME): load the filename, putting items in MODULE-NAME namespace
(load-as "sllgen.ss" 'sll)
sllgen.ss 2000-09-25 11:48
sll
#<environment>
(make-set LIST): returns a list of unique items from LIST
(make-set '(1 2 3 1 2 3))
(1 2 3)
(make-vector LENGTH): returns a vector of length LENGTH
(make-vector 8)
#8(0 0 0 0 0 0 0 0)
(map PROCEDURE LIST...): apply PROCEDURE to each element of LIST; like for-each but returns results.
map
and for-each
can iterate over lists and Python iterators.
(map (lambda (n) (+ n 2)) '(3 4 5))
(5 6 7)
(map (lambda (n) (print n)) '(3 4 5))
3 4 5
(<void> <void> <void>)
(max ...): returns the maximum value from the list of values
(max (range 10))
9
(member ITEM LIST): return LIST if ITEM in top level of LIST
(member 10 (range 10))
#f
(member 0 (range 10))
(0 1 2 3 4 5 6 7 8 9)
(member "b" '("a" "b" "c"))
("b" "c")
(memq ITEM LIST): check for member using eq? in LIST. Returns entire list if found.
(memq 'b '(a b c))
(b c)
(memq 2 '(1.0 2.0 3.0))
#f
(memv ITEM LIST): check for member using eqv? in LIST. Returns entire list if found.
(memv 2 '(1.0 2.0 3.0))
(2.0 3.0)
(min ...): returns the minimum value from the list of values
(min (range 10))
0
(mod arg0 arg1): modulo procedure for two arguments (aliases % and modulo)
(mod 7 3)
1
(modulo arg0 arg1): modulo procedure for two arguments (aliases mod and %)
(modulo 7 3)
1
(newline): displays a new line in output
(newline)
(not ITEM): returns the boolean not of ITEM; ITEM is only #t when #t, otherwise #f
(not #f)
#t
(not #t)
#f
(null? ITEM): return #t if ITEM is empty list, #f otherwise
(null? '())
#t
(null? '(1))
#f
(number->string NUMBER): return NUMBER as a string
(number->string 76.23)
"76.23"
(number? ITEM): return #t if ITEM is a number, #f otherwise
(number? 7623.3)
#t
(odd? NUMBER): returns #t if NUMBER is even, #f otherwise
(odd? 65)
#t
(or #t (/ 8 0))
#t
(pair? ITEM): returns #t if ITEM is a cons cell (a proper or improper list). Note that the empty list is a symbol, but not an actual list.
(pair? '())
#f
(pair? (cons 1 2))
#t
(parse LIST): parse a list; returns Abstract Syntax Tree (AST)
(parse '(+ 2 3))
(app-aexp (lexical-address-aexp 0 1 + none) ((lit-aexp 2 none) (lit-aexp 3 none)) none)
(parse-string STRING): parse a string; returns Abstract Syntax Tree (AST)
(parse-string "(+ 1 2)")
(app-aexp (lexical-address-aexp 0 1 + (stdin 1 2 2 1 2 2)) ((lit-aexp 1 (stdin 1 4 4 1 4 4)) (lit-aexp 2 (stdin 1 6 6 1 6 6))) (stdin 1 1 1 1 7 7))
(print ITEM): output the ITEM as if by write (alias for write)
(print "this string")
"this string"
(printf FORMAT ARGS...): formatted print. Uses standard scheme formatting symbols:
(printf "many possible ~a ~s" 'things "and etc")
many possible things "and etc"
(procedure? ITEM): return #t if ITEM is a procedure, #f otherwise
(procedure? procedure?)
#t
Create a Python property. Under development for creating Python classes from Scheme.
(property NAME VALUE):
(python-eval PYTHON-EXPRESSION [globals [locals]]): return the result of evaluating PYTHON-EXPRESSION string
(python-eval "1 + 4")
5
(python-exec PYTHON-STATEMENTS [globals [locals]]): return the result of evaluating PYTHON-STATEMENTS string
(python-exec
"
x = 1
print(x)
")
1
(quasiquote LIST): quasiquote allows commas in front of expressions in a list which will be evaluated
`(list ,(+ 1 2) 4)
(list 3 4)
(quote ITEM): treat ITEM as a literal (data). Can also be written as the single-quote mark
(quote (1 2 3))
(1 2 3)
'(1 2 3)
(1 2 3)
'#(1 2 3)
#3(1 2 3)
`#(1 ,(+ 2 4))
#2(1 6)
(quotient arg0 arg1): quotient procedure for rationals/ints; divides arg0 by arg1 (aliases // and div)
(quotient 7 3)
2
(rac LIST): return the last item of LIST
(rac '(1 2 3))
3
(range END), (range START END), or (RANGE START END STEP): (all integers)
(range 10)
(0 1 2 3 4 5 6 7 8 9)
(rational NUMERATOR DENOMINTAOR): return a rational number
(rational 3 4)
3/4
(rdc LIST): return everything but last item in LIST
(rdc '(1 2 3))
(1 2)
See try/catch/finally for examples.
(read-string LIST): returns low-level format used in read. Not generally useful.
(read-string '(1 2 3))
((pair) ((atom) 1 (stdin 1 2 2 1 2 2)) ((pair) ((atom) 2 (stdin 1 4 4 1 4 4)) ((pair) ((atom) 3 (stdin 1 6 6 1 6 6)) ((atom) () none) none) none) (stdin 1 1 1 1 7 7))
(record-case RECORD CASES): match a record to a sequence of CASES
(record-case (cons 'banana (cons 'orange (cons (* 2 3) '())))
(apple (a b c) (list c b a r))
((cherry banana) (a . b) (list b a 5))
((orange) () 'no)
(else 2 3 4))
((6) orange 5)
(remainder NUMBER1 NUMBER2): returns the remainder after dividing NUMBER1 by NUMBER2
(remainder 6 3)
0
(reset-toplevel-env): reset the toplevel environment
(reset-toplevel-env)
(reverse LIST): return the top-level items in a list in reverse order.
(reverse '(1 2 3))
(3 2 1)
(round NUMBER): round NUMBER to the nearest integer (may return float)
(round 34.7)
35
(set! VARIABLE VALUE): set a variable to a value
Note that for objects, you currently need to:
(setitem OBJ "PROPERTY" VALUE)
(define x 12)
(set! x 13)
(set-car! LIST ITEM): set the car of LIST to be ITEM
(define a '(1 2 3))
(set-car! a 7)
a
(7 2 3)
(set-cdr! LIST ITEM): set the car of LIST to be ITEM (which is typically a list)
(define a '(1 2 3))
(set-cdr! a '(4 5))
a
(1 4 5)
(setitem DICTIONARY ITEM VALUE): sets DICTIONARY[ITEM] with VALUE and returns it
(setitem VECTOR POSITION VALUE): sets VECTOR[POSITION] with VALUE and returns it
(setitem OBJ "PROPERTY" VALUE): sets OBJ.PROPERY with VALUE, and returns it
(import "conx")
(conx)
(setitem conx "x" 42)
42
(getitem conx "x")
42
conx.x
42
(define d (dict '((a 1)(b 2))))
(setitem d 'b 6)
d
{a: 1, b: 6}
(snoc ITEM LIST): cons the ITEM onto the end of LIST
(snoc '0 '(1 2 3))
(1 2 3 0)
(sort PROCEDURE LIST): sort the list using PROCEDURE to compare items
(sort (lambda (a b) (< a b)) '(9 6 2 3 1 2 0))
(0 1 2 2 3 6 9)
(sort < '(9 6 2 3 1 2 0))
(0 1 2 2 3 6 9)
(sqrt NUMBER): return the square root of NUMBER
(sqrt 9)
3.0
(string ITEM): returns ITEM as a string
(string #\tab)
"\t"
(string->list STRING): string STRING as a list of characters
(string->list "hello world!")
(#\h #\e #\l #\l #\o #\space #\w #\o #\r #\l #\d #\!)
(string->number STRING): return STRING as a number
(string->number "23.3")
23.3
(string->symbol STRING): return STRING as a symbol
(string->symbol "apple")
apple
(string-append STRING1 STRING2): append two strings together
(string-append "abc" "123")
"abc123"
(string-length STRING): returns the length of a string
(string-length "how long?")
9
(string-ref STRING INDEX): return the character of STRING at position INDEX
(string-ref "0123" 1)
#\1
(string-split STRING CHAR): return a list with substrings of STRING where split by CHAR
(string-split "1234" #\2)
("1" "34")
(string<? STRING1 STRING2): compare two strings to see if STRING1 is less than STRING2
(string<? "apple" "zebra")
#t
(string=? STRING1 STRING2): return #t if STRING1 is the same as STRING2, #f otherwise
(string=? "apple" "apple")
#t
(string? ITEM): return #t if ITEM is a string, #f otherwise
(string? 'apple)
#f
(substring STRING START [END]): return the substring of STRING starting with position START and ending before END. If END is not provided, it defaults to the length of the STRING
(substring "01234" 1 3)
"12"
(symbol STRING): turn STRING into a symbol
(symbol "apple")
apple
(symbol->string SYMBOL): return SYMBOL as a string
(symbol->string 'apple)
"apple"
(symbol? ITEM): return #t if ITEM is a symbol, #f otherwise
(symbol? "apple")
#f
(try ... catch ...): attempt to execute an expression, with a method of catching errors, and running code at end regardless of outcome. Note that the finally clause runs, but the return value comes from try or catch. See below for examples.
(try
(/ 1 0)
(catch e e
(printf "Can't do that!")))
Can't do that!
(try 3)
3
(try 3
(finally (define did-it #t)))
3
did-it
#t
(try (/ 3 0)
(catch e e)
(finally (print 'yes 4)))
yes 4
("RunTimeError" "division by zero" "In [32]" 1 6 (("In [32]" 1 6 /)))
(try (raise 'yes)
(catch e e))
yes
(try (try (raise 'yes))
(catch e e))
yes
(try (try (begin 'one (raise 'oops) 'two))
(catch e e))
oops
(* 10 (try (begin 'one (raise 'oops) 'two)
(catch ex 3 4)))
40
(* 10 (try (begin 'one 'two 5)
(catch ex 3 4)))
50
(* 10 (try (begin 'one (raise 'oops) 5)
(catch ex (list 'ex: ex) 4)))
40
(try (* 10 (try (begin 'one (raise 'oops) 5)
(catch ex (list 'ex: ex) (raise ex) 4)))
(catch e e))
oops
(try (* 10 (try (begin 'one (raise 'oops) 5)
(catch ex (list 'ex: ex) (raise ex) 4)
(finally (print 'two 7))))
(catch e e))
two 7
oops
(try (* 10 (try (begin 'one (raise 'oops) 5)
(catch ex (list 'ex: ex) (raise 'bar) 4)))
(catch x 'hello 77))
77
(try 3
(finally (print 'hi 4)))
hi 4
3
(try (div 10 0)
(catch e (cadr e)))
"division by zero"
(try (let ((x
(try (div 10 0)))) x)
(catch e (cadr e)))
"division by zero"
(let ((x (try (div 10 2)
(catch e -1)))) x)
5
(let ((x
(try (div 10 0)
(catch e -1)))) x)
-1
(let ((x (try (div 10 2)
(catch e -1)
(finally (print 'closing-files 42))))) x)
closing-files 42
5
(let ((x (try (div 10 0)
(catch e -1)
(finally (print 'closing-files 42))))) x)
closing-files 42
-1
(let ((x (try (div 10 2)
(finally (print 'closing-files 42))))) x)
closing-files 42
5
(try (let ((x (try (div 10 0)
(catch e -1 (raise 'foo))
(finally (print 'closing-files 42))))) x) (catch e e))
closing-files 42
foo
(try (let ((x (try (div 10 0)
(catch e -1 (raise 'foo))
(finally (print 'closing-files (raise 'ack) 42)))))
x) (catch e e))
ack
(try (let ((x (try (div 10 0)
(catch e -1 (raise 'foo))
(finally (print 'closing-files (raise 'ack) 42)))))
x)
(catch e (if (equal? e 'ack) 99 (raise 'doug)))
(finally (print 'closing-outer-files)))
closing-outer-files
99
(try (try (let ((x (try (div 10 0)
(catch e -1 (raise 'foo))
(finally 'closing-files (raise 'ack) 42))))
x)
(catch e (if (equal? e 'foo) 99 (raise 'doug)))
(finally (print 'closing-outer-files))) (catch e e))
closing-outer-files
doug
(typeof ITEM): returns type of ITEM
(typeof 23.4)
<class 'float'>
(unparse AST): given an AST, turn it back into Scheme code
(unparse (parse '(+ 1 2)))
(+ 1 2)
(unparse-procedure PROCEDURE): given a procedure, show the body as Scheme code
(unparse-procedure (lambda (x) (+ x 1)))
(+ x 1)
(use-lexical-address [BOOLEAN]): get lexical-address setting, or set it on/off if BOOLEAN is given
(use-lexical-address #t)
(use-stack-trace BOOLEAN): set stack-trace usage on/off
(use-stack-trace #t)
(use-tracing [BOOLEAN]): get tracing setting, or set it on/off if BOOLEAN is given
(use-tracing)
#f
(use-tracing #t)
(define fact
(lambda (n)
(if (= n 1)
1
(* n (fact (- n 1))))))
(fact 1)
(use-tracing #f)
call: (define fact (lambda (n) (if (= n 1) 1 (* n (fact (- n 1)))))) call: (lambda (n) (if (= n 1) 1 (* n (fact (- n 1))))) (lambda (n) (if (= n 1) 1 (* n (fact (- n 1))))) => #<procedure> (define fact (lambda (n) (if (= n 1) 1 (* n (fact (- n 1)))))) => <void> call: (fact 1) call: 1 1 => 1 call: fact fact => #<procedure> call: (if (= n 1) 1 (* n (fact (- n 1)))) call: (= n 1) call: n n => 1 call: 1 1 => 1 call: = = => #<procedure> (= n 1) => #t call: 1 1 => 1 (if (= n 1) 1 (* n (fact (- n 1)))) => 1 (fact 1) => 1 call: (use-tracing #f) call: #f #f => #f call: use-tracing use-tracing => #<procedure> (use-tracing #f) => <void>
(vector [ITEMS]...): return ITEMs as a vector
(vector 1 2 (+ 3 3))
#3(1 2 6)
(vector->list VECTOR): return VECTOR as a list
(vector->list #(1 2 3))
(1 2 3)
(vector-length VECTOR): returns length of VECTOR
(vector-length #(1 2 3))
3
(vector-ref VECTOR INDEX):
(vector-ref #(1 2 3) 2)
3
(vector-set! VECTOR INDEX VALUE): sets the item at INDEX of VECTOR
(let ((v #(1 2 3)))
(vector-set! v 1 4)
v)
#3(1 4 3)
(vector? ITEM): return #t if ITEM is a vector, #f otherwise
(vector? '(1 2 3))
#f
(void): The null value symbol
(void)
(zero? NUMBER): return #t if NUMBER is equal to zero, #f otherwise
(zero? 0.0)
#t
((lambda ((n : 1)) n))
1
((lambda ((n : 2)) n))
2
((lambda ((n : 1)) n) 3)
3
((lambda (a b c) (list a b c)) 1 2 3)
(1 2 3)
((lambda (a b c) (list a b c)) 1 2 (c : 3))
(1 2 3)
((lambda (a b c) (list a b c)) 1 (b : 2) (c : 3))
(1 2 3)
((lambda (a b c) (list a b c)) (a : 1) (b : 2) (c : 3))
(1 2 3)
((lambda (a b c) (list a b c)) 1 (c : 3) (b : 2))
(1 2 3)
((lambda ((n : 1)) n) (n : 3))
3
The following items are currently missing from Calysto Scheme. However, much of their functionality can be achieved by using Python versions. For example you can use the Python bin
function to create a binary representation, since the Scheme binary
predicate has not been defined.