Difference between revisions of "Calico Scheme"

From IPRE Wiki
Jump to: navigation, search
(Example Code)
Line 2: Line 2:
  
 
Calico Scheme is a new implementation of a Scheme-based language for Calico. It implements many core Scheme functions, but also adds some functionality to bring it into line with the other modern languages like Python and Ruby.  
 
Calico Scheme is a new implementation of a Scheme-based language for Calico. It implements many core Scheme functions, but also adds some functionality to bring it into line with the other modern languages like Python and Ruby.  
 +
 +
= Commands =
 +
 +
=== quasiquote ===
 +
 +
(quasiquote ...)
 +
 +
Example:
 +
 +
<pre>
 +
(quasiquote (list (unquote (+ 1 2)) 4)) => (list 3 4)
 +
</pre>
 +
 +
=== % ===
 +
 +
(% ...)
 +
 +
Example:
 +
 +
<pre>
 +
(% 10 3) => 1
 +
</pre>
 +
 +
=== * ===
 +
 +
(* ...)
 +
 +
Example:
 +
 +
<pre>
 +
(* 2 3) => 6
 +
</pre>
 +
 +
=== + ===
 +
 +
(+ ...)
 +
 +
Example:
 +
 +
<pre>
 +
(+ 7 8) => 15
 +
</pre>
 +
 +
=== - ===
 +
 +
(- ...)
 +
 +
Example:
 +
 +
<pre>
 +
(- 5 2) => 3
 +
</pre>
 +
 +
=== / ===
 +
 +
(/ ...)
 +
 +
Example:
 +
 +
<pre>
 +
(/ 3 4) => 3/4
 +
</pre>
 +
 +
=== < ===
 +
 +
(< ...)
 +
 +
Example:
 +
 +
<pre>
 +
(< 5 2) => #f
 +
</pre>
 +
 +
=== <= ===
 +
 +
(<= ...)
 +
 +
Example:
 +
 +
<pre>
 +
(<= 5 6) => #t
 +
</pre>
 +
 +
=== = ===
 +
 +
(= ...)
 +
 +
Example:
 +
 +
<pre>
 +
(= 6 7) => #f
 +
</pre>
 +
 +
=== > ===
 +
 +
(> ...)
 +
 +
Example:
 +
 +
<pre>
 +
(> 9 2) => #t
 +
</pre>
 +
 +
=== >= ===
 +
 +
(>= ...)
 +
 +
Example:
 +
 +
<pre>
 +
(>= 4 5) => #f
 +
</pre>
 +
 +
=== abs ===
 +
 +
(abs ...)
 +
 +
Example:
 +
 +
<pre>
 +
(abs -1) => 1
 +
</pre>
 +
 +
=== and ===
 +
 +
(and ...)
 +
 +
Example:
 +
 +
<pre>
 +
