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

Subsections


5 QScheme extensions and deviations

5.1 Comments

QScheme accepts the standard ';' character as standard comment marker. Anything following the ';' character on the line is ignored.

QScheme also reconizes '#!' followed by anything except a letter as comment. For example:

#! This is a valid comment

#!/this also

#!This not

This extension is used to permit QScheme scripting.

5.2 Case sensitivity

QScheme is case sensitive: define is not the same as DEFINE. Generally this should not be a problem. At a certain level, QScheme has to be case sensitive - when referencing entities defined in external libraries, for instance. It is for this reason that I chose to make QScheme globally case sensitive. If this causes too much trouble, contact me. It should be possible to write a compatibility mode.


5.3 Keywords

QScheme recognizes the following tokens as valid keywords:

These different spellings all represent the same keyword.

> (eq? :ake #!ake)  
#t
By default, keywords are printed out in the first form. You can change this with the keyword-display-type function.

(keyword-display-type n) -> n
Change the way keywords are displayed. For example:

> (keyword-display-type 0) :ake

> :ake

> (keyword-display-type 1) :ake

> #!ake

> (keyword-display-type 2) :ake

> ake:

5.4 lambda and define syntax

QScheme introduce a new form of the lambda and define syntax:

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

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

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

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

and

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

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

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

(tst 10 20)

=> 30

Note:
Please don't use this extension if you want your code to run on other Scheme implementations.


5.5 Top-level set!

QScheme makes a strong distinction between define and set!. define creates a new symbol in the current environment and binds a value to it; set! never creates any symbol. Setting a value to an undefined symbol will cause an error. This distinction is needed especially for the external variables. 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 bound 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 behaviour should be compatible with the R5RS specs.


next up previous contents
Next: 6 Expressions Up: QScheme Documentation Previous: 4 Ignore this   Contents
Daniel Crettol 2000-06-12