Previous: , Up: Universal SLIB Procedures   [Contents][Index]

2.5 Miscellany

These procedures are provided by all implementations.

Function: identity x

identity returns its argument.


(identity 3)
   ⇒ 3
(identity '(foo bar))
   ⇒ (foo bar)
(map identity lst)
   ≡ (copy-list lst)

2.5.1 Mutual Exclusion

An exchanger is a procedure of one argument regulating mutually exclusive access to a resource. When a exchanger is called, its current content is returned, while being replaced by its argument in an atomic operation.

Function: make-exchanger obj

Returns a new exchanger with the argument obj as its initial content.

(define queue (make-exchanger (list a)))

A queue implemented as an exchanger holding a list can be protected from reentrant execution thus:

(define (pop queue)
  (let ((lst #f))
        (lambda () (set! lst (queue #f)))
        (lambda () (and lst (not (null? lst))
                        (let ((ret (car lst)))
                          (set! lst (cdr lst))
        (lambda () (and lst (queue lst))))))

(pop queue)         ⇒ a

(pop queue)         ⇒ #f

2.5.2 Legacy

The following procedures were present in Scheme until R4RS (see Language changes in Revised(4) Scheme). They are provided by all SLIB implementations.

Constant: t

Defined as #t.

Constant: nil

Defined as #f.

Function: last-pair l

Returns the last pair in the list l. Example:

(last-pair (cons 1 2))
   ⇒ (1 . 2)
(last-pair '(1 2))
   ⇒ (2)
    ≡ (cons 2 '())