CSE 341 -- Scheme/ML Cheatsheet

Here is a list of important equivalences between these two languages.
The Scheme WayThe ML WayNotes
;; Scheme comment (* ML comment *)
() nil The empty list
#t/#f true/false Boolean values
"hi" "hi" Literal strings
'hi "hi" ML doesn't support symbols
(+ 3 4) 3 + 4
(+ 2 7.0) Not legal! Unless we convert types: real(3) + 7.0
(fun 3 4)fun(3, 4)
(fun 3) fun(3) or fun 3
(list 3 4 5) or
'(3 4 5)
[3,4,5]
'((3 4) (5) (6 7 8)) [[3,4], [5], [6,7,8]]
'(2 (4 5) hi)Not Legal! (Lists can't be heterogeneous) Use tuples instead:
(3, [4,5], "hi")
(cons 1 '(2 3)) 1::[2,3] :: is the cons operator
(append '(1 2) '(3 4)) [1,2]@[3,4]
(if test then-expr else-expr) if test then then-expr else else-expr then-expr and else-expr must be the same type!
(define foo 22) val foo = 22;
(define (f x) ...) fun f(x) = ...;
(load "filename") use("filename");

dugan@cs.washington.edu (Last Update: )