5. Bigloo -- Standard Library<BR>5.1 Scheme Library

5. Bigloo -- Standard Library
5.1 Scheme Library

Browsing

Home: Bigloo
A ``practical Scheme compiler''
for Bigloo version 2.5a
April 2002

Previous chapter: Core Language
Next chapter: Pattern Matching


Standard Library

5.1 Scheme Library
5.2 Input and output
5.3 Structures and Records
5.4 Serialization
5.5 Bit manipulation
5.6 Hash Tables
5.7 System programming
5.8 Process support
5.9 Socket support
5.10 Posix Regular Expressions


Chapters

Copyright
Acknowledgements
1. Table of contents
2. Overview of Bigloo
3. Modules
4. Core Language
5. Standard Library
6. Pattern Matching
7. Object System
8. Threads
9. Regular parsing
10. Lalr(1) parsing
11. Errors and Assertions
12. Eval and code interpretation
13. Macro expansion
14. Command Line Parsing
15. Explicit typing
16. The C interface
17. The Java interface
18. Bigloo Libraries
19. SRFIs
20. DSSSL support
21. Compiler description
22. User Extensions
23. Bigloo Development Environment
24. Global Index
25. Library Index
Bibliography


When the definition of a procedure or a special form is the same in Bigloo and Scheme, we just mention its name; otherwise, we explain it and qualify it as a ``bigloo procedure''.

5.1.1 Booleans

The standard boolean objects are #t and #f. Note: the empty list is true.

not objlibrary procedure
not returns #t if obj is false, and returns #f otherwise.

