next up previous contents
Next: 6. QScheme procedures Up: QScheme Documentation Previous: 4. Ignore this   Contents

Subsections

5. Expressions

5.1 Primitive expressions types

(quote (datum)) -> <list> 
'(datum) -> <list>

(operator operand1 ...) -> <object>

(lambda formals body) -> <procedure>
(define (name arg ...) body) -> #undefined

(define variable expr) -> #undefined 
(set! variable expr) -> #undefined

(if test when-true when-false) -> <object> 
(if test when-true) -> <object>

(while test body) -> <object>

(begin expr ...) -> <object>

See R5RS.

QScheme make a strong distinction between define and set!. define creates a new symbol in the current environment and binds a value to it, set! does not create any symbol. Setting a value to an undefined symbol will cause an error. This distinction is needed especially for the external variable. There, you have to use define to create a new symbol and bind the symbol to the external variable location and set! to assign a new value to the external variable. Example:

(define testvar-b (extern-var *lib* "extern-char"  "testvar_b"))

testvar-b

=> 10

(set! testvar-b 20) testvar-b

=> 20

In this case, the define variable testvar-b is bounded to an external variable object. References to this variable will return the value of the object, not the binding. Set! will modify the value of the external variable, not the binding. This should be compatible with the R5RS specs.

5.2 Derived expressions

(cond clause1 clause2 ...) -> <object>  
(and test1 ...) -> <object>  
(or test1 ... ) -> <object>

See R5RS.

(case key clause1 clause2 ...) -> <object>

Not implemented yet

(let binding body) -> <object>  
(let* binding body) -> <object>  
(letrec binding body) -> <object>

See R5RS.

(begin expr1 expr2 ...) -> <object>

See R5RS.

(do ((var1 init1 step1 ) ... ) (test expr ... ) command ...) -> <object>
(let var bindings body) -> <object>

Not implemented yet

(delay expr) -> <object>

Not implemented yet.

(quasiquote (template)) -> <object>

`(template)) -> <object>

See R5RS

5.3 QScheme extensions

QScheme introduce a new form of lambda and define syntax:

(lambda (formal [:opt var ] [:local local-vars])body) -> <procedure>

(define (func formal [:opt var ] [:local local-vars])body) -> #undefined

The formal parameters are just like in standard Scheme. The optional part ':opt var' can be used to an optional variable and the ':local local-vars' part is used to create local variables. For example:

(lambda (x y :opt z) ...) is equivalent to (lambda (x y . z) ...)

and

(lambda (x y :opt a b)...) is equivalent to (lambda (x y) (let ((a) (b)) ...)

The define special form also uses the same convention, so you should be able to say:

(define (tst x y :local sum) (set! sum (+ x y)) sum)

(tst 10 20)

=> 30


next up previous contents
Next: 6. QScheme procedures Up: QScheme Documentation Previous: 4. Ignore this   Contents
Daniel Crettol
1999-09-01