In this section I give a list of native QScheme types and the procedure to handle this types. Most of the types are described in the R5RS document and are ligthly documented here. New types are described more in depth.
Atoms are unique string collected in a hash, the atom hash. They are used anywhere
we need unique strings. Symbols name and keywords are examples of atoms
(atom-hash) -> hash
(string->atom str) -> atom
(atom->string atom) -> str
A symbol has a name and a value. The name of a symbol is an atom, it's value may be any valid scheme object. New symbols are created by the (define sym value) special form.
(symbol? obj ) -> <boolean>
(symbol->string symbol ) -> <string>
*THINK*: should we provide a way to undefine a symbol ?
Keyword are special symbols that evaluate to them self. The keywords are reconized by the read procedure. A keyword always start with a ':' . Exemples:
A pair consist of two pointer to other scheme object. The name of the pointers are CAR and CDR for historical reasons. Procedure to handle pairs are:
(pair? object) -> <boolean>
(cons arg1 arg2) -> <pair>
(car pair) -> <object>
(cdr pair) -> <object>
(caar pair)
(cadr pair)
...
(cdddar pair)
(cddddr pair)
(cdr pair) -> <object>
(set-car! pair object) -> #undefined
(set-cdr! pair object) -> #undefined
(null? obj) -> <boolean>
All procedures of R5RS are implemented.
(list? obj) -> <boolean>
(length list) -> <number>
(append list ...) -> <list>
(reverse list) -> <list>
(list-tail list n) -> <object>
(list-ref list n) -> <object>
(memq obj list) -> <list>
(memv obj list) -> <list>
(member obj list) -> <list>
(assq obj alist) -> <list>
(assv obj alist) -> <list>
(assoc obj alist) -> <list>
Characters represents printed chars. Character uses the notation #\<character>
or #<character name>, see R5RS and table 3 for more
details.
|
Procedure handling chars are:
(char? obj) -> <boolean>
(char=? char1 char2) -> <boolean>
(char<? char1 char2) -> <boolean>
(char>? char1 char2) -> <boolean>
(char<=? char1 char2) -> <boolean>
(char>=? char1 char2) -> <boolean>
(char-ci=? char1 char2) -> <boolean>
(char-ci<? char1 char2) -> <boolean>
(char-ci>? char1 char2) -> <boolean>
(char-ci<=? char1 char2) -> <boolean>
(char-ci>=? char1 char2) -> <boolean>
(char-alphabetic? char) -> <boolean>
(char-numeric? char) -> <boolean>
(char-whitespace? char) -> <boolean>
(char-upper-case? char) -> <boolean>
(char-lower-case? char) -> <boolean>
(char->integer char) -> <number>
(integer->char number) -> <char>
(char-upcase char) -> <char>
(char-downcase char) -> <char>
Strings procedure are compatible with R5RS.
(string? object) -> <boolean>
(make-string size [char]) -> <string>
(string char ...) -> <string>
(string-length str) -> <number>
(string-ref str k) -> <char>
(string-set! str k char) -> <number>
(string=? str1 str2) -> <boolean>
(string<? str1 str2) -> <boolean>
(string>? str1 str2) -> <boolean>
(string<=? str1 str2) -> <boolean>
(string>=? str1 str2) -> <boolean>
(string-ci=? str1 str2) -> <boolean>
(string-ci<? str1 str2) -> <boolean>
(string-ci>? str1 str2) -> <boolean>
(string-ci<=? str1 str2) -> <boolean>
(string-ci>=? str1 str2) -> <boolean>
(substring str start end) -> <string>
(string-length str) -> <number>
(string-append str ...) -> <str>
(string->list str) -> <list>
(list->string list) -> <string>
(string-copy str) -> <string>
(string-fill! str char) -> #undefined
(string-append2 str1 str2) -> <string>
All procedures of R5RS are implemented.
(vector? object) -> <boolean>
(make-vector k [fill]) -> <vector>
(vector obj ...) -> <vector>
(vector-length vector) -> <number>
(vector-ref vector k) -> <object>
(vector-set! vector k obj) -> #undefined
(vector->list vector) -> <list>
(list->vector list) -> <vector>
(vector-fill! vector obj) -> <vector>
(vector-resize vector newsize) -> <vector>
(vector-append v1 v2) -> <vector>
Hash is used to store key/value pair for fast access. Keys are assumed to be unique. Acceptable key type depends on the hash type. For generic type, any key may be used. For symbol hashes, only atoms or strings are acceptable
(make-hash type) -> <hash>
(hash? hash) -> <boolean>
(atom-hash? hash) -> <boolean>
(symbol-hash? hash) -> <boolean>
(generic-hash? hash) -> <boolean>
(hash-set! hash key value) -> <hash>
(hash-ref hash key) -> <value>
(hash-stat hash) -> #undefined
(hash->list hash) -> <list>
(list->hash list) -> <hash>
Input-output in scheme is based on concept of port.
(port? obj) -> <boolean>
(input-port? obj) -> <boolean>
(input-port? obj) -> <boolean>
(current-input-port) -> <port>
(current-output-port) -> <port>
(current-error-port) -> <port>
(open-input-file <string>filename) -> <port> | #f
(open-output-file <string>filename) -> <port> | #f
(close-port port) -> #undefined
(read-char [port]) -> <char> | #eof
(peek-char [port]) -> <char> | #eof
(read-line [port]) -> <string> | #eof
(eof-object? obj) -> <boolean>
(char-ready? port) -> <boolean>
The error handling is proved by two functions: catch and throw. The catch form defines a context where error are trapped. The throw function signal an error. Error is sended to the catch having the same tag or a #f as tag. When a match is found, the handler is called with the string thrown as argument. If the handler terminates, the execution resumed after the catch form and the value returned by the handler will be returned by the catch form.
When throwing, the #f tag can be used to force a top-level error with
no resume, some kind of abort.
(catch tag handler expr ...)
(%catch tag handler) handler tag - catch-context catch-link cont
(%uncatch) catch-context catch-link res - res
(throw tag string)
The module system implement private name spaces in different level. It provides a way to control what names may be used from outside the module. This is a small example of the module definition:
(export x)
(define x 10))
(module B
(export x)
(define x 20))
(module C
(import A B)
(print x))
=> 10
=> 10
(module module expr...)
(export symbol1 symbol2 ...)
(import module1 module2 ...)
(current-module) -> module
(set-current-module module)
(make-module name)-> module
module-hash -> hash
(module-exports module)-> list
(module-imports module)-> list
(module-symbols module)-> hash
(find-module name)-> module
*REVIEW*