> I'm trying to use arbno for the questions on the let extensions
> (chapter 3). However, the behaviour of "arbno" is nowhere specified in
> the book, and I also didn't find the code for it. For example, how can
> a value be extracted from an arbno?
Here is an example to show how an arbitrary number of things are > (chapter 3). However, the behaviour of "arbno" is nowhere specified in
> the book, and I also didn't find the code for it. For example, how can
> a value be extracted from an arbno?
specified in the grammar using arbno,
specified in the datatype using list-of,
parsed,
extracted as lists.
; <expression> := <number>
; := <identifier>
; := let { <identifier = <expression> }* in <expression>
(define scanner
'((white-sp (whitespace) skip)
(number (digit (arbno digit)) number)
(identifier (letter (arbno (or letter digit "?"))) symbol)))
(define grammar
'((expression (number) lit-exp) (define grammar
(expression (identifier) var-exp)
(expression ("let" (arbno identifier "=" expression) "in"
expression) let-exp)))
(sllgen:list-define-datatypes scanner grammar) expression) let-exp)))
((define-datatype
expression
expression?
(lit-exp (lit-exp1 number?))
(var-exp (var-exp2 symbol?))
(let-exp (let-exp3 (list-of symbol?)) (let-exp4 (list-of
expression?)) (let-exp5 expression?))))
(sllgen:make-define-datatypes scanner grammar)
(define scan-parse (sllgen:make-string-parser scanner grammar))
(define sp (sllgen:make-string-parser scanner grammar))
(define exp (sp "let x = 1 y = 2 z = 3 in x"))
(cases expression exp
(lit-exp (datum) datum)
(var-exp (id) id)
(let-exp (ids rands body) ids))
;=> (x y z)
(cases expression exp
(lit-exp (datum) datum)
(var-exp (id) id)
(let-exp (ids rands body) rands))
;=> (#<struct:lit-exp> #<struct:lit-exp> #<struct:lit-exp>)
;----------
; a peek inside the Scheme implementation
(require (only mzscheme print-struct))
(print-struct #t)
exp
;=> #(struct:let-exp (x y z) (#(struct:lit-exp 1) #(struct:lit-exp 2)
#(struct:lit-exp 3)) #(struct:var-exp x))
(cases expression exp
(lit-exp (datum) datum)
(var-exp (id) id)
(let-exp (ids rands body) rands))
;=> (#(struct:lit-exp 1) #(struct:lit-exp 2) #(struct:lit-exp 3))