5 Advanced Student
program | = | def-or-expr ... | ||||
def-or-expr | = | definition | ||||
| | expr | |||||
| | test-case | |||||
| | library-require | |||||
definition | = | (define (name variable ...) expr) | ||||
| | (define name expr) | |||||
| | (define-struct name (name ...)) | |||||
| | (define-datatype name (name name ...) ...) | |||||
expr | = | (begin expr expr ...) | ||||
| | (begin0 expr expr ...) | |||||
| | (set! variable expr) | |||||
| | (delay expr) | |||||
| | (lambda (variable ...) expr) | |||||
| | (λ (variable ...) expr) | |||||
| | (local [definition ...] expr) | |||||
| | (letrec ([name expr] ...) expr) | |||||
| | (shared ([name expr] ...) expr) | |||||
| | (let ([name expr] ...) expr) | |||||
| | (let name ([name expr] ...) expr) | |||||
| | (let* ([name expr] ...) expr) | |||||
| | (recur name ([name expr] ...) expr) | |||||
| | (expr expr ...) | |||||
| | (cond [expr expr] ... [expr expr]) | |||||
| | (cond [expr expr] ... [else expr]) | |||||
| |
| |||||
| |
| |||||
| | (match expr [pattern expr] ...) | |||||
| | (if expr expr expr) | |||||
| | (when expr expr) | |||||
| | (unless expr expr) | |||||
| | (and expr expr expr ...) | |||||
| | (or expr expr expr ...) | |||||
| | (time expr) | |||||
| | name | |||||
| | ’quoted | |||||
| | ‘quasiquoted | |||||
| | ’() | |||||
| | number | |||||
| | boolean | |||||
| | string | |||||
| | character | |||||
choice | = | name | ||||
| | number | |||||
pattern | = | _ | ||||
| | name | |||||
| | number | |||||
| | true | |||||
| | false | |||||
| | string | |||||
| | character | |||||
| | ’quoted | |||||
| | ‘quasiquoted-pattern | |||||
| | (cons pattern pattern) | |||||
| | (list pattern ...) | |||||
| | (list* pattern ...) | |||||
| | (struct id (pattern ...)) | |||||
| | (vector pattern ...) | |||||
| | (box pattern) | |||||
quasiquoted-pattern | = | name | ||||
| | number | |||||
| | string | |||||
| | character | |||||
| | (quasiquoted-pattern ...) | |||||
| | ’quasiquoted-pattern | |||||
| | ‘quasiquoted-pattern | |||||
| | ,pattern | |||||
| | ,@pattern | |||||
quoted | = | name | ||||
| | number | |||||
| | string | |||||
| | character | |||||
| | (quoted ...) | |||||
| | ’quoted | |||||
| | ‘quoted | |||||
| | ,quoted | |||||
| | ,@quoted | |||||
quasiquoted | = | name | ||||
| | number | |||||
| | string | |||||
| | character | |||||
| | (quasiquoted ...) | |||||
| | ’quasiquoted | |||||
| | ‘quasiquoted | |||||
| | ,expr | |||||
| | ,@expr | |||||
test-case | = | (check-expect expr expr) | ||||
| | (check-random expr expr) | |||||
| | (check-within expr expr expr) | |||||
| | (check-error expr expr ...) | |||||
| | (check-member-of expr expr expr) | |||||
| | (check-satisfied expr expr) | |||||
| | (check-range expr expr) | |||||
| | (check-range expr) | |||||
library-require | = | (require string) | ||||
| | (require (lib string string ...)) | |||||
| | (require (planet string package)) | |||||
package | = | (string string number number) |
5.1 Pre-defined Variables
5.2 Template Variables
syntax
syntax
syntax
syntax
syntax
5.3 Syntax for Advanced
In Advanced, set! can be used to mutate variables, and define-struct’s structures are mutatable. define and lambda can define functions of zero arguments, and function calls can invoke functions of zero arguments.
syntax
(lambda (variable ...) expression)
syntax
(λ (variable ...) expression)
syntax
(expression expression ...)
The function being called must come from either a definition appearing before the function call, or from a lambda expression. The number of argument expressions must be the same as the number of arguments expected by the function.
syntax
(define-datatype dataype-name [variant-name field-name ...] ...)
(define-datatype datatype-name [variant-name field-name ...] ...)
(define (datatype-name? x) (or (variant-name? x) ...)) (define-struct variant-name (field-name ...)) ...
syntax
(begin expression expression ...)
syntax
(begin0 expression expression ...)
syntax
(set! variable expression)
syntax
(delay expression)
syntax
(shared ([name expression] ...) expression)
syntax
(recur name ([name expression] ...) expression)
More precisely, the following recur:
(recur func-name ([arg-name arg-expression] ...) body-expression)
is equivalent to:
(local [(define (func-name arg-name ...) body-expression)] (func-name arg-expression ...))
syntax
(let name ([name expression] ...) expression)
syntax
(case expression [(choice ...) expression] ... [(choice ...) expression])
syntax
(match expression [pattern expression] ...)
syntax
(when test-expression body-expression)
syntax
(unless test-expression body-expression)
5.4 Common Syntaxes
The following syntaxes behave the same in the Advanced level as they did in the Intermediate Student with Lambda level.
syntax
(local [definition ...] expression)
syntax
(letrec ([name expr-for-let] ...) expression)
syntax
(let* ([name expr-for-let] ...) expression)
syntax
(let ([name expr-for-let] ...) expression)
syntax
(time expression)
syntax
(define (name variable variable ...) expression)
syntax
(define name expression)
syntax
(define-struct structure-name (field-name ...))
make-structure-name : takes a number of arguments equal to the number of fields in the structure, and creates a new instance of that structure.
structure-name-field-name : takes an instance of the structure and returns the value in the field named by field-name.
structure-name? : takes any value, and returns #true if the value is an instance of the structure.
The name of the new functions introduced by define-struct must not be the same as that of other functions or variables, otherwise define-struct reports an error.
set-structure-name-field-name! : takes an instance of the structure and a value, and mutates the instance’s field to the given value.
syntax
(cond [question-expression answer-expression] ...)
(cond [question-expression answer-expression] ... [else answer-expression])
If none of the question-expressions evaluates to #true, cond’s value is the answer-expression of the else clause. If there is no else, cond reports an error. If the result of a question-expression is neither #true nor #false, cond also reports an error.
syntax
(if test-expression then-expression else-expression)
syntax
(and expression expression expression ...)
syntax
(or expression expression expression ...)
syntax
(check-expect expression expected-expression)
(check-expect (fahrenheit->celsius 212) 100) (check-expect (fahrenheit->celsius -40) -40) (define (fahrenheit->celsius f) (* 5/9 (- f 32)))
syntax
(check-random expression expected-expression)
The form supplies the same random-number generator to both parts. If both parts request random numbers from the same interval in the same order, they receive the same random numbers.
(define WIDTH 100) (define HEIGHT (* 2 WIDTH)) (define-struct player (name x y)) ; A Player is (make-player String Nat Nat) ; String -> Player (check-random (create-randomly-placed-player "David Van Horn") (make-player "David Van Horn" (random WIDTH) (random HEIGHT))) (define (create-randomly-placed-player name) (make-player name (random WIDTH) (random HEIGHT)))
; String -> Player (check-random (create-randomly-placed-player "David Van Horn") (make-player "David Van Horn" (random WIDTH) (random HEIGHT))) (define (create-randomly-placed-player name) (local ((define h (random HEIGHT)) (define w (random WIDTH))) (make-player name w h)))
syntax
(check-satisfied expression predicate)
> (check-satisfied 1 odd?) The only test passed!
> (check-satisfied 1 even?)
Ran 1 check.
0 checks passed.
Actual value 1 does not satisfy "even?".
At line 3 column 0
; [cons Number [List-of Number]] -> Boolean ; a function for testing htdp-sort (check-expect (sorted? (list 1 2 3)) #true) (check-expect (sorted? (list 2 1 3)) #false) (define (sorted? l) (cond [(empty? (rest l)) #true] [else (and (<= (first l) (second l)) (sorted? (rest l)))])) ; [List-of Number] -> [List-of Number] ; create a sorted version of the given list of numbers (check-satisfied (htdp-sort (list 1 2 0 3)) sorted?) (define (htdp-sort l) (cond [(empty? l) l] [else (insert (first l) (htdp-sort (rest l)))])) ; Number [List-of Number] -> [List-of Number] ; insert x into l at proper place ; assume l is arranged in ascending order ; the result is sorted in the same way (define (insert x l) (cond [(empty? l) (list x)] [else (if (<= x (first l)) (cons x l) (cons (first l) (insert x (rest l))))]))
> (check-satisfied (htdp-sort (list 1 2 0 3)) sorted?)
syntax
(check-within expression expected-expression delta)
(define-struct roots (x sqrt)) ; RT is [List-of (make-roots Number Number)] (define (roots-table xs) (map (lambda (a) (make-roots a (sqrt a))) xs))
> (check-within (roots-table (list 1.0 2.0 3.0)) (list (make-roots 1.0 1.0) (make-roots 2 1.414) (make-roots 3 1.713)) 0.1) The only test passed!
> (check-within (roots-table (list 2.0)) (list (make-roots 2 1.414)) 1e-05)
Ran 1 check.
0 checks passed.
Actual value '((make-roots 2.0 1.4142135623730951)) is not within 1e-05 of expected value '((make-roots 2 1.414)).
At line 5 column 0
It is an error for expressions or expected-expression to produce a function value; see note on check-expect for details.
syntax
(check-error expression expected-error-message)
(check-error expression)
(define sample-table '(("matthias" 10) ("matthew" 20) ("robby" -1) ("shriram" 18))) ; [List-of [list String Number]] String -> Number ; determine the number associated with s in table (define (lookup table s) (cond [(empty? table) (error (string-append s " not found"))] [else (if (string=? (first (first table)) s) (second (first table)) (lookup (rest table)))]))
Consider the following two examples in this context:
> (check-expect (lookup sample-table "matthew") 20) The only test passed!
> (check-error (lookup sample-table "kathi") "kathi not found") The only test passed!
syntax
(check-member-of expression expression expression ...)
; [List-of X] -> X ; pick a random element from the given list l (define (pick-one l) (list-ref l (random (length l))))
> (check-member-of (pick-one '("a" "b" "c")) "a" "b" "c") The only test passed!
syntax
(check-range expression low-expression high-expression)
; [Real -> Real] Real -> Real ; what is the slope of f at x? (define (differentiate f x) (local ((define epsilon 0.001) (define left (- x epsilon)) (define right (+ x epsilon)) (define slope (/ (- (f right) (f left)) 2 epsilon))) slope)) (check-range (differentiate sin 0) 0.99 1.0)
syntax
(require string)
syntax
(require module-name)
syntax
(require (lib string string ...))
syntax
(require (planet string (string string number number)))
syntax
(require (planet id))
syntax
(require (planet string))
The full grammar for planet requires is given in Importing and Exporting: require and provide, but the best place to find examples of the syntax is on the the PLaneT server, in the description of a specific package.
5.5 Pre-Defined Functions
The remaining subsections list those functions that are built into the programming language. All other functions are imported from a teachpack or must be defined in the program.
5.6 Numbers: Integers, Rationals, Reals, Complex, Exacts, Inexacts
procedure
(- x y ...) → number
x : number y : number
> (- 5) -5
> (- 5 3) 2
> (- 5 3 1) 1
procedure
(< x y z ...) → boolean?
x : real y : real z : real
> (< 42 2/5) #f
procedure
(<= x y z ...) → boolean?
x : real y : real z : real
> (<= 42 2/5) #f
procedure
(= x y z ...) → boolean?
x : number y : number z : number
> (= 42 2/5) #f
procedure
(> x y z ...) → boolean?
x : real y : real z : real
> (> 42 2/5) #t
procedure
(>= x y z ...) → boolean?
x : real y : real z : real
> (>= 42 42) #t
procedure
(abs x) → real
x : real
> (abs -12) 12
procedure
(acos x) → number
x : number
> (acos 0) 1.5707963267948966
procedure
(add1 x) → number
x : number
> (add1 2) 3
procedure
(angle x) → real
x : number
> (angle (make-polar 3 4)) -2.2831853071795867
procedure
(asin x) → number
x : number
> (asin 0) 0
procedure
(atan x) → number
x : number
> (atan 0) 0
> (atan 0.5) 0.4636476090008061
> (atan 3 4) 0.6435011087932844
> (atan -2 -1) -2.0344439357957027
procedure
(ceiling x) → integer
x : real
> (ceiling 12.3) 13.0
procedure
(complex? x) → boolean?
x : any/c
> (complex? 1-2i) #t
procedure
(conjugate x) → number
x : number
> (conjugate 3+4i) 3-4i
> (conjugate -2-5i) -2+5i
> (conjugate (make-polar 3 4)) -1.960930862590836+2.2704074859237844i
procedure
(cos x) → number
x : number
> (cos pi) -1.0
procedure
(cosh x) → number
x : number
> (cosh 10) 11013.232920103324
procedure
(current-seconds) → integer
> (current-seconds) 1505247872
procedure
(denominator x) → integer
x : rational?
> (denominator 2/3) 3
value
e : real
> e 2.718281828459045
procedure
(even? x) → boolean?
x : integer
> (even? 2) #t
procedure
(exact->inexact x) → number
x : number
> (exact->inexact 12) 12.0
procedure
(exact? x) → boolean?
x : number
> (exact? (sqrt 2)) #f
procedure
(exp x) → number
x : number
> (exp -2) 0.1353352832366127
procedure
(expt x y) → number
x : number y : number
> (expt 16 1/2) 4
> (expt 3 -4) 1/81
procedure
(floor x) → integer
x : real
> (floor 12.3) 12.0
procedure
(gcd x y ...) → integer
x : integer y : integer
> (gcd 6 12 8) 2
procedure
(imag-part x) → real
x : number
> (imag-part 3+4i) 4
procedure
(inexact->exact x) → number
x : number
> (inexact->exact 12.0) 12
procedure
(inexact? x) → boolean?
x : number
> (inexact? 1-2i) #f
procedure
(integer->char x) → char
x : exact-integer?
> (integer->char 42) #\*
procedure
(integer-sqrt x) → complex
x : integer
> (integer-sqrt 11) 3
> (integer-sqrt -11) 0+3i
procedure
(integer? x) → boolean?
x : any/c
> (integer? (sqrt 2)) #f
procedure
(lcm x y ...) → integer
x : integer y : integer
> (lcm 6 12 8) 24
procedure
(log x) → number
x : number
> (log 12) 2.4849066497880004
procedure
(magnitude x) → real
x : number
> (magnitude (make-polar 3 4)) 3.0
procedure
(make-polar x y) → number
x : real y : real
> (make-polar 3 4) -1.960930862590836-2.2704074859237844i
procedure
(make-rectangular x y) → number
x : real y : real
> (make-rectangular 3 4) 3+4i
procedure
(max x y ...) → real
x : real y : real
> (max 3 2 8 7 2 9 0) 9
procedure
(min x y ...) → real
x : real y : real
> (min 3 2 8 7 2 9 0) 0
procedure
(modulo x y) → integer
x : integer y : integer
> (modulo 9 2) 1
> (modulo 3 -4) -1
procedure
(negative? x) → boolean?
x : real
> (negative? -2) #t
procedure
(number->string x) → string
x : number
> (number->string 42) "42"
procedure
(number? n) → boolean?
n : any/c
> (number? "hello world") #f
> (number? 42) #t
procedure
(numerator x) → integer
x : rational?
> (numerator 2/3) 2
procedure
(odd? x) → boolean?
x : integer
> (odd? 2) #f
value
pi : real
> pi 3.141592653589793
procedure
(positive? x) → boolean?
x : real
> (positive? -2) #f
procedure
(quotient x y) → integer
x : integer y : integer
> (quotient 9 2) 4
> (quotient 3 4) 0
procedure
(random x) → natural
x : natural
> (random) 0.7206639589038919
> (random) 0.3844039174625685
> (random 42) 0
> (random 42) 18
procedure
(rational? x) → boolean?
x : any/c
> (rational? 1) #t
> (rational? -2.349) #t
> (rational? #i1.23456789) #t
> (rational? (sqrt -1)) #f
> (rational? pi) #t
> (rational? e) #t
> (rational? 1-2i) #f
procedure
(real-part x) → real
x : number
> (real-part 3+4i) 3
procedure
(real? x) → boolean?
x : any/c
> (real? 1-2i) #f
procedure
(remainder x y) → integer
x : integer y : integer
> (remainder 9 2) 1
> (remainder 3 4) 3
procedure
(round x) → integer
x : real
> (round 12.3) 12.0
procedure
(sgn x) → (union 1 #i1.0 0 #i0.0 -1 #i-1.0)
x : real
> (sgn -12) -1
procedure
(sin x) → number
x : number
> (sin pi) 1.2246467991473532e-16
procedure
(sinh x) → number
x : number
> (sinh 10) 11013.232874703393
procedure
(sqr x) → number
x : number
> (sqr 8) 64
procedure
(sqrt x) → number
x : number
> (sqrt 9) 3
> (sqrt 2) 1.4142135623730951
procedure
(sub1 x) → number
x : number
> (sub1 2) 1
procedure
(tan x) → number
x : number
> (tan pi) -1.2246467991473532e-16
procedure
(zero? x) → boolean?
x : number
> (zero? 2) #f
5.7 Booleans
procedure
(boolean=? x y) → boolean?
x : boolean? y : boolean?
> (boolean=? #true #false) #f
procedure
(boolean? x) → boolean?
x : any/c
> (boolean? 42) #f
> (boolean? #false) #t
procedure
(false? x) → boolean?
x : any/c
> (false? #false) #t
procedure
(not x) → boolean?
x : boolean?
> (not #false) #t
5.8 Symbols
procedure
(symbol->string x) → string
x : symbol
> (symbol->string 'c) "c"
procedure
(symbol=? x y) → boolean?
x : symbol y : symbol
> (symbol=? 'a 'b) #f
procedure
(symbol? x) → boolean?
x : any/c
> (symbol? 'a) #t
5.9 Lists
procedure
(append l ...) → (listof any)
l : (listof any)
procedure
(assoc x l) → (union (listof any) #false)
x : any l : (listof any)
> (assoc "hello" '(("world" 2) ("hello" 3) ("good" 0))) ("hello" 3)
procedure
(assq x l) → (union #false cons?)
x : any/c l : list?
> a ((a 22) (b 8) (c 70))
> (assq 'b a) (b 8)
procedure
(caaar x) → any/c
x : list?
> w (((("bye") 3) #t) 42)
> (caaar w) ("bye")
procedure
(caadr x) → any/c
x : list?
> (caadr (cons 1 (cons (cons 'a '()) (cons (cons 'd '()) '())))) a
procedure
(caar x) → any/c
x : list?
> y (((1 2 3) #f "world"))
> (caar y) (1 2 3)
procedure
(cadar x) → any/c
x : list?
> w (((("bye") 3) #t) 42)
> (cadar w) #t
procedure
(cadddr x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (cadddr v) 4
procedure
(caddr x) → any/c
x : list?
> x (2 "hello" #t)
> (caddr x) #t
procedure
(cadr x) → any/c
x : list?
> x (2 "hello" #t)
> (cadr x) "hello"
procedure
(car x) → any/c
x : cons?
> x (2 "hello" #t)
> (car x) 2
procedure
(cdaar x) → any/c
x : list?
> w (((("bye") 3) #t) 42)
> (cdaar w) (3)
procedure
(cdadr x) → any/c
x : list?
> z (2 "hello" #t "hello")
> (cdadr z) cdadr: contract violation
expected: (cons/c any/c (cons/c pair? any/c))
given: (2 "hello" #t "hello")
procedure
(cdar x) → list?
x : list?
> y (((1 2 3) #f "world"))
> (cdar y) (#f "world")
procedure
(cddar x) → any/c
x : list?
> w (((("bye") 3) #t) 42)
> (cddar w) ()
procedure
(cdddr x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (cdddr v) (4 5 6 7 8 9 A)
procedure
(cddr x) → list?
x : list?
> x (2 "hello" #t)
> (cddr x) (#t)
procedure
(cdr x) → any/c
x : cons?
> x (2 "hello" #t)
> (cdr x) ("hello" #t)
procedure
(cons x l) → (listof X)
x : X l : (listof X)
procedure
(cons? x) → boolean?
x : any/c
> (cons? (cons 1 '())) #t
> (cons? 42) #f
procedure
(eighth x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (eighth v) 8
procedure
(empty? x) → boolean?
x : any/c
> (empty? '()) #t
> (empty? 42) #f
procedure
(fifth x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (fifth v) 5
procedure
(first x) → any/c
x : cons?
> x (2 "hello" #t)
> (first x) 2
procedure
(fourth x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (fourth v) 4
procedure
(length l) → natural-number?
l : list?
> x (2 "hello" #t)
> (length x) 3
procedure
(list x ...) → list?
x : any/c
> (list 1 2 3 4 5 6 7 8 9 0) (1 2 3 4 5 6 7 8 9 0)
procedure
(list* x ... l) → (listof any)
x : any l : (listof any)
procedure
(list-ref x i) → any/c
x : list? i : natural?
> v (1 2 3 4 5 6 7 8 9 A)
> (list-ref v 9) A
procedure
(list? x) → boolean?
x : any
> (list? 42) #f
> (list? '()) #t
> (list? (cons 1 (cons 2 '()))) #t
procedure
(make-list i x) → list?
i : natural-number x : any/c
> (make-list 3 "hello") ("hello" "hello" "hello")
procedure
(member x l) → boolean?
x : any/c l : list?
> x (2 "hello" #t)
> (member "hello" x) #t
procedure
(member? x l) → boolean?
x : any/c l : list?
> x (2 "hello" #t)
> (member? "hello" x) #t
procedure
(memq x l) → boolean?
x : any/c l : list?
> x (2 "hello" #t)
> (memq (list (list 1 2 3)) x) #f
procedure
(memq? x l) → boolean?
x : any/c l : list?
> x (2 "hello" #t)
> (memq? (list (list 1 2 3)) x) #f
procedure
(memv x l) → (or/c #false list)
x : any/c l : list?
> x (2 "hello" #t)
> (memv (list (list 1 2 3)) x) #f
value
null : list
> null ()
procedure
(null? x) → boolean?
x : any/c
> (null? '()) #t
> (null? 42) #f
procedure
(range start end step) → list?
start : number end : number step : number
> (range 0 10 2) (0 2 4 6 8)
procedure
(remove x l) → list?
x : any/c l : list?
> x (2 "hello" #t)
> (remove "hello" x) (2 #t)
> z (2 "hello" #t "hello")
> (remove "hello" z) (2 #t "hello")
procedure
(remove-all x l) → list?
x : any/c l : list?
> x (2 "hello" #t)
> (remove-all "hello" x) (2 #t)
> z (2 "hello" #t "hello")
> (remove-all "hello" z) (2 #t)
procedure
(rest x) → any/c
x : cons?
> x (2 "hello" #t)
> (rest x) ("hello" #t)
procedure
(reverse l) → list
l : list?
> x (2 "hello" #t)
> (reverse x) (#t "hello" 2)
procedure
(second x) → any/c
x : list?
> x (2 "hello" #t)
> (second x) "hello"
procedure
(seventh x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (seventh v) 7
procedure
(sixth x) → any/c
x : list?
> v (1 2 3 4 5 6 7 8 9 A)
> (sixth v) 6
procedure
(third x) → any/c
x : list?
> x (2 "hello" #t)
> (third x) #t
5.10 Posns
procedure
(make-posn x y) → posn
x : any/c y : any/c
> (make-posn 3 3) #(struct:posn 3 3)
> (make-posn "hello" #true) #(struct:posn "hello" #t)
procedure
(posn-x p) → any
p : posn
> p #(struct:posn 2 -3)
> (posn-x p) 2
procedure
(posn-y p) → any
p : posn
> p #(struct:posn 2 -3)
> (posn-y p) -3
procedure
(posn? x) → boolean?
x : any/c
> q #(struct:posn "bye" 2)
> (posn? q) #t
> (posn? 42) #f
procedure
(set-posn-x! p x) → void?
p : posn x : any
> p #(struct:posn 2 -3)
> (set-posn-x! p 678) > p #(struct:posn 678 -3)
procedure
(set-posn-y! p x) → void
p : posn x : any
> q #(struct:posn "bye" 2)
> (set-posn-y! q 678) > q #(struct:posn "bye" 678)
5.11 Characters
procedure
(char->integer c) → integer
c : char
> (char->integer #\a) 97
> (char->integer #\z) 122
procedure
(char-alphabetic? c) → boolean?
c : char
> (char-alphabetic? #\Q) #t
procedure
(char-ci<=? c d e ...) → boolean?
c : char d : char e : char
> (char-ci<=? #\b #\B) #t
> (char<=? #\b #\B) #f
procedure
(char-ci<? c d e ...) → boolean?
c : char d : char e : char
> (char-ci<? #\B #\c) #t
> (char<? #\b #\B) #f
procedure
(char-ci=? c d e ...) → boolean?
c : char d : char e : char
> (char-ci=? #\b #\B) #t
procedure
(char-ci>=? c d e ...) → boolean?
c : char d : char e : char
> (char-ci>=? #\b #\C) #f
> (char>=? #\b #\C) #t
procedure
(char-ci>? c d e ...) → boolean?
c : char d : char e : char
> (char-ci>? #\b #\B) #f
> (char>? #\b #\B) #t
procedure
(char-downcase c) → char
c : char
> (char-downcase #\T) #\t
procedure
(char-lower-case? c) → boolean?
c : char
> (char-lower-case? #\T) #f
procedure
(char-numeric? c) → boolean?
c : char
> (char-numeric? #\9) #t
procedure
(char-upcase c) → char
c : char
> (char-upcase #\t) #\T
procedure
(char-upper-case? c) → boolean?
c : char
> (char-upper-case? #\T) #t
procedure
(char-whitespace? c) → boolean?
c : char
> (char-whitespace? #\tab) #t
procedure
(char<=? c d e ...) → boolean?
c : char d : char e : char
> (char<=? #\a #\a #\b) #t
procedure
(char<? x d e ...) → boolean?
x : char d : char e : char
> (char<? #\a #\b #\c) #t
procedure
(char=? c d e ...) → boolean?
c : char d : char e : char
> (char=? #\b #\a) #f
procedure
(char>=? c d e ...) → boolean?
c : char d : char e : char
> (char>=? #\b #\b #\a) #t
procedure
(char>? c d e ...) → boolean?
c : char d : char e : char
> (char>? #\A #\z #\a) #f
procedure
(char? x) → boolean?
x : any/c
> (char? "a") #f
> (char? #\a) #t
5.12 Strings
procedure
(explode s) → (listof string)
s : string
> (explode "cat") ("c" "a" "t")
procedure
(format f x ...) → string
f : string x : any/c
> (format "Dear Dr. ~a:" "Flatt") "Dear Dr. Flatt:"
> (format "Dear Dr. ~s:" "Flatt") "Dear Dr. \"Flatt\":"
> (format "the value of ~s is ~a" '(+ 1 1) (+ 1 1)) "the value of (+ 1 1) is 2"
procedure
(implode l) → string
l : list?
> (implode (cons "c" (cons "a" (cons "t" '())))) "cat"
procedure
(int->string i) → string
i : integer
> (int->string 65) "A"
procedure
(list->string l) → string
l : list?
> (list->string (cons #\c (cons #\a (cons #\t '())))) "cat"
procedure
(make-string i c) → string
i : natural-number c : char
> (make-string 3 #\d) "ddd"
procedure
(replicate i s) → string
i : natural-number s : string
> (replicate 3 "h") "hhh"
procedure
(string c ...) → string?
c : char
> (string #\d #\o #\g) "dog"
procedure
(string->int s) → integer
s : string
> (string->int "a") 97
procedure
(string->list s) → (listof char)
s : string
> (string->list "hello") (#\h #\e #\l #\l #\o)
procedure
(string->number s) → (union number #false)
s : string
> (string->number "-2.03") -2.03
> (string->number "1-2i") 1-2i
procedure
(string->symbol s) → symbol
s : string
> (string->symbol "hello") hello
procedure
(string-alphabetic? s) → boolean?
s : string
> (string-alphabetic? "123") #f
> (string-alphabetic? "cat") #t
procedure
(string-append s ...) → string
s : string
> (string-append "hello" " " "world" " " "good bye") "hello world good bye"
procedure
(string-ci<=? s t x ...) → boolean?
s : string t : string x : string
> (string-ci<=? "hello" "WORLD" "zoo") #t
procedure
(string-ci<? s t x ...) → boolean?
s : string t : string x : string
> (string-ci<? "hello" "WORLD" "zoo") #t
procedure
(string-ci=? s t x ...) → boolean?
s : string t : string x : string
> (string-ci=? "hello" "HellO") #t
procedure
(string-ci>=? s t x ...) → boolean?
s : string t : string x : string
> (string-ci>? "zoo" "WORLD" "hello") #t
procedure
(string-ci>? s t x ...) → boolean?
s : string t : string x : string
> (string-ci>? "zoo" "WORLD" "hello") #t
procedure
(string-contains? s t) → boolean?
s : string t : string
> (string-contains? "at" "cat") #t
procedure
(string-copy s) → string
s : string
> (string-copy "hello") "hello"
procedure
(string-ith s i) → 1string?
s : string i : natural-number
> (string-ith "hello world" 1) "e"
procedure
(string-length s) → nat
s : string
> (string-length "hello world") 11
procedure
(string-lower-case? s) → boolean?
s : string
> (string-lower-case? "CAT") #f
procedure
(string-numeric? s) → boolean?
s : string
> (string-numeric? "123") #t
> (string-numeric? "1-2i") #f
procedure
(string-ref s i) → char
s : string i : natural-number
> (string-ref "cat" 2) #\t
procedure
(string-upper-case? s) → boolean?
s : string
> (string-upper-case? "CAT") #t
procedure
(string-whitespace? s) → boolean?
s : string
> (string-whitespace? (string-append " " (string #\tab #\newline #\return))) #t
procedure
(string<=? s t x ...) → boolean?
s : string t : string x : string
> (string<=? "hello" "hello" "world" "zoo") #t
procedure
(string<? s t x ...) → boolean?
s : string t : string x : string
> (string<? "hello" "world" "zoo") #t
procedure
(string=? s t x ...) → boolean?
s : string t : string x : string
> (string=? "hello" "world") #f
> (string=? "bye" "bye") #t
procedure
(string>=? s t x ...) → boolean?
s : string t : string x : string
> (string>=? "zoo" "zoo" "world" "hello") #t
procedure
(string>? s t x ...) → boolean?
s : string t : string x : string
> (string>? "zoo" "world" "hello") #t
procedure
(string? x) → boolean?
x : any/c
> (string? "hello world") #t
> (string? 42) #f
procedure
(substring s i j) → string
s : string i : natural-number j : natural-number
> (substring "hello world" 1 5) "ello"
> (substring "hello world" 4) "o world"
5.13 Images
procedure
(image=? i j) → boolean?
i : image j : image
> c1 > (image=? (circle 5 "solid" "green") c1) #f
> (image=? (circle 10 "solid" "green") c1) #t
procedure
(image? x) → boolean?
x : any/c
> c1 > (image? c1) #t
5.14 Misc
procedure
(=~ x y z) → boolean?
x : number y : number z : non-negative-real
> (=~ 1.01 1.0 0.1) #t
> (=~ 1.01 1.5 0.1) #f
procedure
(current-milliseconds) → exact-integer
> (current-milliseconds) 1505247870073
value
eof : eof-object?
> eof #<eof>
procedure
(eof-object? x) → boolean?
x : any/c
> (eof-object? eof) #t
> (eof-object? 42) #f
procedure
(eq? x y) → boolean?
x : any/c y : any/c
> (eq? (cons 1 '()) (cons 1 '())) #f
> one (1)
> (eq? one one) #t
procedure
(equal? x y) → boolean?
x : any/c y : any/c
> (equal? (make-posn 1 2) (make-posn (- 2 1) (+ 1 1))) #t
procedure
(equal~? x y z) → boolean?
x : any/c y : any/c z : non-negative-real
> (equal~? (make-posn 1.01 1.0) (make-posn 1.01 0.99) 0.2) #t
procedure
(eqv? x y) → boolean?
x : any/c y : any/c
> (eqv? (cons 1 '()) (cons 1 '())) #f
> one (1)
> (eqv? one one) #t
procedure
(error x ...) → void?
x : any/c
> zero 0
> (if (= zero 0) (error "can't divide by 0") (/ 1 zero)) can't divide by 0
procedure
(exit) → void
procedure
(force v) → any
v : any
procedure
(gensym) → symbol?
> (gensym) g16561
procedure
(identity x) → any
x : any/c
> (identity 42) 42
> (identity c1) > (identity "hello") "hello"
procedure
(promise? x) → boolean?
x : any
procedure
(sleep sec) → void
sec : positive-num
procedure
(struct? x) → boolean?
x : any/c
> (struct? (make-posn 1 2)) #t
> (struct? 43) #f
procedure
(void) → void?
> (void)
procedure
(void? x) → boolean?
x : any
> (void? (void)) #t
> (void? 42) #f
5.15 Numbers (relaxed conditions)
procedure
(* x ...) → number
x : number
> (* 5 3) 15
> (* 5 3 2) 30
> (* 2) 2
> (*) 1
procedure
(+ x ...) → number
x : number
> (+ 2/3 1/16) 35/48
> (+ 3 2 5 8) 18
> (+ 1) 1
> (+) 0
procedure
(/ x y ...) → number
x : number y : number
> (/ 12 2) 6
> (/ 12 2 3) 2
> (/ 3) 1/3
5.16 Posn
procedure
(posn) → signature
5.17 Higher-Order Functions
procedure
(andmap p? [l]) → boolean
p? : (X ... -> boolean) l : (listof X) = ...
(andmap p (list x-1 ... x-n)) = (and (p x-1) ... (p x-n))
(andmap p (list x-1 ... x-n) (list y-1 ... y-n)) = (and (p x-1 y-1) ... (p x-n y-n))
> (andmap odd? '(1 3 5 7 9)) #t
> threshold 3
> (andmap (lambda (x) (< x threshold)) '(0 1 2)) #t
> (andmap even? '()) #t
> (andmap (lambda (x f) (f x)) (list 0 1 2) (list odd? even? positive?)) #f
procedure
(apply f x-1 ... l) → Y
f : (X-1 ... X-N -> Y) x-1 : X-1 l : (list X-i+1 ... X-N)
(apply f (list x-1 ... x-n)) = (f x-1 ... x-n)
> a-list (0 1 2 3 4 5 6 7 8 9)
> (apply max a-list) 9
procedure
(argmax f l) → X
f : (X -> real) l : (listof X)
> (argmax second '((sam 98) (carl 78) (vincent 93) (asumu 99))) (asumu 99)
procedure
(argmin f l) → X
f : (X -> real) l : (listof X)
> (argmin second '((sam 98) (carl 78) (vincent 93) (asumu 99))) (carl 78)
procedure
(build-list n f) → (listof X)
n : nat f : (nat -> X)
(build-list n f) = (list (f 0) ... (f (- n 1)))
> (build-list 22 add1) (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22)
> i 3
> (build-list 3 (lambda (j) (+ j i))) (3 4 5)
> (build-list 5 (lambda (i) (build-list 5 (lambda (j) (if (= i j) 1 0))))) ((1 0 0 0 0) (0 1 0 0 0) (0 0 1 0 0) (0 0 0 1 0) (0 0 0 0 1))
procedure
(build-string n f) → string
n : nat f : (nat -> char)
(build-string n f) = (string (f 0) ... (f (- n 1)))
> (build-string 10 integer->char) "\u0000\u0001\u0002\u0003\u0004\u0005\u0006\a\b\t"
> (build-string 26 (lambda (x) (integer->char (+ 65 x)))) "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
procedure
(compose f g) → (X -> Z)
f : (Y -> Z) g : (X -> Y)
(compose f g) = (lambda (x) (f (g x)))
> ((compose add1 second) '(add 3)) 4
> (map (compose add1 second) '((add 3) (sub 2) (mul 4))) (4 3 5)
procedure
(filter p? l) → (listof X)
p? : (X -> boolean) l : (listof X)
> (filter odd? '(0 1 2 3 4 5 6 7 8 9)) (1 3 5 7 9)
> threshold 3
> (filter (lambda (x) (>= x threshold)) '(0 1 2 3 4 5 6 7 8 9)) (3 4 5 6 7 8 9)
procedure
(foldl f base l ...) → Y
f : (X ... Y -> Y) base : Y l : (listof X)
(foldl f base (list x-1 ... x-n)) = (f x-n ... (f x-1 base))
(foldl f base (list x-1 ... x-n) (list x-1 ... x-n)) = (f x-n y-n ... (f x-1 y-1 base))
> (foldl + 0 '(0 1 2 3 4 5 6 7 8 9)) 45
> a-list (0 1 2 3 4 5 6 7 8 9)
> (foldl (lambda (x r) (if (> x threshold) (cons (* 2 x) r) r)) '() a-list) (18 16 14 12 10 8)
> (foldl (lambda (x y r) (+ x y r)) 0 '(1 2 3) '(10 11 12)) 39
procedure
(foldr f base l ...) → Y
f : (X ... Y -> Y) base : Y l : (listof X)
(foldr f base (list x-1 ... x-n)) = (f x-1 ... (f x-n base))
(foldr f base (list x-1 ... x-n) (list y-1 ... y-n)) = (f x-1 y-1 ... (f x-n y-n base))
> (foldr + 0 '(0 1 2 3 4 5 6 7 8 9)) 45
> a-list (0 1 2 3 4 5 6 7 8 9)
> (foldr (lambda (x r) (if (> x threshold) (cons (* 2 x) r) r)) '() a-list) (8 10 12 14 16 18)
> (foldr (lambda (x y r) (+ x y r)) 0 '(1 2 3) '(10 11 12)) 39
procedure
(for-each f l ...) → void?
f : (any ... -> any) l : (listof any)
(for-each f (list x-1 ... x-n)) = (begin (f x-1) ... (f x-n))
> (for-each (lambda (x) (begin (display x) (newline))) '(1 2 3))
1
2
3
procedure
(map f l ...) → (listof Z)
f : (X ... -> Z) l : (listof X)
(map f (list x-1 ... x-n)) = (list (f x-1) ... (f x-n))
(map f (list x-1 ... x-n) (list y-1 ... y-n)) = (list (f x-1 y-1) ... (f x-n y-n))
> (map add1 '(3 -4.01 2/5)) (4 -3.01 7/5)
> (map (lambda (x) (list 'my-list (+ x 1))) '(3 -4.01 2/5)) ((my-list 4) (my-list -3.01) (my-list 7/5))
> (map (lambda (x y) (+ x (* x y))) '(3 -4 2/5) '(1 2 3)) (6 -12 8/5)
procedure
(memf p? l) → (union #false (listof X))
p? : (X -> any) l : (listof X)
> (memf odd? '(2 4 6 3 8 0)) (3 8 0)
procedure
(ormap p? l) → boolean
p? : (X -> boolean) l : (listof X)
(ormap p (list x-1 ... x-n)) = (or (p x-1) ... (p x-n))
(ormap p (list x-1 ... x-n) (list y-1 ... y-n)) = (or (p x-1 y-1) ... (p x-n y-n))
> (ormap odd? '(1 3 5 7 9)) #t
> threshold 3
> (ormap (lambda (x) (< x threshold)) '(6 7 8 1 5)) #t
> (ormap even? '()) #f
> (ormap (lambda (x f) (f x)) (list 0 1 2) (list odd? even? positive?)) #t
procedure
(procedure? x) → boolean?
x : any
> (procedure? cons) #t
> (procedure? add1) #t
> (procedure? (lambda (x) (> x 22))) #t
procedure
(quicksort l comp) → (listof X)
l : (listof X) comp : (X X -> boolean)
> (quicksort '(6 7 2 1 3 4 0 5 9 8) <) (0 1 2 3 4 5 6 7 8 9)
procedure
(sort l comp) → (listof X)
l : (listof X) comp : (X X -> boolean)
> (sort '(6 7 2 1 3 4 0 5 9 8) <) (0 1 2 3 4 5 6 7 8 9)
5.18 Reading and Printing
procedure
(display x) → void
x : any
> (display 10) 10
> (display "hello") hello
> (display 'hello) hello
procedure
(newline) → void
procedure
(pretty-print x) → void
x : any
> (pretty-print '((1 2 3) ((a) ("hello world" #true) (((false "good bye")))))) ((1 2 3) ((a) ("hello world" #t) (((false "good bye")))))
> (pretty-print (build-list 10 (lambda (i) (build-list 10 (lambda (j) (= i j))))))
((#t #f #f #f #f #f #f #f #f #f)
(#f #t #f #f #f #f #f #f #f #f)
(#f #f #t #f #f #f #f #f #f #f)
(#f #f #f #t #f #f #f #f #f #f)
(#f #f #f #f #t #f #f #f #f #f)
(#f #f #f #f #f #t #f #f #f #f)
(#f #f #f #f #f #f #t #f #f #f)
(#f #f #f #f #f #f #f #t #f #f)
(#f #f #f #f #f #f #f #f #t #f)
(#f #f #f #f #f #f #f #f #f #t))
procedure
(print x) → void
x : any
> (print 10) 10
> (print "hello") "hello"
> (print 'hello) hello
procedure
(printf f x ...) → void
f : string x : any
procedure
(read) → sexp
procedure
(with-input-from-file f p) → any
f : string p : (-> any)
procedure
(with-input-from-string s p) → any
s : string p : (-> any)
> (with-input-from-string "hello" read) hello
> (string-length (symbol->string (with-input-from-string "hello" read))) 5
procedure
(with-output-to-file f p) → any
f : string p : (-> any)
procedure
(with-output-to-string p) → any
p : (-> any)
> (with-output-to-string (lambda () (display 10))) "10"
procedure
(write x) → void
x : any
> (write 10) 10
> (write "hello") "hello"
> (write 'hello) hello
5.19 Vectors
procedure
(build-vector n f) → (vectorof X)
n : nat f : (nat -> X)
> (build-vector 5 add1) #(1 2 3 4 5)
procedure
(list->vector l) → (vectorof X)
l : (listof X)
> (list->vector (list "hello" "world" "good" "bye")) #("hello" "world" "good" "bye")
procedure
(make-vector n x) → (vectorof X)
n : number x : X
> (make-vector 5 0) #(0 0 0 0 0)
procedure
(vector x ...) → (vector X ...)
x : X
> (vector 1 2 3 -1 -2 -3) #(1 2 3 -1 -2 -3)
procedure
(vector->list v) → (listof X)
v : (vectorof X)
> (vector->list (vector 'a 'b 'c)) (a b c)
procedure
(vector-length v) → nat
v : (vector X)
> v #("a" "b" "c" "d" "e")
> (vector-length v) 5
procedure
(vector-ref v n) → X
v : (vector X) n : nat
> v #("a" "b" "c" "d" "e")
> (vector-ref v 3) "d"
procedure
(vector-set! v n x) → void
v : (vectorof X) n : nat x : X
> v #("a" "b" "c" "d" "e")
> (vector-set! v 3 77) > v #("a" "b" "c" 77 "e")
procedure
(vector? x) → boolean
x : any
> v #("a" "b" "c" 77 "e")
> (vector? v) #t
> (vector? 42) #f
5.20 Boxes
procedure
(box x) → box?
x : any/c
> (box 42) #&42
procedure
(box? x) → boolean?
x : any/c
> b #&33
> (box? b) #t
> (box? 42) #f
procedure
(set-box! b x) → void
b : box? x : any/c
> b #&33
> (set-box! b 31) > b #&31
procedure
(unbox b) → any
b : box?
> b #&31
> (unbox b) 31
5.21 Hash Tables
procedure
(hash-copy h) → hash
h : hash
procedure
(hash-count h) → integer
h : hash
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-count ish) 4
procedure
(hash-eq? h) → boolean
h : hash
> hsh #hash((b . 69) (c . 42) (e . 61) (r . 999))
> (hash-eq? hsh) #f
> heq #hasheq((b . 69) (c . 42) (e . 61) (r . 999))
> (hash-eq? heq) #t
procedure
(hash-equal? h) → boolean
h : hash?
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-equal? ish) #t
> ieq #hasheq((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-equal? ieq) #f
procedure
(hash-eqv? h) → boolean
h : hash
> heq #hasheq((b . 69) (c . 42) (e . 61) (r . 999))
> (hash-eqv? heq) #f
> heqv #hasheqv((b . 69) (c . 42) (e . 61) (r . 999))
> (hash-eqv? heqv) #t
procedure
(hash-for-each h f) → void?
h : (hash X Y) f : (X Y -> any)
> hsh #hash((b . 69) (c . 42) (e . 61) (r . 999))
> (hash-for-each hsh (lambda (ky vl) (hash-set! hsh ky (+ vl 1)))) > hsh #hash((b . 70) (c . 43) (e . 62) (r . 1000))
procedure
(hash-has-key? h x) → boolean
h : (hash X Y) x : X
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-has-key? ish 'b) #t
> hsh #hash((b . 70) (c . 43) (e . 62) (r . 1000))
> (hash-has-key? hsh 'd) #f
procedure
(hash-map h f) → (listof Z)
h : (hash X Y) f : (X Y -> Z)
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-map ish list) ((e 61) (r 999) (c 42) (b 69))
procedure
(hash-ref h k) → Y
h : (hash X Y) k : X
> hsh #hash((b . 70) (c . 43) (e . 62) (r . 1000))
> (hash-ref hsh 'b) 70
procedure
(hash-ref! h k v) → Y
h : (hash X Y) k : X v : Y
> hsh #hash((b . 70) (c . 43) (e . 62) (r . 1000))
> (hash-ref! hsh 'd 99) 99
> hsh #hash((b . 70) (c . 43) (d . 99) (e . 62) (r . 1000))
procedure
(hash-remove h k) → (hash X Y)
h : (hash X Y) k : X
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash-remove ish 'b) #hash((e . 61) (r . 999) (c . 42))
procedure
(hash-remove! h x) → void
h : (hash X Y) x : X
> hsh #hash((b . 70) (c . 43) (d . 99) (e . 62) (r . 1000))
> (hash-remove! hsh 'r) > hsh #hash((b . 70) (c . 43) (d . 99) (e . 62))
procedure
(hash-set h k v) → (hash X Y)
h : (hash X Y) k : X v : Y
> (hash-set ish 'a 23) #hash((a . 23) (e . 61) (r . 999) (c . 42) (b . 69))
procedure
(hash-set! h k v) → void?
h : (hash X Y) k : X v : Y
> hsh #hash((b . 70) (c . 43) (d . 99) (e . 62))
> (hash-set! hsh 'a 23) > hsh #hash((b . 70) (c . 43) (d . 99) (e . 62) (a . 23))
procedure
(hash-update h k f) → (hash X Y)
h : (hash X Y) k : X f : (Y -> Y)
> (hash-update ish 'b (lambda (old-b) (+ old-b 1))) #hash((e . 61) (r . 999) (c . 42) (b . 70))
procedure
(hash-update! h k f) → void?
h : (hash X Y) k : X f : (Y -> Y)
> hsh #hash((b . 70) (c . 43) (d . 99) (e . 62) (a . 23))
> (hash-update! hsh 'b (lambda (old-b) (+ old-b 1))) > hsh #hash((b . 71) (c . 43) (d . 99) (e . 62) (a . 23))
procedure
(hash? x) → boolean
x : any
> ish #hash((e . 61) (r . 999) (c . 42) (b . 69))
> (hash? ish) #t
> (hash? 42) #f
procedure
(make-hash) → (hash X Y)
> (make-hash) #hash()
> (make-hash '((b 69) (e 61) (i 999))) #hash((b . 69) (e . 61) (i . 999))
procedure
(make-hasheq) → (hash X Y)
> (make-hasheq) #hasheq()
> (make-hasheq '((b 69) (e 61) (i 999))) #hasheq((b . 69) (e . 61) (i . 999))
procedure
(make-hasheqv) → (hash X Y)
> (make-hasheqv) #hasheqv()
> (make-hasheqv '((b 69) (e 61) (i 999))) #hasheqv((b . 69) (e . 61) (i . 999))
procedure
(make-immutable-hash) → (hash X Y)
> (make-immutable-hash) #hash()
> (make-immutable-hash '((b 69) (e 61) (i 999))) #hash((e . 61) (i . 999) (b . 69))
procedure
(make-immutable-hasheq) → (hash X Y)
> (make-immutable-hasheq) #hasheq()
> (make-immutable-hasheq '((b 69) (e 61) (i 999))) #hasheq((e . 61) (i . 999) (b . 69))
procedure
(make-immutable-hasheqv) → (hash X Y)
> (make-immutable-hasheqv) #hasheqv()
> (make-immutable-hasheqv '((b 69) (e 61) (i 999))) #hasheqv((e . 61) (i . 999) (b . 69))