(not #t)                               => #f
(not 3)                                => #f
(not (list 3))                         => #f
(not #f)                               => #t
(not '())                              => #f
(not (list))                           => #f
(not 'nil)                             => #f

boolean? objlibrary procedure
Boolean? returns #t if obj is either #t or #f and returns #f otherwise.

(boolean? #f)                          => #t
(boolean? 0)                           => #f
(boolean? '())                         => #f


5.1.2 Equivalence predicates

eqv? obj1 obj2procedure
eq? obj1 obj2procedure
eqv? and eq? are equivalent in Bigloo.

(eq? 'a 'a)                            =>  #t
(eq? '(a) '(a))                        =>  unspecified
(eq? (list 'a) (list 'a))              =>  #f
(eq? "a" "a")                          =>  unspecified
(eq? "" "")                            =>  unspecified
(eq? '() '())                          =>  #t
(eq? 2 2)                              =>  unspecified
(eq? #\A #\A)                          =>  unspecified
(eq? car car)                          =>  #t
(let ((n (+ 2 3)))
  (eq? n n))                           =>  unspecified
(let ((x '(a)))
  (eq? x x))                           =>  #t
(let ((x '#()))
  (eq? x x))                           =>  #t
(let ((p (lambda (x) x)))
  (eq? p p))                           =>  #t
Since Bigloo implements eqv? as eq?, the behavior is not always conforming to R5RS.
(eqv? 'a 'a)                           =>  #t
(eqv? 'a 'b)                           =>  #f
(eqv? 2 2)                             =>  #t
(eqv? '() '())                         =>  #t
(eqv? 100000000 100000000)             =>  #t
(eqv? (cons 1 2) (cons 1 2))           =>  #f
(eqv? (lambda () 1)
      (lambda () 2))                   =>  #f
(eqv? #f 'nil)                         =>  #f
(let ((p (lambda (x) x)))
  (eqv? p p))                          =>  unspecified


The following examples illustrate cases in which the above rules do not fully specify the behavior of eqv?. All that can be said about such cases is that the value returned by eqv? must be a boolean.

(eqv? "" "")                           =>  unspecified
(eqv? '#() '#())                       =>  unspecified
(eqv? (lambda (x) x)
      (lambda (x) x))                  =>  unspecified
(eqv? (lambda (x) x)
      (lambda (y) y))                  =>  unspecified

(define gen-counter
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) n))))
(let ((g (gen-counter)))
  (eqv? g g))                          =>  #t
(eqv? (gen-counter) (gen-counter))
                                       =>  #f
(define gen-loser
  (lambda ()
    (let ((n 0))
      (lambda () (set! n (+ n 1)) 27))))
(let ((g (gen-loser)))
  (eqv? g g))                          =>  #t
(eqv? (gen-loser) (gen-loser))
                                       =>  unspecified

(letrec ((f (lambda () (if (eqv? f g) 'both 'f)))
         (g (lambda () (if (eqv? f g) 'both 'g))))
  (eqv? f g))
                                       =>  unspecified

(letrec ((f (lambda () (if (eqv? f g) 'f 'both)))
         (g (lambda () (if (eqv? f g) 'g 'both))))
  (eqv? f g))
                                       =>  #f
(eqv? '(a) '(a))                       =>  unspecified
(eqv? "a" "a")                         =>  unspecified
(eqv? '(b) (cdr '(a b)))               =>  unspecified
(let ((x '(a)))
  (eqv? x x))                          =>  #t

equal? obj1 obj2library procedure
(equal? 'a 'a)                         =>  #t
(equal? '(a) '(a))                     =>  #t
(equal? '(a (b) c)
        '(a (b) c))                    =>  #t
(equal? "abc" "abc")                   =>  #t
(equal? 2 2)                           =>  #t
(equal? (make-vector 5 'a)
        (make-vector 5 'a))            =>  #t
(equal? (lambda (x) x)
        (lambda (y) y))                =>  unspecified

See
r5rs, Equivalence predicates, for more details.


5.1.3 Pairs and lists

The form () is illegal.

pair? objprocedure

pair-or-null? objbigloo procedure
Returns #t if obj is either a pair or the empty list. Otherwise it returns #f.

car pairprocedure
cdr pairprocedure
set-car! pair objprocedure
set-cdr! pair objprocedure

caar pairlibrary procedure
cadr pairlibrary procedure
...

cdddar pairlibrary procedure
cddddr pairlibrary procedure

null? objlibrary procedure
list? objlibrary procedure
list obj ...library procedure
length listlibrary procedure
append list ...library procedure
append! list ...bigloo procedure
A destructive append.

reverse listlibrary procedure
reverse! listbigloo procedure
A destructive reverse.

list-ref list klibrary procedure
list-tail list klibrary procedure
Returns the sublist of list obtained by omitting the first k elements.

last-pair listbigloo procedure
Returns the last pair in the nonempty, possibly improper, list.

memq obj listlibrary procedure
memv obj listlibrary procedure
member obj listlibrary procedure
assq obj alistlibrary procedure
assv obj alistlibrary procedure
assoc obj alistlibrary procedure
remq obj listbigloo procedure
Returns a new list which is a copy of list with all items eq? to obj removed from it.

remq! obj listbigloo procedure
Same as remq but in a destructive way.

delete obj listbigloo procedure
Returns a new list which is a copy of list with all items equal? to obj deleted from it.

delete! obj listbigloo procedure
Same as delete but in a destructive way.

cons* obj ...bigloo procedure
Returns an object formed by consing all arguments together from right to left. If only one obj is supplied, that obj is returned.

See
r5rs, Pairs and lists, for more details.


5.1.4 Symbols

Symbols are case sensitive and the reader is case sensitive too. So:
(eq? 'foo 'FOO) => #f
(eq? (string->symbol "foo") (string->symbol "FOO")) => #f
Symbols may contain special characters (such as #\Newline or #\Space). Such symbols that have to be read must be written: |[^]+|. The function write uses that notation when it encounters symbols containing special characters.

(write 'foo) =>foo
(write 'Foo) =>Foo
(write '|foo bar|) =>|foo bar|
symbol? objprocedure
symbol->string symbolprocedure
Returns the name of the symbol as a string. Modifying the string result of symbol->string could yield incoherent programs. It is better to copy the string before any physical update. For instance, don't write:
(string-downcase! (symbol->string 'foo))
See
r5rs, Symbols, for more details.

but prefer:
(string-downcase (symbol->string 'foo))

string->symbol stringprocedure
string->symbol-ci stringbigloo procedure
symbol-append symbol ...bigloo procedure
String->symbol returns a symbol whose name is string. String->symbol respects the case of string. String->symbol-ci returns a symbol whose name is (string-upcase string). Symbol-append returns a symbol whose name is the concatenation of all the symbol's names.

gensym [obj]bigloo procedure
Returns a new fresh symbol. If obj is provided and is a string or a symbol, it is used as prefix for the new symbol.

symbol-plist symbol-or-keywordbigloo procedure
Returns the property-list associated with symbol-or-keyword.

getprop symbol-or-keyword keybigloo procedure
Returns the value that has the key eq? to key from the symbol-or-keyword's property list. If there is no value associated with key then #f is returned.

putprop! symbol-or-keyword key valbigloo procedure
Stores val using key on symbol-or-keyword's property list.

remprop! symbol-or-keyword keybigloo procedure
Removes the value associated with key in the symbol-or-keyword's property list. The result is unspecified.

Here is an example of properties handling:

(getprop 'a-sym 'a-key)       => #f
(putprop! 'a-sym 'a-key 24)  
(getprop 'a-sym 'a-key)       => 24
(putprop! 'a-sym 'a-key2 25)  
(getprop 'a-sym 'a-key)       => 24
(getprop 'a-sym 'a-key2)      => 25
(symbol-plist 'a-sym)         => (a-key2 25 a-key 24)
(remprop! 'a-sym 'a-key)
(symbol-plist 'a-sym)         => (a-key2 25)
(putprop! 'a-sym 'a-key2 16)  
(symbol-plist 'a-sym)         => (a-key2 26)


5.1.5 Keywords

Keywords constitute an extension to Scheme required by Dsssl [Dsssl96]. Keywords syntax is: <ident>:

Keywords are autoquote and case insensitive. So
(eq? toto: TOTO:) => #t
keyword? objbigloo procedure
keyword->string keywordbigloo procedure
string->keyword stringbigloo procedure


5.1.6 Numbers

Bigloo has only three kinds of numbers: fixnum, long fixnum and flonum. Operations on complexes and rationals are not implemented but for compatibility purposes, the functions complex? and rational? exist. (In fact, complex? is the same as number? and rational? is the same as real? in Bigloo.) The binary radix is not implemented so the only accepted prefixes are #o, #d and #x. For each generic arithmetic procedure, Bigloo provides two specialized procedures, one for fixnums and one for flonums. The names of these two specialized procedures is the name of the original one suffixed by fx or fl. A fixnum has the size of a C integer minus 2 bits. A flonum has the size of a C double.

number? objprocedure
real? objprocedure
integer? objprocedure
complex? xbigloo procedure
rational? xbigloo procedure

fixnum? objbigloo procedure
flonum? objbigloo procedure
These two procedures are type checkers on types integer and real.

elong? objbigloo procedure
llong? objbigloo procedure
The elong? procedures is a type checker for "hardware" integers, that is integers that have the very same size has the host platform permits (e.g., 32 bits or 64 bits integers). The llong? procedure is a type checker for "hardware" long long integers.

exact? zprocedure
inexact? zprocedure

zero? zlibrary procedure
positive? zlibrary procedure
negative? zlibrary procedure
odd? nlibrary procedure
even? nlibrary procedure

max x1 x2 ...library procedure
min x1 x2 ...library procedure

= z1 z2 z3 ...procedure
=fx i1 i2bigloo procedure
=fl r1 r2bigloo procedure
< z1 z2 z3 ...procedure
<fx i1 i2bigloo procedure
<fl r1 r2bigloo procedure
> z1 z2 z3 ...procedure
>fx i1 i2bigloo procedure
>fl r1 r2bigloo procedure
<= z1 z2 z3 ...procedure
<=fx i1 i2bigloo procedure
<=fl r1 r2bigloo procedure
>= z1 z2 z3 ...procedure
>=fx i1 i2bigloo procedure
>=fl r1 r2bigloo procedure

+ z ...procedure
+fx i1 i2bigloo procedure
+fl r1 r2bigloo procedure
* z ...procedure
*fx i1 i2bigloo procedure
*fl r1 r2bigloo procedure
- zprocedure
- z1 z2 ...procedure
-fx i1 i2bigloo procedure
-fl r1 r2bigloo procedure
negfx ibigloo procedure
negfl rbigloo procedure
These two functions implement the unary function -.

/ z1 z2procedure
/ z1 z2 ...procedure
/fx i1 i2bigloo procedure
/fl r1 r2bigloo procedure

abs zlibrary procedure
quotient z1 z2procedure
remainder z1 z2procedure
modulo z1 z2procedure
gcd z ...procedure
lcm z ...procedure
floor zprocedure
ceiling zprocedure
truncate zprocedure
round zprocedure

exp zprocedure
log zprocedure
sin zprocedure
cos zprocedure
tan zprocedure
asin zprocedure
acos zprocedure
atan z1 z2procedure
sqrt zprocedure
expt z1 x2procedure

exact->inexact zprocedure
inexact->exact zprocedure
number->string zprocedure
integer->string ibigloo procedure
integer->string i radixbigloo procedure
real->string zbigloo procedure

string->number string procedure
string->number string radixprocedure
string->elong string radixprocedure
string->llong string radixprocedure
Bigloo implements a restricted version of string->number. If string denotes a floating point number then, the only radix 10 may be send to string->number. That is:

(string->number "1243" 16)          => 4675
(string->number "1243.0" 16)        -|
# *** ERROR:bigloo:string->number
# Only radix `10' is legal for floating point number -- 16
(string->elong "234456353")         => #e234456353
In addition, string->number does not support radix encoded inside string. That is:

(string->number "#x1243")          => #f

string->integer stringbigloo procedure
string->integer string radixbigloo procedure
string->real stringbigloo procedure
fixnum->flonum ibigloo procedure
flonum->fixnum rbigloo procedure
These last two procedures implement the natural translation from fixnum to flonum and vice versa.

See
r5rs, Numerical operations, for more details.


5.1.7 Characters

Bigloo knows one more named character #\tab in addition to the #\space and #\newline of R5RS.

A new alternate syntax exists for characters: #\a<ascii-code> where <ascii-code> is the three digit decimal ascii number of the character to be read. Thus, for instance, the character #\space can be written #a032.

char? objprocedure

char=? char1 char2procedure
char<? char1 char2procedure
char>? char1 char2procedure
char<=? char1 char2procedure
char>=? char1 char2procedure
char-ci=? char1 char2library procedure
char-ci<? char1 char2library procedure
char-ci>? char1 char2library procedure
char-ci<=? char1 char2library procedure
char-ci>=? char1 char2library procedure

char-alphabetic? charlibrary procedure
char-numeric? charlibrary procedure
char-whitespace? charlibrary procedure
char-upper-case? charlibrary procedure
char-lower-case? charlibrary procedure

char->integer charprocedure
integer->char iprocedure

char-upcase charlibrary procedure
char-downcase charlibrary procedure


5.1.8 UCS-2 Characters

UCS-2 Characters are two byte encoded characters. They can be read with the syntax: #u<unicode> where <unicode> is the four digit hexadecimal unicode value of the character to be read. Thus, for instance, the character #\space can be written #u0020.

ucs2? objbigloo procedure

ucs2=? ucs2a ucs2bbigloo procedure
ucs2<? ucs2a ucs2bbigloo procedure
ucs2>? ucs2a ucs2bbigloo procedure
ucs2<=? ucs2a ucs2bbigloo procedure
ucs2>=? ucs2a ucs2bbigloo procedure
ucs2-ci=? ucs2a ucs2bbigloo procedure
ucs2-ci<? ucs2a ucs2bbigloo procedure
ucs2-ci>? ucs2a ucs2bbigloo procedure
ucs2-ci<=? ucs2a ucs2bbigloo procedure
ucs2-ci>=? ucs2a ucs2bbigloo procedure

ucs2-alphabetic? ucs2bigloo procedure
ucs2-numeric? ucs2bigloo procedure
ucs2-whitespace? ucs2bigloo procedure
ucs2-upper-case? ucs2bigloo procedure
ucs2-lower-case? ucs2bigloo procedure

ucs2->integer ucs2bigloo procedure
integer->ucs2 ibigloo procedure

ucs2->char ucs2bigloo procedure
char->ucs2 charbigloo procedure

ucs2-upcase ucs2bigloo procedure
ucs2-downcase ucs2bigloo procedure


5.1.9 Strings

There are three different syntaxes for strings in Bigloo: traditional, foreign or Unicode. The traditional syntax for strings may conform to the Revised Report, see r5rs, Lexical structure. With the foreign syntax, C escape sequences are interpreted as specified by ISO-C. In addition, Bigloo's reader evaluate \x?? sequence as an hexadecimal escape character. For Unicode syntax, see Unicode (UCS-2) Strings. Only the reader distinguishes between these three appearances of strings; i.e., there is only one type of string at evaluation-time. The regular expression describing the syntax for foreign string is: #"([^"]|\")*".

*bigloo-strict-r5rs-strings*variable
Traditional syntax conforms to the Revised Report if the variable *bigloo-strict-r5rs-strings* is not #f. Otherwise constant strings specified by the "([^"]|\")*" are considered as foreign strings.


For example, after reading the expression "1\n23\t4\"5", the following string is built, which is equal to (string #\1 #\n #\2 #\3 #\t #\4 #\" #\5) if *bigloo-strict-r5rs-strings* is not #f. It is (string #\1 #\n #\2 #\3 #\tab #\4 #\" #\5) otherwise.

Printing this string will produce: 1n23t4"5.

The new foreign syntax allows C escape sequences to be recognized. For example, the expression #"1\n23\t4\"5" builds a string equal to:

(string #\1 #\newline #\2 #\3 #\t #\4 #\" #\5)

and printing this string will then produce:
1
23    4"5

The library functions for string processing are:
string? objprocedure

make-string kprocedure
make-string k charprocedure
string char ...library procedure

string-length stringprocedure
string-ref string kprocedure
string-set! string k charprocedure

string=? string1 string2library procedure
substring=? string1 string2 lenbigloo procedure
This function returns #t if string1 and string2 have a common prefix of size len.

(substring=? "abcdef" "ab9989898" 2)
   => #t
(substring=? "abcdef" "ab9989898" 3)
   => #f

string-ci=? string1 string2library procedure
string<? string1 string2library procedure
string>? string1 string2library procedure
string<=? string1 string2library procedure
string>=? string1 string2library procedure
string-ci<? string1 string2library procedure
string-ci>? string1 string2library procedure
string-ci<=? string1 string2library procedure
string-ci>=? string1 string2library procedure

substring string start endlibrary procedure
string must be a string, and start and end must be exact integers satisfying:

  0 <= START <= END <= (string-length STRING)
substring returns a newly allocated string formed from the characters of STRING beginning with index START (inclusive) and ending with index END (exclusive).

(substring "abcdef" 0 5)
   => "abcde"
(substring "abcdef" 1 5)
   => "bcde"

string-append string ...library procedure
string->list stringlibrary procedure
list->string listlibrary procedure
string-copy stringlibrary procedure

string-fill! string charbigloo procedure
Stores char in every element of the given string and returns an unspecified value.

string-downcase stringbigloo procedure
Returns a newly allocated version of string where each upper case letter is replaced by its lower case equivalent.

string-upcase stringbigloo procedure
Returns a newly allocated version of string where each lower case letter is replaced by its upper case equivalent.

string-capitalize stringbigloo procedure
Builds a newly allocated capitalized string.

string-downcase! stringbigloo procedure
Physically downcases the string argument.

string-upcase! stringbigloo procedure
Physically upcases the string argument.

string-capitalize! stringbigloo procedure
Physically capitalized the string argument.

string-for-read stringbigloo procedure
Returns a copy of string with each special character replaced by an escape sequence.

blit-string! string1 o1 string2 o2 lenbigloo procedure
Fill string s2 starting at position o2 with len characters taken out of string s1 from position o1.

(let ((s (make-string 20 #\-)))
        (blit-string! "toto" 0 s 16 4)
        s)
   => "----------------toto"


5.1.10 Unicode (UCS-2) Strings

UCS-2 strings cannot be read by the standard reader but UTF-8 strings can. The special syntax for UTF-8 is described by the regular expression: #u"([^]|\")*".

The library functions for Unicode string processing are:
ucs2-string? objbigloo procedure

make-ucs2-string kbigloo procedure
make-ucs2-string k charbigloo procedure
ucs2-string k ...bigloo procedure

ucs2-string-length s-ucs2bigloo procedure
ucs2-string-ref s-ucs2 kbigloo procedure
ucs2-string-set! s-ucs2 k charbigloo procedure

ucs2-string=? s-ucs2a s-ucs2bbigloo procedure
ucs2-string-ci=? s-ucs2a s-ucs2bbigloo procedure
ucs2-string<? s-ucs2a s-ucs2bbigloo procedure
ucs2-string>? s-ucs2a s-ucs2bbigloo procedure
ucs2-string<=? s-ucs2a s-ucs2bbigloo procedure
ucs2-string>=? s-ucs2a s-ucs2bbigloo procedure
ucs2-string-ci<? s-ucs2a s-ucs2bbigloo procedure
ucs2-string-ci>? s-ucs2a s-ucs2bbigloo procedure
ucs2-string-ci<=? s-ucs2a s-ucs2bbigloo procedure
ucs2-string-ci>=? s-ucs2a s-ucs2bbigloo procedure

subucs2-string s-ucs2 start endbigloo procedure
ucs2-string-append s-ucs2 ...bigloo procedure
ucs2-string->list s-ucs2bigloo procedure
list->ucs2-string charsbigloo procedure
ucs2-string-copy s-ucs2bigloo procedure

ucs2-string-fill! s-ucs2 charbigloo procedure
Stores char in every element of the given s-ucs2 and returns an unspecified value.

ucs2-string-downcase s-ucs2bigloo procedure
Builds a newly allocated ucs2-string with lower case letters.

ucs2-string-upcase s-ucs2bigloo procedure
Builds a new allocated ucs2-string with upper case letters.

ucs2-string-downcase! s-ucs2bigloo procedure
Physically downcases the s-ucs2 argument.

ucs2-string-upcase! s-ucs2bigloo procedure
Physically upcases the s-ucs2 argument.

ucs2-string->utf8-string s-ucs2bigloo procedure
utf8-string->ucs2-string stringbigloo procedure
Convert UCS-2 strings to (or from) UTF-8 encoded ascii strings.


5.1.11 Vectors

Vectors are not autoquoted objects.

vector? objprocedure

make-vector kprocedure
make-vector k objprocedure
vector obj ...library procedure

vector-length vectorprocedure
vector-ref vector kprocedure
vector-set! vector k objprocedure

vector->list vectorlibrary procedure
list->vector listlibrary procedure

vector-fill! vector objlibrary procedure
Stores obj in every element of vector. For instance:

(let ((v (make-vector 5 #f)))
   (vector-fill! v #t)
   v)

copy-vector vector lenbigloo procedure
Allocate a new vector of size len and fills it with the first len element of vector. The new length len might be bigger than the old vector length.

sort obj procbigloo procedure
Sorts obj according to proc test. The argument obj can either be a vector or a list. In either case, a copy of the argument is returned. For instance:

(let ((l '(("foo" 5) ("bar" 6) ("hux" 1) ("gee" 4))))
   (sort l (lambda (x y) (string<? (car x) (car y)))))
   => ((bar 6) (foo 5) (gee 4) (hux 1))

See
r5rs, Vectors, for more details.


5.1.12 Control features

procedure? objprocedure

apply proc arg1 ... argsprocedure

map proc list1 list2 ...library procedure
for-each proc list1 list2 ...library procedure

filter pred list ...library procedure
filter! pred list ...library procedure
Strip out all elements of list for which the predicate pred is not true. The second version filter! is destructive:

(filter number? '(1 2 #\a "foo" foo 3)) => (1 2 3)
(let ((l (list 1 2 #\a "foo" 'foo 3)))
   (set! l (filter! number? l))
   l)                                   => (1 2 3)

force promiselibrary procedure

call/cc procbigloo procedure
This function is the same as the call-with-current-continuation function of the R5RS, see
r5rs, call-with-current-continuation, but it is necessary to compile the module with the -call/cc option to use it, see Section See The Bigloo command line.

Note: Since call/cc is difficult to compile efficiently, one might consider using bind-exit instead. For this reason, we decided to enable call/cc only with a compiler option.

bind-exit escape bodybigloo syntax
This form provides an escape operator facility. bind-exit evaluates the body, which may refer to the variable escape which will denote an ``escape function'' of one argument: when called, this escape function will return from the bind-exit form with the given argument as the value of the bind-exit form. The escape can only be used while in the dynamic extent of the form. Bindings introduced by bind-exit are immutable.

(bind-exit (exit)
 (for-each (lambda (x)
             (if (negative? x)
                 (exit x)))
           '(54 0 37 -3 245 19))
 #t)                                  => -3

(define list-length
  (lambda (obj)
    (bind-exit (return)
     (letrec ((r (lambda (obj)
                    (cond ((null? obj) 0)
                          ((pair? obj)
                           (+ (r (cdr obj)) 1))
                          (else (return #f))))))
          (r obj)))))

(list-length '(1 2 3 4))               => 4
(list-length '(a b . c))               => #f

unwind-protect expr protectbigloo syntax
This form provides protections. Expression expr is evaluated. If this evaluation requires the invocation of an escape procedure (a procedure bounded by the bind-exit special form), protect is evaluated before the control jump to the exit procedure. If expr does not raise any exit procedure, unwind-protect has the same behaviour as the begin special form except that the value of the form is always the value of expr.

(define (my-open f)
   (if (file-exists? f)
       (let ((port (open-input-file f)))
          (if (input-port? port)
              (unwind-protect
                 (bar port)
                 (close-input-port port))))))

dynamic-wind before thunk afterprocedure
Calls thunk without arguments, returning the result(s) of this call. Before and after are called, also without arguments, as required by the following rules (note that in the absence of calls to continuations captured using call/cc the three arguments are
called once each, in order). Before is called whenever execution enters the dynamic extent of the call to thunk and after is called whenever it exits that dynamic extent. The dynamic extent of a procedure call is the period between when the call is initiated and when it returns. In Scheme, because of call/cc, the dynamic extent of a call may not be a single, connected time period. It is defined as follows:

  • The dynamic extent is entered when execution of the body of the called procedure begins.

  • The dynamic extent is also entered when execution is not within the dynamic extent and a continuation is invoked that was captured (using call/cc) during the dynamic extent.

  • It is exited when the called procedure returns.

  • It is also exited when execution is within the dynamic extent and a continuation is invoked that was captured while not within the dynamic extent.

If a second call to dynamic-wind occurs within the dynamic extent of the call to thunk and then a continuation is invoked in such a way that the afters from these two invocations of dynamic-wind are both to be called, then the after associated with the second (inner) call to dynamic-wind is called first.

If a second call to dynamic-wind occurs within the dynamic extent of the call to thunk and then a continuation is invoked in such a way that the befores from these two invocations of dynamic-wind are both to be called, then the before associated with the first (outer) call to dynamic-wind is called first.

If invoking a continuation requires calling the before from one call to dynamic-wind and the after from another, then the after is called first.

The effect of using a captured continuation to enter or exit the dynamic extent of a call to before or after is undefined.


(let ((path '())
      (c #f))
  (let ((add (lambda (s)
               (set! path (cons s path)))))
    (dynamic-wind
      (lambda () (add 'connect))
      (lambda ()
        (add (call/cc
               (lambda (c0)
                 (set! c c0)
                 'talk1))))
      (lambda () (add 'disconnect)))
    (if (< (length path) 4)
        (c 'talk2)
        (reverse path))))
    
   => (connect talk1 disconnect connect talk2 disconnect)

unspecifiedbigloo procedure
Returns the unspecified (noted as #unspecified) object with no specific property.

try exp handlerbigloo syntax
This form is documented in Section
Errors and Assertions.

values obj ...procedure
Delivers all of its arguments to its continuation. Except for continuations created by the call-with-values
procedure, all continuations take exactly one value. Values might be defined as follows:

(define (values . things)
  (call/cc
    (lambda (cont) (apply cont things))))

call-with-values producer consumerprocedure
Calls its producer argument with no values and a continuation that, when passed some values, calls the consumer procedure with those values as arguments. The continuation for the call to consumer is the continuation of the call to call-with-values.

(call-with-values (lambda () (values 4 5))
                  (lambda (a b) b))
    => 5
(call-with-values * -)
    => -1

multiple-value-bind (var ...) producer exp ...bigloo syntax
receive (var ...) producer exp ...bigloo syntax
Evaluates exp ... in a environment where var ... are bound from the evaluation of producer. The result of producer must be a call to values where the number of argument is the number of bound variables.
(define (bar a)
   (values (modulo a 5) (quotient a 5)))

(define (foo a)
   (multiple-value-bind (x y)
      (bar a)
      (print x " " y)))

(foo 354)
   -| 4 70



This
Scribe page has been generated by scribeinfo.
Last update Thu Apr 25 09:40:15 2002