(and 4 1 2 #t (quote ()) 0) => 0
 +
</pre>
 +
 +
=== append ===
 +
 +
(append ...)
 +
 +
Example:
 +
 +
<pre>
 +
(append (quote (1 2 3)) (quote (4 5 6))) => (1 2 3 4 5 6)
 +
</pre>
 +
 +
=== apply ===
 +
 +
(apply ...)
 +
 +
Example:
 +
 +
<pre>
 +
(apply car (quote ((1)))) => 1
 +
</pre>
 +
 +
=== assq ===
 +
 +
(assq ...)
 +
 +
Example:
 +
 +
<pre>
 +
(assq 1 (quote ((1 2) (3 4)))) => (1 2)
 +
</pre>
 +
 +
=== assv ===
 +
 +
(assv ...)
 +
 +
Example:
 +
 +
<pre>
 +
(assv 1 (quote ((1 2) (3 4)))) => (1 2)
 +
</pre>
 +
 +
=== atom? ===
 +
 +
(atom? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(atom? 1) => #t
 +
</pre>
 +
 +
=== boolean? ===
 +
 +
(boolean? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(boolean? #t) => #t
 +
</pre>
 +
 +
=== caaaar ===
 +
 +
(caaaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caaaar (quote (((((hello there) this is a test) what is this) another item) in the list))) => (hello there)
 +
</pre>
 +
 +
=== caaadr ===
 +
 +
(caaadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caaadr (quote (((((hello there) this is a test) what is this) another item) ((((((1 2 3) 4 5 6) 7 8 9) 10 11 12) 13 14 15) 16 17 18)))) => ((((1 2 3) 4 5 6) 7 8 9) 10 11 12)
 +
</pre>
 +
 +
=== caaar ===
 +
 +
(caaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caaar (quote (((((hello there) this is a test) what is this) another item) in the list))) => ((hello there) this is a test)
 +
</pre>
 +
 +
=== caadar ===
 +
 +
(caadar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caadar (quote (((((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)
 +
</pre>
 +
 +
=== caaddr ===
 +
 +
(caaddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caaddr (quote (((((hello there) this is a test) what is this) (((1 2 3) 4 5 6) 7 8 9) another item) head ((1 2) 3 4) in the list))) => (1 2)
 +
</pre>
 +
 +
=== caadr ===
 +
 +
(caadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caadr (quote (((((hello there) this is a test) what is this) (((1 2 3) 4 5 6) 7 8 9) another item) (in this) ((7 8)) the list))) => in
 +
</pre>
 +
 +
=== caar ===
 +
 +
(caar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caar (quote (((((hello there) this is a test) what is this) another item) in the list))) => (((hello there) this is a test) what is this)
 +
</pre>
 +
 +
=== cadaar ===
 +
 +
(cadaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cadaar (quote (((((hello there) this is a test) (what) is this) (yet another) item) in the list))) => (what)
 +
</pre>
 +
 +
=== cadadr ===
 +
 +
(cadadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cadadr (quote (((((hello there) this is a test) what is this) (yet another) item) (in the) list))) => the
 +
</pre>
 +
 +
=== cadar ===
 +
 +
(cadar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cadar (quote (((((hello there) this is a test) what is this) (yet another) item) in the list))) => (yet another)
 +
</pre>
 +
 +
=== caddar ===
 +
 +
(caddar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caddar (quote (((((hello there) this is a test) what is this) another item) in the list))) => item
 +
</pre>
 +
 +
=== cadddr ===
 +
 +
(cadddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cadddr (quote (((((hello there) this is a test) what is this) another item) in the list))) => list
 +
</pre>
 +
 +
=== caddr ===
 +
 +
(caddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caddr (quote (((((hello there) this is a test) what is this) another item) in the list))) => the
 +
</pre>
 +
 +
=== cadr ===
 +
 +
(cadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cadr (quote (((((hello there) this is a test) what is this) another item) in the list))) => in
 +
</pre>
 +
 +
=== car ===
 +
 +
(car ...)
 +
 +
Example:
 +
 +
<pre>
 +
(car (quote (((((hello there) this is a test) what is this) another item) in the list))) => ((((hello there) this is a test) what is this) another item)
 +
</pre>
 +
 +
=== case ===
 +
 +
(case ...)
 +
 +
Example:
 +
 +
<pre>
 +
(case (quote thing1) (thing2 1) (thing1 2)) => 2
 +
</pre>
 +
 +
=== case-2 ===
 +
 +
(case-2 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(case (quote thing1) (thing2 1) ((thing1 thing3) 2)) => 2
 +
</pre>
 +
 +
=== case-3 ===
 +
 +
(case-3 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(case (quote thingx) (thing2 1) ((thing1 thing3) 2) (else 3)) => 3
 +
</pre>
 +
 +
=== cd ===
 +
 +
(cd ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cd) => ""
 +
</pre>
 +
 +
=== cdaaar ===
 +
 +
(cdaaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdaaar (quote (((((hello there) this is a test) what is this) another item)))) => (this is a test)
 +
</pre>
 +
 +
=== cdaadr ===
 +
 +
(cdaadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdaadr (quote (((((hello there) this is a test) what is this) another item) ((7 8)) 9 10))) => (8)
 +
</pre>
 +
 +
=== cdaar ===
 +
 +
(cdaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdaar (quote (((((hello there) this is a test) what is this) another item)))) => (what is this)
 +
</pre>
 +
 +
=== cdadar ===
 +
 +
(cdadar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdadar (quote (((((hello there) this is a test) what is this) (another two) items)))) => (two)
 +
</pre>
 +
 +
=== cdaddr ===
 +
 +
(cdaddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdaddr (quote (((((hello there) this is a test) what is this) another item) 1 (2 5) 3 4))) => (5)
 +
</pre>
 +
 +
=== cdadr ===
 +
 +
(cdadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdadr (quote (((((hello there) this is a test) what is this) another item) (1 6) (2 5) 3 4))) => (6)
 +
</pre>
 +
 +
=== cdar ===
 +
 +
(cdar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdar (quote (((((hello there) this is a test) what is this) another item)))) => (another item)
 +
</pre>
 +
 +
=== cddaar ===
 +
 +
(cddaar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cddaar (quote (((((hello there) this is a test) what is this) another item) 1 (2) 3))) => (is this)
 +
</pre>
 +
 +
=== cddadr ===
 +
 +
(cddadr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cddadr (quote (((((hello there) this is a test) what is this) another item) (7 13) (8 12) 9 10))) => ()
 +
</pre>
 +
 +
=== cddar ===
 +
 +
(cddar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cddar (quote (((((hello there) this is a test) what is this) another item)))) => (item)
 +
</pre>
 +
 +
=== cdddar ===
 +
 +
(cdddar ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdddar (quote (((((hello there) this is a test) what is this) another item)))) => ()
 +
</pre>
 +
 +
=== cddddr ===
 +
 +
(cddddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cddddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3 4 5))) => (4 5)
 +
</pre>
 +
 +
=== cdddr ===
 +
 +
(cdddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3 4))) => (3 4)
 +
</pre>
 +
 +
=== cddr ===
 +
 +
(cddr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3))) => (2 3)
 +
</pre>
 +
 +
=== cdr ===
 +
 +
(cdr ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cdr (quote (((((hello there) this is a test) what is this) another item) 1 2 3))) => (1 2 3)
 +
</pre>
 +
 +
=== char->integer ===
 +
 +
(char->integer ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char->integer #\a) => 97
 +
</pre>
 +
 +
=== char->string ===
 +
 +
(char->string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char->string #\b) => "b"
 +
</pre>
 +
 +
=== char-alphabetic? ===
 +
 +
(char-alphabetic? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-alphabetic? #\A) => #t
 +
</pre>
 +
 +
=== char-numeric? ===
 +
 +
(char-numeric? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-numeric? #\1) => #t
 +
</pre>
 +
 +
=== char-whitespace? ===
 +
 +
(char-whitespace? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-whitespace? #\t) => #f
 +
</pre>
 +
 +
=== char-whitespace? ===
 +
 +
(char-whitespace? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-whitespace? #\ ) => #t
 +
</pre>
 +
 +
=== char-whitespace? ===
 +
 +
(char-whitespace? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-whitespace? #\
 +
) => #t
 +
</pre>
 +
 +
=== char-whitespace? ===
 +
 +
(char-whitespace? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char-whitespace? #\a) => #f
 +
</pre>
 +
 +
=== char=? ===
 +
 +
(char=? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char=? #\a #\a) => #t
 +
</pre>
 +
 +
=== char=? ===
 +
 +
(char=? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char=? #\a #\b) => #f
 +
</pre>
 +
 +
=== char? ===
 +
 +
(char? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(char? 2) => #f
 +
</pre>
 +
 +
=== cond ===
 +
 +
(cond ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cond (#f 1) (else 2)) => 2
 +
</pre>
 +
 +
=== cons ===
 +
 +
(cons ...)
 +
 +
Example:
 +
 +
<pre>
 +
(cons 1 (quote ())) => (1)
 +
</pre>
 +
 +
=== current-directory ===
 +
 +
(current-directory ...)
 +
 +
Example:
 +
 +
<pre>
 +
(current-directory) => "."
 +
</pre>
 +
 +
=== current-environment ===
 +
 +
(current-environment ...)
 +
 +
Example:
 +
 +
<pre>
 +
(length (dir (current-environment))) => 160
 +
</pre>
 +
 +
=== current-time ===
 +
 +
(current-time ...)
 +
 +
Example:
 +
 +
<pre>
 +
(current-time) => 1397405073.208179
 +
</pre>
 +
 +
=== cut ===
 +
 +
(cut ...)
 +
 +
Example:
 +
 +
<pre>
 +
(letrec ((loop (lambda (n) (if (= n 0) (set! var (cut 23)) (loop (- n 1))))) (var 0)) (loop 10) var) => (23)
 +
</pre>
 +
 +
=== dict ===
 +
 +
(dict ...)
 +
 +
Example:
 +
 +
<pre>
 +
(dict (quote ((1 2) (3 4)))) => none
 +
</pre>
 +
 +
=== dir ===
 +
 +
(dir ...)
 +
 +
Example:
 +
 +
<pre>
 +
(length (dir)) => 170
 +
</pre>
 +
 +
=== eq? ===
 +
 +
(eq? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(eq? (quote a) (quote a)) => #t
 +
</pre>
 +
 +
=== equal? ===
 +
 +
(equal? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(equal? 1 1.0) => #t
 +
</pre>
 +
 +
=== eqv? ===
 +
 +
(eqv? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(eqv? 1 1) => #t
 +
</pre>
 +
 +
=== error ===
 +
 +
(error ...)
 +
 +
Example:
 +
 +
<pre>
 +
(try (error (quote a) "message") (catch e e (cadr e))) => "Error in 'a': message"
 +
</pre>
 +
 +
=== eval ===
 +
 +
(eval ...)
 +
 +
Example:
 +
 +
<pre>
 +
(eval (quote (+ 1 2))) => 3
 +
</pre>
 +
 +
=== eval-ast ===
 +
 +
(eval-ast ...)
 +
 +
Example:
 +
 +
<pre>
 +
(eval-ast (parse (quote (+ 3 4)))) => 7
 +
</pre>
 +
 +
=== even? ===
 +
 +
(even? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(even? 33) => #f
 +
</pre>
 +
 +
=== float ===
 +
 +
(float ...)
 +
 +
Example:
 +
 +
<pre>
 +
(float 23) => 23.0
 +
</pre>
 +
 +
=== for-each ===
 +
 +
(for-each ...)
 +
 +
Example:
 +
 +
<pre>
 +
(for-each (lambda (n) (+ n 1)) (quote (1 2 3))) => <void>
 +
</pre>
 +
 +
=== format ===
 +
 +
(format ...)
 +
 +
Example:
 +
 +
<pre>
 +
(format "~a ~s ~%" "hello" "hello") => "hello \"hello\"
 +
"
 +
</pre>
 +
 +
=== get-stack-trace ===
 +
 +
(get-stack-trace ...)
 +
 +
Example:
 +
 +
<pre>
 +
(caddr (cadar (get-stack-trace))) => 69
 +
</pre>
 +
 +
=== int ===
 +
 +
(int ...)
 +
 +
Example:
 +
 +
<pre>
 +
(int 12.8) => 13
 +
</pre>
 +
 +
=== integer->char ===
 +
 +
(integer->char ...)
 +
 +
Example:
 +
 +
<pre>
 +
(integer->char 97) => #\a
 +
</pre>
 +
 +
=== iter? ===
 +
 +
(iter? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(iter? 3) => #f
 +
</pre>
 +
 +
=== length ===
 +
 +
(length ...)
 +
 +
Example:
 +
 +
<pre>
 +
(length (quote (1 2 3))) => 3
 +
</pre>
 +
 +
=== let ===
 +
 +
(let ...)
 +
 +
Example:
 +
 +
<pre>
 +
(let ((x 1)) x) => 1
 +
</pre>
 +
 +
=== let* ===
 +
 +
(let* ...)
 +
 +
Example:
 +
 +
<pre>
 +
(let* ((x 1) (y (+ x 1))) y) => 2
 +
</pre>
 +
 +
=== letrec ===
 +
 +
(letrec ...)
 +
 +
Example:
 +
 +
<pre>
 +
(letrec ((loop (lambda (n) (if (= n 0) (quote ok) (loop (- n 1)))))) (loop 10)) => ok
 +
</pre>
 +
 +
=== list ===
 +
 +
(list ...)
 +
 +
Example:
 +
 +
<pre>
 +
(list 1 2) => (1 2)
 +
</pre>
 +
 +
=== list->string ===
 +
 +
(list->string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(list->string (quote (#\1 #\2 #\3))) => "123"
 +
</pre>
 +
 +
=== list->vector ===
 +
 +
(list->vector ...)
 +
 +
Example:
 +
 +
<pre>
 +
(list->vector (quote (1 2 3))) => [1, 2, 3]
 +
</pre>
 +
 +
=== list-ref ===
 +
 +
(list-ref ...)
 +
 +
Example:
 +
 +
<pre>
 +
(list-ref (quote (1 2 3)) 1) => 2
 +
</pre>
 +
 +
=== list? ===
 +
 +
(list? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(list? (quote (1 2 3))) => #t
 +
</pre>
 +
 +
=== make-set ===
 +
 +
(make-set ...)
 +
 +
Example:
 +
 +
<pre>
 +
(sort < (make-set (quote (1 2 3 1 2)))) => (1 2 3)
 +
</pre>
 +
 +
=== make-vector ===
 +
 +
(make-vector ...)
 +
 +
Example:
 +
 +
<pre>
 +
(make-vector 3) => [0, 0, 0]
 +
</pre>
 +
 +
=== map ===
 +
 +
(map ...)
 +
 +
Example:
 +
 +
<pre>
 +
(map (lambda (n) (+ n 1)) (range 5)) => (1 2 3 4 5)
 +
</pre>
 +
 +
=== member ===
 +
 +
(member ...)
 +
 +
Example:
 +
 +
<pre>
 +
(member "b" (quote ("a" "b" "c"))) => ("b" "c")
 +
</pre>
 +
 +
=== memq ===
 +
 +
(memq ...)
 +
 +
Example:
 +
 +
<pre>
 +
(memq (quote b) (quote (a b c))) => (b c)
 +
</pre>
 +
 +
=== memv ===
 +
 +
(memv ...)
 +
 +
Example:
 +
 +
<pre>
 +
(memv 2 (quote (1.0 2.0 3.0))) => (2.0 3.0)
 +
</pre>
 +
 +
=== not ===
 +
 +
(not ...)
 +
 +
Example:
 +
 +
<pre>
 +
(not #f) => #t
 +
</pre>
 +
 +
=== null? ===
 +
 +
(null? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(null? (quote ())) => #t
 +
</pre>
 +
 +
=== number->string ===
 +
 +
(number->string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(number->string 23) => "23"
 +
</pre>
 +
 +
=== number? ===
 +
 +
(number? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(number? 23) => #t
 +
</pre>
 +
 +
=== odd? ===
 +
 +
(odd? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(odd? 45) => #t
 +
</pre>
 +
 +
=== or ===
 +
 +
(or ...)
 +
 +
Example:
 +
 +
<pre>
 +
(or #t (/ 1 0)) => #t
 +
</pre>
 +
 +
=== pair? ===
 +
 +
(pair? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(pair? (quote ())) => #f
 +
</pre>
 +
 +
=== pair? ===
 +
 +
(pair? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(pair? (cons 1 2)) => #t
 +
</pre>
 +
 +
=== parse ===
 +
 +
(parse ...)
 +
 +
Example:
 +
 +
<pre>
 +
(parse (quote (+ 1 2))) => (app-aexp (lexical-address-aexp 0 1 + none) ((lit-aexp 1 none) (lit-aexp 2 none)) none)
 +
</pre>
 +
 +
=== parse-string ===
 +
 +
(parse-string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(parse-string "(- 7 8)") => (app-aexp (lexical-address-aexp 0 2 - (stdin 1 2 2 1 2 2)) ((lit-aexp 7 (stdin 1 4 4 1 4 4)) (lit-aexp 8 (stdin 1 6 6 1 6 6))) (stdin 1 1 1 1 7 7))
 +
</pre>
 +
 +
=== procedure? ===
 +
 +
(procedure? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(procedure? procedure?) => #t
 +
</pre>
 +
 +
=== quotient ===
 +
 +
(quotient ...)
 +
 +
Example:
 +
 +
<pre>
 +
(quotient 1 4) => 0
 +
</pre>
 +
 +
=== rac ===
 +
 +
(rac ...)
 +
 +
Example:
 +
 +
<pre>
 +
(rac (quote (1 2 3))) => 3
 +
</pre>
 +
 +
=== range ===
 +
 +
(range ...)
 +
 +
Example:
 +
 +
<pre>
 +
(range 10) => (0 1 2 3 4 5 6 7 8 9)
 +
</pre>
 +
 +
=== rational ===
 +
 +
(rational ...)
 +
 +
Example:
 +
 +
<pre>
 +
(rational 3 4) => 3/4
 +
</pre>
 +
 +
=== rdc ===
 +
 +
(rdc ...)
 +
 +
Example:
 +
 +
<pre>
 +
(rdc (quote (1 2 3))) => (1 2)
 +
</pre>
 +
 +
=== read-string ===
 +
 +
(read-string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(read-string (quote (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))
 +
</pre>
 +
 +
=== remainder ===
 +
 +
(remainder ...)
 +
 +
Example:
 +
 +
<pre>
 +
(remainder 1 4) => 1
 +
</pre>
 +
 +
=== require ===
 +
 +
(require ...)
 +
 +
Example:
 +
 +
<pre>
 +
(require #t) => ok
 +
</pre>
 +
 +
=== reverse ===
 +
 +
(reverse ...)
 +
 +
Example:
 +
 +
<pre>
 +
(reverse (quote (1 2 3))) => (3 2 1)
 +
</pre>
 +
 +
=== round-1 ===
 +
 +
(round-1 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(round 45.5) => 46
 +
</pre>
 +
 +
=== round-2 ===
 +
 +
(round-2 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(round 45.4) => 45
 +
</pre>
 +
 +
=== set-car! ===
 +
 +
(set-car! ...)
 +
 +
Example:
 +
 +
<pre>
 +
(let ((x (quote (1 2 3)))) (set-car! x 0) x) => (0 2 3)
 +
</pre>
 +
 +
=== set-cdr! ===
 +
 +
(set-cdr! ...)
 +
 +
Example:
 +
 +
<pre>
 +
(let ((x (quote (1 2 3)))) (set-cdr! x (quote (3 4))) x) => (1 3 4)
 +
</pre>
 +
 +
=== snoc ===
 +
 +
(snoc ...)
 +
 +
Example:
 +
 +
<pre>
 +
(snoc 0 (quote (1 2 3))) => (1 2 3 0)
 +
</pre>
 +
 +
=== sort ===
 +
 +
(sort ...)
 +
 +
Example:
 +
 +
<pre>
 +
(sort < (quote (3 7 1 2))) => (1 2 3 7)
 +
</pre>
 +
 +
=== sqrt ===
 +
 +
(sqrt ...)
 +
 +
Example:
 +
 +
<pre>
 +
(sqrt 3) => 1.7320508075688772
 +
</pre>
 +
 +
=== string ===
 +
 +
(string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string #\1 #\2) => "12"
 +
</pre>
 +
 +
=== string->list ===
 +
 +
(string->list ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string->list "hello world") => (#\h #\e #\l #\l #\o #\  #\w #\o #\r #\l #\d)
 +
</pre>
 +
 +
=== string->number ===
 +
 +
(string->number ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string->number "12.1") => 12.1
 +
</pre>
 +
 +
=== string->symbol ===
 +
 +
(string->symbol ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string->symbol "hello") => hello
 +
</pre>
 +
 +
=== string-append ===
 +
 +
(string-append ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string-append "hell" "o") => "hello"
 +
</pre>
 +
 +
=== string-length ===
 +
 +
(string-length ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string-length "what") => 4
 +
</pre>
 +
 +
=== string-ref ===
 +
 +
(string-ref ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string-ref "what" 2) => #\a
 +
</pre>
 +
 +
=== string-split ===
 +
 +
(string-split ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string-split "hello.world" #\.) => ("hello" "world")
 +
</pre>
 +
 +
=== string<? ===
 +
 +
(string<? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string<? "a" "b") => #t
 +
</pre>
 +
 +
=== string=? ===
 +
 +
(string=? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string=? "a" "b") => #f
 +
</pre>
 +
 +
=== string? ===
 +
 +
(string? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(string? "hello") => #t
 +
</pre>
 +
 +
=== substring ===
 +
 +
(substring ...)
 +
 +
Example:
 +
 +
<pre>
 +
(substring "hello" 1 3) => "el"
 +
</pre>
 +
 +
=== symbol ===
 +
 +
(symbol ...)
 +
 +
Example:
 +
 +
<pre>
 +
(symbol "hello") => hello
 +
</pre>
 +
 +
=== symbol->string ===
 +
 +
(symbol->string ...)
 +
 +
Example:
 +
 +
<pre>
 +
(symbol->string (quote hello)) => "hello"
 +
</pre>
 +
 +
=== symbol? ===
 +
 +
(symbol? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(symbol? (quote hello)) => #t
 +
</pre>
 +
 +
=== typeof ===
 +
 +
(typeof ...)
 +
 +
Example:
 +
 +
<pre>
 +
(typeof 23) => <type 'int'>
 +
</pre>
 +
 +
=== unparse ===
 +
 +
(unparse ...)
 +
 +
Example:
 +
 +
<pre>
 +
(unparse (parse (quote (+ 1 2)))) => (+ 1 2)
 +
</pre>
 +
 +
=== use-lexial-address ===
 +
 +
(use-lexial-address ...)
 +
 +
Example:
 +
 +
<pre>
 +
(use-lexical-address) => #t
 +
</pre>
 +
 +
=== use-satck-trace ===
 +
 +
(use-satck-trace ...)
 +
 +
Example:
 +
 +
<pre>
 +
(use-stack-trace) => #t
 +
</pre>
 +
 +
=== use-tracing ===
 +
 +
(use-tracing ...)
 +
 +
Example:
 +
 +
<pre>
 +
(use-tracing) => #f
 +
</pre>
 +
 +
=== using ===
 +
 +
(using ...)
 +
 +
Example:
 +
 +
<pre>
 +
(try (using "math") (catch e e (using "Graphics"))) => ()
 +
</pre>
 +
 +
=== vector ===
 +
 +
(vector ...)
 +
 +
Example:
 +
 +
<pre>
 +
(vector 1 2 3) => [1, 2, 3]
 +
</pre>
 +
 +
=== vector->lsit ===
 +
 +
(vector->lsit ...)
 +
 +
Example:
 +
 +
<pre>
 +
(vector->list (vector 1 2 3)) => (1 2 3)
 +
</pre>
 +
 +
=== vector-ref ===
 +
 +
(vector-ref ...)
 +
 +
Example:
 +
 +
<pre>
 +
(vector-ref (vector 1 2 3) 2) => 3
 +
</pre>
 +
 +
=== let ===
 +
 +
(let ...)
 +
 +
Example:
 +
 +
<pre>
 +
(let ((v (vector 1 2 3))) (vector-set! v 2 (quote a)) v) => [1, 2, a]
 +
</pre>
 +
 +
=== vector? ===
 +
 +
(vector? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(vector? (vector)) => #t
 +
</pre>
 +
 +
=== (void) ===
 +
 +
((void) ...)
 +
 +
Example:
 +
 +
<pre>
 +
(void) => <void>
 +
</pre>
 +
 +
=== zero? ===
 +
 +
(zero? ...)
 +
 +
Example:
 +
 +
<pre>
 +
(zero? 0.0) => #t
 +
</pre>
 +
 +
=== my-odd ===
 +
 +
(my-odd ...)
 +
 +
Example:
 +
 +
<pre>
 +
(my-odd? 42) => #f
 +
</pre>
 +
 +
=== my-even ===
 +
 +
(my-even ...)
 +
 +
Example:
 +
 +
<pre>
 +
(my-even? 42) => #t
 +
</pre>
 +
 +
=== my-odd ===
 +
 +
(my-odd ...)
 +
 +
Example:
 +
 +
<pre>
 +
(my-odd? 43) => #t
 +
</pre>
 +
 +
=== my-even ===
 +
 +
(my-even ...)
 +
 +
Example:
 +
 +
<pre>
 +
(my-even? 43) => #f
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (0 1 4 9 16 25 36 49 64 81)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (25 64 121 196 289)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (36 49 64 81)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => done
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => done
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => done
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => done
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 120
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 3628800
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 10946
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (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)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (1 2 3 4 5)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (1 (2 3 4 5))
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (1 2 (3 4 5))
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (1 2 (3))
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => (1 2 ())
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => "not enough arguments given"
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => ((1 2 3) (42) ((1 2 3)) (1 2 3 (4 5)) (1 2 3 4))
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 40
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 40
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 50
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 60
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => blastoff!
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => #t
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 6
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => #f
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => ((6) orange 5)
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 3
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 3
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => yes
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => yes
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => oops
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 40
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 50
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 40
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => oops
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => oops
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 77
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 3
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => <void>
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5/1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => "division by zero"
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => "division by zero"
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5/1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => -1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5/1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => -1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 5/1
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => foo
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => ack
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => 99
 +
</pre>
 +
 +
=== COMMAND ===
 +
 +
(COMMAND ...)
 +
 +
Example:
 +
 +
<pre>
 +
ans => doug
 +
</pre>
 +
 +
=== define-datatype-1 ===
 +
 +
(define-datatype-1 ...)
 +
 +
Example:
 +
 +
<pre>
 +
lc-exp? => ()
 +
</pre>
 +
 +
=== define-datatype-2 ===
 +
 +
(define-datatype-2 ...)
 +
 +
Example:
 +
 +
<pre>
 +
var-exp => ()
 +
</pre>
 +
 +
=== define-datatype-3 ===
 +
 +
(define-datatype-3 ...)
 +
 +
Example:
 +
 +
<pre>
 +
lambda-exp => ()
 +
</pre>
 +
 +
=== define-datatype-4 ===
 +
 +
(define-datatype-4 ...)
 +
 +
Example:
 +
 +
<pre>
 +
app-exp => ()
 +
</pre>
 +
 +
=== define-datatype-5 ===
 +
 +
(define-datatype-5 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(var-exp (quote a)) => ()
 +
</pre>
 +
 +
=== define-datatype-6 ===
 +
 +
(define-datatype-6 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(lambda-exp (quote a) (var-exp (quote a))) => ()
 +
</pre>
 +
 +
=== define-datatype-7 ===
 +
 +
(define-datatype-7 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(app-exp (lambda-exp (quote a) (var-exp (quote a))) (var-exp (quote a))) => ()
 +
</pre>
 +
 +
=== define-datatype-8 ===
 +
 +
(define-datatype-8 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(un-parse (var-exp (quote a))) => a
 +
</pre>
 +
 +
=== define-datatype-8 ===
 +
 +
(define-datatype-8 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(un-parse (lambda-exp (quote a) (var-exp (quote a)))) => (a (var-exp a))
 +
</pre>
 +
 +
=== define-datatype-8 ===
 +
 +
(define-datatype-8 ...)
 +
 +
Example:
 +
 +
<pre>
 +
(un-parse (app-exp (lambda-exp (quote a) (var-exp (quote a))) (var-exp (quote a)))) => ((lambda-exp a (var-exp a)) (var-exp a))
 +
</pre>
 +
 +
 +
 +
<pre>
 +
(define distinct? (lambda (nums) (or (null? nums) (null? (cdr nums)) (and (not (member (car nums) (cdr nums))) (distinct? (cdr nums))))))
 +
</pre>
 +
 +
 +
 +
<pre>
 +
(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 (quote baker:) baker) (list (quote cooper:) cooper) (list (quote fletcher:) fletcher) (list (quote miller:) miller) (list (quote smith:) smith)))))))))
 +
</pre>
 +
 +
=== choose ===
 +
 +
(choose ...)
 +
 +
Example:
 +
 +
<pre>
 +
(floors2) => ((baker: 3) (cooper: 2) (fletcher: 4) (miller: 5) (smith: 1))
 +
</pre>
 +
  
 
= Example Code =
 
= Example Code =

Revision as of 16:07, 13 April 2014

Here we will provide documentation for using Calico Scheme.

Calico Scheme is a new implementation of a Scheme-based language for Calico. It implements many core Scheme functions, but also adds some functionality to bring it into line with the other modern languages like Python and Ruby.

Contents

Commands

quasiquote

(quasiquote ...)

Example:

(quasiquote (list (unquote (+ 1 2)) 4)) => (list 3 4)

%

(% ...)

Example:

(% 10 3) => 1

*

(* ...)

Example:

(* 2 3) => 6

+

(+ ...)

Example:

(+ 7 8) => 15

-

(- ...)

Example:

(- 5 2) => 3

/

(/ ...)

Example:

(/ 3 4) => 3/4

<

(< ...)

Example:

(< 5 2) => #f

<=

(<= ...)

Example:

(<= 5 6) => #t

=

(= ...)

Example:

(= 6 7) => #f

>

(> ...)

Example:

(> 9 2) => #t

>=

(>= ...)

Example:

(>= 4 5) => #f

abs

(abs ...)

Example:

(abs -1) => 1

and

(and ...)

Example:

(and 4 1 2 #t (quote ()) 0) => 0

append

(append ...)

Example:

(append (quote (1 2 3)) (quote (4 5 6))) => (1 2 3 4 5 6)

apply

(apply ...)

Example:

(apply car (quote ((1)))) => 1

assq

(assq ...)

Example:

(assq 1 (quote ((1 2) (3 4)))) => (1 2)

assv

(assv ...)

Example:

(assv 1 (quote ((1 2) (3 4)))) => (1 2)

atom?

(atom? ...)

Example:

(atom? 1) => #t

boolean?

(boolean? ...)

Example:

(boolean? #t) => #t

caaaar

(caaaar ...)

Example:

(caaaar (quote (((((hello there) this is a test) what is this) another item) in the list))) => (hello there)

caaadr

(caaadr ...)

Example:

(caaadr (quote (((((hello there) this is a test) what is this) another item) ((((((1 2 3) 4 5 6) 7 8 9) 10 11 12) 13 14 15) 16 17 18)))) => ((((1 2 3) 4 5 6) 7 8 9) 10 11 12)

caaar

(caaar ...)

Example:

(caaar (quote (((((hello there) this is a test) what is this) another item) in the list))) => ((hello there) this is a test)

caadar

(caadar ...)

Example:

(caadar (quote (((((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

(caaddr ...)

Example:

(caaddr (quote (((((hello there) this is a test) what is this) (((1 2 3) 4 5 6) 7 8 9) another item) head ((1 2) 3 4) in the list))) => (1 2)

caadr

(caadr ...)

Example:

(caadr (quote (((((hello there) this is a test) what is this) (((1 2 3) 4 5 6) 7 8 9) another item) (in this) ((7 8)) the list))) => in

caar

(caar ...)

Example:

(caar (quote (((((hello there) this is a test) what is this) another item) in the list))) => (((hello there) this is a test) what is this)

cadaar

(cadaar ...)

Example:

(cadaar (quote (((((hello there) this is a test) (what) is this) (yet another) item) in the list))) => (what)

cadadr

(cadadr ...)

Example:

(cadadr (quote (((((hello there) this is a test) what is this) (yet another) item) (in the) list))) => the

cadar

(cadar ...)

Example:

(cadar (quote (((((hello there) this is a test) what is this) (yet another) item) in the list))) => (yet another)

caddar

(caddar ...)

Example:

(caddar (quote (((((hello there) this is a test) what is this) another item) in the list))) => item

cadddr

(cadddr ...)

Example:

(cadddr (quote (((((hello there) this is a test) what is this) another item) in the list))) => list

caddr

(caddr ...)

Example:

(caddr (quote (((((hello there) this is a test) what is this) another item) in the list))) => the

cadr

(cadr ...)

Example:

(cadr (quote (((((hello there) this is a test) what is this) another item) in the list))) => in

car

(car ...)

Example:

(car (quote (((((hello there) this is a test) what is this) another item) in the list))) => ((((hello there) this is a test) what is this) another item)

case

(case ...)

Example:

(case (quote thing1) (thing2 1) (thing1 2)) => 2

case-2

(case-2 ...)

Example:

(case (quote thing1) (thing2 1) ((thing1 thing3) 2)) => 2

case-3

(case-3 ...)

Example:

(case (quote thingx) (thing2 1) ((thing1 thing3) 2) (else 3)) => 3

cd

(cd ...)

Example:

(cd) => ""

cdaaar

(cdaaar ...)

Example:

(cdaaar (quote (((((hello there) this is a test) what is this) another item)))) => (this is a test)

cdaadr

(cdaadr ...)

Example:

(cdaadr (quote (((((hello there) this is a test) what is this) another item) ((7 8)) 9 10))) => (8)

cdaar

(cdaar ...)

Example:

(cdaar (quote (((((hello there) this is a test) what is this) another item)))) => (what is this)

cdadar

(cdadar ...)

Example:

(cdadar (quote (((((hello there) this is a test) what is this) (another two) items)))) => (two)

cdaddr

(cdaddr ...)

Example:

(cdaddr (quote (((((hello there) this is a test) what is this) another item) 1 (2 5) 3 4))) => (5)

cdadr

(cdadr ...)

Example:

(cdadr (quote (((((hello there) this is a test) what is this) another item) (1 6) (2 5) 3 4))) => (6)

cdar

(cdar ...)

Example:

(cdar (quote (((((hello there) this is a test) what is this) another item)))) => (another item)

cddaar

(cddaar ...)

Example:

(cddaar (quote (((((hello there) this is a test) what is this) another item) 1 (2) 3))) => (is this)

cddadr

(cddadr ...)

Example:

(cddadr (quote (((((hello there) this is a test) what is this) another item) (7 13) (8 12) 9 10))) => ()

cddar

(cddar ...)

Example:

(cddar (quote (((((hello there) this is a test) what is this) another item)))) => (item)

cdddar

(cdddar ...)

Example:

(cdddar (quote (((((hello there) this is a test) what is this) another item)))) => ()

cddddr

(cddddr ...)

Example:

(cddddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3 4 5))) => (4 5)

cdddr

(cdddr ...)

Example:

(cdddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3 4))) => (3 4)

cddr

(cddr ...)

Example:

(cddr (quote (((((hello there) this is a test) what is this) another item) 1 2 3))) => (2 3)

cdr

(cdr ...)

Example:

(cdr (quote (((((hello there) this is a test) what is this) another item) 1 2 3))) => (1 2 3)

char->integer

(char->integer ...)

Example:

(char->integer #\a) => 97

char->string

(char->string ...)

Example:

(char->string #\b) => "b"

char-alphabetic?

(char-alphabetic? ...)

Example:

(char-alphabetic? #\A) => #t

char-numeric?

(char-numeric? ...)

Example:

(char-numeric? #\1) => #t

char-whitespace?

(char-whitespace? ...)

Example:

(char-whitespace? #\t) => #f

char-whitespace?

(char-whitespace? ...)

Example:

(char-whitespace? #\	) => #t

char-whitespace?

(char-whitespace? ...)

Example:

(char-whitespace? #\
) => #t

char-whitespace?

(char-whitespace? ...)

Example:

(char-whitespace? #\a) => #f

char=?

(char=? ...)

Example:

(char=? #\a #\a) => #t

char=?

(char=? ...)

Example:

(char=? #\a #\b) => #f

char?

(char? ...)

Example:

(char? 2) => #f

cond

(cond ...)

Example:

(cond (#f 1) (else 2)) => 2

cons

(cons ...)

Example:

(cons 1 (quote ())) => (1)

current-directory

(current-directory ...)

Example:

(current-directory) => "."

current-environment

(current-environment ...)

Example:

(length (dir (current-environment))) => 160

current-time

(current-time ...)

Example:

(current-time) => 1397405073.208179

cut

(cut ...)

Example:

(letrec ((loop (lambda (n) (if (= n 0) (set! var (cut 23)) (loop (- n 1))))) (var 0)) (loop 10) var) => (23)

dict

(dict ...)

Example:

(dict (quote ((1 2) (3 4)))) => none

dir

(dir ...)

Example:

(length (dir)) => 170

eq?

(eq? ...)

Example:

(eq? (quote a) (quote a)) => #t

equal?

(equal? ...)

Example:

(equal? 1 1.0) => #t

eqv?

(eqv? ...)

Example:

(eqv? 1 1) => #t

error

(error ...)

Example:

(try (error (quote a) "message") (catch e e (cadr e))) => "Error in 'a': message"

eval

(eval ...)

Example:

(eval (quote (+ 1 2))) => 3

eval-ast

(eval-ast ...)

Example:

(eval-ast (parse (quote (+ 3 4)))) => 7

even?

(even? ...)

Example:

(even? 33) => #f

float

(float ...)

Example:

(float 23) => 23.0

for-each

(for-each ...)

Example:

(for-each (lambda (n) (+ n 1)) (quote (1 2 3))) => <void>

format

(format ...)

Example:

(format "~a ~s ~%" "hello" "hello") => "hello \"hello\" 
"

get-stack-trace

(get-stack-trace ...)

Example:

(caddr (cadar (get-stack-trace))) => 69

int

(int ...)

Example:

(int 12.8) => 13

integer->char

(integer->char ...)

Example:

(integer->char 97) => #\a

iter?

(iter? ...)

Example:

(iter? 3) => #f

length

(length ...)

Example:

(length (quote (1 2 3))) => 3

let

(let ...)

Example:

(let ((x 1)) x) => 1

let*

(let* ...)

Example:

(let* ((x 1) (y (+ x 1))) y) => 2

letrec

(letrec ...)

Example:

(letrec ((loop (lambda (n) (if (= n 0) (quote ok) (loop (- n 1)))))) (loop 10)) => ok

list

(list ...)

Example:

(list 1 2) => (1 2)

list->string

(list->string ...)

Example:

(list->string (quote (#\1 #\2 #\3))) => "123"

list->vector

(list->vector ...)

Example:

(list->vector (quote (1 2 3))) => [1, 2, 3]

list-ref

(list-ref ...)

Example:

(list-ref (quote (1 2 3)) 1) => 2

list?

(list? ...)

Example:

(list? (quote (1 2 3))) => #t

make-set

(make-set ...)

Example:

(sort < (make-set (quote (1 2 3 1 2)))) => (1 2 3)

make-vector

(make-vector ...)

Example:

(make-vector 3) => [0, 0, 0]

map

(map ...)

Example:

(map (lambda (n) (+ n 1)) (range 5)) => (1 2 3 4 5)

member

(member ...)

Example:

(member "b" (quote ("a" "b" "c"))) => ("b" "c")

memq

(memq ...)

Example:

(memq (quote b) (quote (a b c))) => (b c)

memv

(memv ...)

Example:

(memv 2 (quote (1.0 2.0 3.0))) => (2.0 3.0)

not

(not ...)

Example:

(not #f) => #t

null?

(null? ...)

Example:

(null? (quote ())) => #t

number->string

(number->string ...)

Example:

(number->string 23) => "23"

number?

(number? ...)

Example:

(number? 23) => #t

odd?

(odd? ...)

Example:

(odd? 45) => #t

or

(or ...)

Example:

(or #t (/ 1 0)) => #t

pair?

(pair? ...)

Example:

(pair? (quote ())) => #f

pair?

(pair? ...)

Example:

(pair? (cons 1 2)) => #t

parse

(parse ...)

Example:

(parse (quote (+ 1 2))) => (app-aexp (lexical-address-aexp 0 1 + none) ((lit-aexp 1 none) (lit-aexp 2 none)) none)

parse-string

(parse-string ...)

Example:

(parse-string "(- 7 8)") => (app-aexp (lexical-address-aexp 0 2 - (stdin 1 2 2 1 2 2)) ((lit-aexp 7 (stdin 1 4 4 1 4 4)) (lit-aexp 8 (stdin 1 6 6 1 6 6))) (stdin 1 1 1 1 7 7))

procedure?

(procedure? ...)

Example:

(procedure? procedure?) => #t

quotient

(quotient ...)

Example:

(quotient 1 4) => 0

rac

(rac ...)

Example:

(rac (quote (1 2 3))) => 3

range

(range ...)

Example:

(range 10) => (0 1 2 3 4 5 6 7 8 9)

rational

(rational ...)

Example:

(rational 3 4) => 3/4

rdc

(rdc ...)

Example:

(rdc (quote (1 2 3))) => (1 2)

read-string

(read-string ...)

Example:

(read-string (quote (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))

remainder

(remainder ...)

Example:

(remainder 1 4) => 1

require

(require ...)

Example:

(require #t) => ok

reverse

(reverse ...)

Example:

(reverse (quote (1 2 3))) => (3 2 1)

round-1

(round-1 ...)

Example:

(round 45.5) => 46

round-2

(round-2 ...)

Example:

(round 45.4) => 45

set-car!

(set-car! ...)

Example:

(let ((x (quote (1 2 3)))) (set-car! x 0) x) => (0 2 3)

set-cdr!

(set-cdr! ...)

Example:

(let ((x (quote (1 2 3)))) (set-cdr! x (quote (3 4))) x) => (1 3 4)

snoc

(snoc ...)

Example:

(snoc 0 (quote (1 2 3))) => (1 2 3 0)

sort

(sort ...)

Example:

(sort < (quote (3 7 1 2))) => (1 2 3 7)

sqrt

(sqrt ...)

Example:

(sqrt 3) => 1.7320508075688772

string

(string ...)

Example:

(string #\1 #\2) => "12"

string->list

(string->list ...)

Example:

(string->list "hello world") => (#\h #\e #\l #\l #\o #\  #\w #\o #\r #\l #\d)

string->number

(string->number ...)

Example:

(string->number "12.1") => 12.1

string->symbol

(string->symbol ...)

Example:

(string->symbol "hello") => hello

string-append

(string-append ...)

Example:

(string-append "hell" "o") => "hello"

string-length

(string-length ...)

Example:

(string-length "what") => 4

string-ref

(string-ref ...)

Example:

(string-ref "what" 2) => #\a

string-split

(string-split ...)

Example:

(string-split "hello.world" #\.) => ("hello" "world")

string<?

(string<? ...)

Example:

(string<? "a" "b") => #t

string=?

(string=? ...)

Example:

(string=? "a" "b") => #f

string?

(string? ...)

Example:

(string? "hello") => #t

substring

(substring ...)

Example:

(substring "hello" 1 3) => "el"

symbol

(symbol ...)

Example:

(symbol "hello") => hello

symbol->string

(symbol->string ...)

Example:

(symbol->string (quote hello)) => "hello"

symbol?

(symbol? ...)

Example:

(symbol? (quote hello)) => #t

typeof

(typeof ...)

Example:

(typeof 23) => <type 'int'>

unparse

(unparse ...)

Example:

(unparse (parse (quote (+ 1 2)))) => (+ 1 2)

use-lexial-address

(use-lexial-address ...)

Example:

(use-lexical-address) => #t

use-satck-trace

(use-satck-trace ...)

Example:

(use-stack-trace) => #t

use-tracing

(use-tracing ...)

Example:

(use-tracing) => #f

using

(using ...)

Example:

(try (using "math") (catch e e (using "Graphics"))) => ()

vector

(vector ...)

Example:

(vector 1 2 3) => [1, 2, 3]

vector->lsit

(vector->lsit ...)

Example:

(vector->list (vector 1 2 3)) => (1 2 3)

vector-ref

(vector-ref ...)

Example:

(vector-ref (vector 1 2 3) 2) => 3

let

(let ...)

Example:

(let ((v (vector 1 2 3))) (vector-set! v 2 (quote a)) v) => [1, 2, a]

vector?

(vector? ...)

Example:

(vector? (vector)) => #t

(void)

((void) ...)

Example:

(void) => <void>

zero?

(zero? ...)

Example:

(zero? 0.0) => #t

my-odd

(my-odd ...)

Example:

(my-odd? 42) => #f

my-even

(my-even ...)

Example:

(my-even? 42) => #t

my-odd

(my-odd ...)

Example:

(my-odd? 43) => #t

my-even

(my-even ...)

Example:

(my-even? 43) => #f

COMMAND

(COMMAND ...)

Example:

ans => (0 1 4 9 16 25 36 49 64 81)

COMMAND

(COMMAND ...)

Example:

ans => (25 64 121 196 289)

COMMAND

(COMMAND ...)

Example:

ans => (36 49 64 81)

COMMAND

(COMMAND ...)

Example:

ans => 5

COMMAND

(COMMAND ...)

Example:

ans => done

COMMAND

(COMMAND ...)

Example:

ans => done

COMMAND

(COMMAND ...)

Example:

ans => done

COMMAND

(COMMAND ...)

Example:

ans => done

COMMAND

(COMMAND ...)

Example:

ans => 120

COMMAND

(COMMAND ...)

Example:

ans => 3628800

COMMAND

(COMMAND ...)

Example:

ans => 10946

COMMAND

(COMMAND ...)

Example:

ans => (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)

COMMAND

(COMMAND ...)

Example:

ans => (1 2 3 4 5)

COMMAND

(COMMAND ...)

Example:

ans => (1 (2 3 4 5))

COMMAND

(COMMAND ...)

Example:

ans => (1 2 (3 4 5))

COMMAND

(COMMAND ...)

Example:

ans => (1 2 (3))

COMMAND

(COMMAND ...)

Example:

ans => (1 2 ())

COMMAND

(COMMAND ...)

Example:

ans => "not enough arguments given"

COMMAND

(COMMAND ...)

Example:

ans => ((1 2 3) (42) ((1 2 3)) (1 2 3 (4 5)) (1 2 3 4))

COMMAND

(COMMAND ...)

Example:

ans => 40

COMMAND

(COMMAND ...)

Example:

ans => 40

COMMAND

(COMMAND ...)

Example:

ans => 50

COMMAND

(COMMAND ...)

Example:

ans => 60

COMMAND

(COMMAND ...)

Example:

ans => blastoff!

COMMAND

(COMMAND ...)

Example:

ans => #t

COMMAND

(COMMAND ...)

Example:

ans => 6

COMMAND

(COMMAND ...)

Example:

ans => #f

COMMAND

(COMMAND ...)

Example:

ans => 5

COMMAND

(COMMAND ...)

Example:

ans => ((6) orange 5)

COMMAND

(COMMAND ...)

Example:

ans => 3

COMMAND

(COMMAND ...)

Example:

ans => 3

COMMAND

(COMMAND ...)

Example:

ans => yes

COMMAND

(COMMAND ...)

Example:

ans => yes

COMMAND

(COMMAND ...)

Example:

ans => oops

COMMAND

(COMMAND ...)

Example:

ans => 40

COMMAND

(COMMAND ...)

Example:

ans => 50

COMMAND

(COMMAND ...)

Example:

ans => 40

COMMAND

(COMMAND ...)

Example:

ans => oops

COMMAND

(COMMAND ...)

Example:

ans => oops

COMMAND

(COMMAND ...)

Example:

ans => 77

COMMAND

(COMMAND ...)

Example:

ans => 3

COMMAND

(COMMAND ...)

Example:

ans => <void>

COMMAND

(COMMAND ...)

Example:

ans => 5/1

COMMAND

(COMMAND ...)

Example:

ans => "division by zero"

COMMAND

(COMMAND ...)

Example:

ans => "division by zero"

COMMAND

(COMMAND ...)

Example:

ans => 5/1

COMMAND

(COMMAND ...)

Example:

ans => -1

COMMAND

(COMMAND ...)

Example:

ans => 5/1

COMMAND

(COMMAND ...)

Example:

ans => -1

COMMAND

(COMMAND ...)

Example:

ans => 5/1

COMMAND

(COMMAND ...)

Example:

ans => foo

COMMAND

(COMMAND ...)

Example:

ans => ack

COMMAND

(COMMAND ...)

Example:

ans => 99

COMMAND

(COMMAND ...)

Example:

ans => doug

define-datatype-1

(define-datatype-1 ...)

Example:

lc-exp? => ()

define-datatype-2

(define-datatype-2 ...)

Example:

var-exp => ()

define-datatype-3

(define-datatype-3 ...)

Example:

lambda-exp => ()

define-datatype-4

(define-datatype-4 ...)

Example:

app-exp => ()

define-datatype-5

(define-datatype-5 ...)

Example:

(var-exp (quote a)) => ()

define-datatype-6

(define-datatype-6 ...)

Example:

(lambda-exp (quote a) (var-exp (quote a))) => ()

define-datatype-7

(define-datatype-7 ...)

Example:

(app-exp (lambda-exp (quote a) (var-exp (quote a))) (var-exp (quote a))) => ()

define-datatype-8

(define-datatype-8 ...)

Example:

(un-parse (var-exp (quote a))) => a

define-datatype-8

(define-datatype-8 ...)

Example:

(un-parse (lambda-exp (quote a) (var-exp (quote a)))) => (a (var-exp a))

define-datatype-8

(define-datatype-8 ...)

Example:

(un-parse (app-exp (lambda-exp (quote a) (var-exp (quote a))) (var-exp (quote a)))) => ((lambda-exp a (var-exp a)) (var-exp a))


(define distinct? (lambda (nums) (or (null? nums) (null? (cdr nums)) (and (not (member (car nums) (cdr nums))) (distinct? (cdr nums))))))


(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 (quote baker:) baker) (list (quote cooper:) cooper) (list (quote fletcher:) fletcher) (list (quote miller:) miller) (list (quote smith:) smith)))))))))

choose

(choose ...)

Example:

(floors2) => ((baker: 3) (cooper: 2) (fletcher: 4) (miller: 5) (smith: 1))


Example Code

  • Examples - these come with Calico in Calico/examples/scheme

Scheme Extensions

  1. Exceptions - implements try/catch/finally
  2. Modules and namespaces - implements namespaces for imports and foreign objects
  3. DLLs - import libraries written for the CLR
  4. Interop - ways for Scheme to interop with other Calico languages

Exceptions

(raise <exp>)
(try <exp>...)
(try <exp>... (catch <sym> <exp>...))
(try <exp>... (finally <exp>...))
(try <exp>... (catch <sym> <exp>...) (finally <exp>...))

There are four main forms of try:

  1. try alone: has no effect---doesn't catch exceptions
  2. try with a catch-clause: if exception in try-body, catch-clause will catch and provide return value, otherwise body of try provides. If exception in catch-clause will simple raise it.
  3. try with a finally-clause: finally-clause will run if exception in try-body or not. If there is an exception in the finally, it will raise it.
  4. try with a catch-clause and finally-clause: if an exception in try-body, the catch-clause will run, followed by the finally-clause. If an exception is raised in the catch-clause too, then finally-clause will run, and then raise the catch-exception; if there is an exception raised in the

finally-clause, then it will raise.

The <sym> of the catch-clause will be bound to the expression raised.

Examples

==> 

> (try x)
(uncaught exception: "unbound variable x")
==> "(try x (catch e e))"
"unbound variable x"
==> "(try x (catch e (raise e)))"
(uncaught exception: "unbound variable x")
==> "(try x (finally 'hi))"
hi 
(uncaught exception: "unbound variable x")
==> "(try x (catch e 1 2 3 4 (finally 'hi))"
hi 
4

Modules

Modules provide an easy method for structuring hierarchies of libraries and code.

Import

(import <string-exp>)
(import <string-exp> '<symbol-exp>)

Examples

==> (import "my-file.ss")

my-file.ss is a Scheme program file, which itself could have imports.

==> (import "my-file.ss" 'my-stuff)

Loads the file, and puts it in the namespace "my-stuff" accessible through the lookup interface below.

import uses the local environment, while load uses the toplevel-environment.

Lookup

module.name
module.module.name
==> (import "my-file.ss" 'my-stuff)
==> my-stuff.x
5

Directory Listing

==> (dir)
(- % * / + < <= = =? > >= abort abs and append apply assq assv atom? boolean? caaaar caaadr caaar caadar 
caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr call/cc call-with-current-continuation 
car case cases cd cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr 
cddr cdr char? char=? char-alphabetic? char-numeric? char-whitespace? cond cons current-directory 
current-environment current-time cut debug define-datatype dir display eq? equal? eqv? error eval 
eval-ast even? exit float for-each format get get-member globals import int iter? length let let* letrec 
list list? list->string list->vector list-head list-ref list-tail load make-set make-vector map member 
memq memv newline not null? number? number->string odd? or pair? parse parse-string print printf 
procedure? property quotient range rational read-string record-case remainder require reset-toplevel-env 
reverse safe-print set-car! set-cdr! sort sqrt string string? string<? string=? string->list string->number 
string->symbol string-append string-length string-ref string-split substring symbol symbol? symbol->string 
typeof unparse unparse-procedure use-lexical-address use-tracing using vector vector? vector->list 
vector-ref vector-set! void zero?)
==> (dir my-stuff)
(x y z)

You can also use dir on an object:

(using "Myro")
(dir Myro)

define-syntax

define-syntax is used to change the semantics of Scheme in a manner not possible with regular functions. For example, imagine that you wanted to time a particular function call. To time a function, you can do:

(let ((start (current-time)))
  (fact 5)
  (- (current-time) start))

If you tried to define a function time such that you could call it like:

(time (fact 5))

then, unfortunately, you would evaluate (fact 5) before you could do anything in the function time. You could call it like:

(time fact 5)

but that looks a bit strange. Perhaps a more natural way would be to just change the semantics of Scheme to allow (time (fact 5)). Scheme makes that easy with define-sytnax:

(define-syntax time 
  [(time ?exp) (let ((start (current-time)))
		 ?exp
		 (- (current-time) start))])

Now, you can call it like:

(time (fact 5))

and you get the correct answer.

define-syntax takes a list of two items: a template, and a response. If the template matches, then you evaluate the response. In this example, (time ?exp) matches, so the system will record the start time, evaluate the ?exp, and then return the time minus the start time.

Calico Scheme uses this simple, but powerful pattern matcher to implement define-case. Here is a more complex example: for.

(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))])

In this example, define-syntax creates a for function with 4 forms:

(for 4 times do (function ...))

(for x in '(1 2 3) do (function ...))

(for x at (0) in '(1 2 3) do (function ...))

(for x at (0 1 2) in (range 10) do (function ...))

Calico Libraries

You can use any of the Calico libraries:

scheme> (using "DLLName")
scheme> (DLLName.Class arg1 arg2)

For example, you can use Scheme to do art or control robots:

(using "Myro")
(Myro.init "sim")
(Myro.joystick)

Interop

There is a special object in the environment, calico. It has access to a variety of Calico functions. See Calico: calico object for more details.

Use the define! to put a variable in the global Calico namespace.

scheme> (define! x 8)
python> x
8

Wrap a function for use by other Calico languages:

scheme> (func (lambda (a b) (+ a b)))

Combine for cross-language interoperation:

 scheme> (define fact (lambda (n) (if (= n 1) 1 (* n (fact (- n 1))))))
 scheme> (define! factorial (func fact))
 python> factorial(5)
 120

Be careful not to wrap the func around the part that is called recursively, or you will destroy the tail-call optimization.

Iterators

Strings, vectors, and lists all work with map and for-each.

==> (map display "123")
123(void void void)
==> (for-each (lambda (v) (printf "~a\n" v)) (range 3))
1
2
3

choose/fail

Calico Scheme also contains a non-deterministic search with back-tracking. To use this, you select choice-points using the keyword "choose" with arguments, set requirements using the keyword "require", and fail using "(choose)". For example, to automatically find two numbers that sum to seven:

(define sum-to-seven
  (lambda ()
    (let ((num1 (choose 0 1 2 3 4 5 6 7 8 9))
          (num2 (choose 0 1 2 3 4 5 6 7 8 9)))
      (require (= (+ num1 num2) 7))
      (printf "The numbers are ~s ~s\n" num1 num2))))

Then, you can let Scheme do the searching for you:

scheme>>> (sum-to-seven)
The numbers are 0 7
Done

If you don't like that result, you can force Scheme back to any choice-points to make a different choice:

scheme>>> (choose)
The numbers are 1 6
Done

This can continue until there are no more choices left.

See menu -> File -> Examples -> Scheme -> choose-examples.ss for more examples.

scheme>>> (choose)
The numbers are 7 0
Done

cut

The (cut) operation will succeed, but cannot be back-tracked afterwards.

Help/Doc System

When you define a variable, you can optionally add a doc-string:

==> (define x "This variable holds the sum" 0)
==> (define y 0)
==> (define function "This computes the polynomial..." (lambda (x) ...))

You can lookup the doc-string with:

==> (help 'x)
This variable holds the sum

Misc

typeof will give you the .NET type of a value:

==> (typeof 1)
System.Int32
==> (typeof 238762372632732736)
Microsoft.Scripting.Math.BigInteger
==> (typeof 1/5)                
Rational
==> (cd "/path/to/folder")
==> (cd)
"/path/to/folder"
==> (import "file.ss" 'F)
==> (set! F.x 45)
==> (current-environment)
#<environment>
==> (remainder 4 5)
==> (quotient 6 4)
==> (dir (current-environment))
==> (make-set '(1 1 2 3 4 5))
==> (using "Myro")
==> (dir Myro.robot)

Language Interop

Converting from Scheme to Python:

scheme> (define pylist (calico.Evaluate "lambda *args: list(args)" "python"))
Ok
scheme> (define pytuple (calico.Evaluate "lambda *args: args" "python"))
Ok
scheme> (pylist 1 2 3)
[1, 2, 3]
scheme> (pytuple 1 2 3)
(1, 2, 3)

Converting from Python to Scheme

scheme> (define pylist2list
           (lambda (args)
              (map (lambda (i) i) args)))
Ok
scheme> (pylist2list (pylist 1 2 3))
(1 2 3)
scheme> (pylist2list (pytuple 1 2 3))
(1 2 3)

References

Calico

  1. CalicoDevelopment - plans and details for Calico development
  2. http://www.scheme.com/tspl4/ - The Scheme Programming Language, 4th edition

For Developers