## srfi-216

## TOC »

### Introduction

This egg implements SRFI-216, with minor modifications to the reference implementation to avoid unnecessary dependencies.

### Author

Vasilij Schneidermann

### Repository

https://depp.brause.cc/srfi-216

### API

#### Booleans

`false`constantThe canonical false value

`#f`.Even though Scheme reports as early as R4RS (Sections 3.2, 6.1) already have

`#f`as a distinct`false`value, SICP continues to refer to false. See Section 1.1.6, footnote 17.

`true`constantThe canonical true value

`#t`.Even though Scheme reports as early as R4RS (Sections 3.2, 6.1) already have

`#t`as a distinct`true`value, SICP continues to refer to true. See Section 1.1.6, footnote 17.

#### The empty list

`nil`constantThe canonical empty list value

`'()`Remark: even though many modern Scheme implementations only use

`'()`to represent the empty list, SICP follows the Lisp tradition in this respect.

#### Time data

`runtime`procedureReturns an integer that specifies the amount of time the process has been running (measured in microseconds). See Section 1.2.6 of the SICP, Subsection "Probabilistic Methods", Exercise 1.22.

Example:

(import (srfi 216)) (display (runtime)) ;; prints 1604464095599.357

#### Random numbers

`random``x`procedureReturns a nonnegative number less than its input. If random is given an exact integer, it returns an exact integer, but if it is given a decimal value, it returns a decimal value. If

`x`is less than 0, the behaviour is unspecified. See Section 1.2.6 of the SICP, Subsection "Fermat Test", and Exercise 3.5, footnote 8.Example:

(import (srfi 216)) (random 11) ;; prints 1

#### Multi-threading

`parallel-execute``p1``p2``...`procedureEach argument must be a procedure of no arguments.

`parallel-execute`creates a separate process for each argument, and that process applies the argument to no arguments. These processes all run concurrently.See SICP Section 3.4.2, Subsection "Serializers in Scheme".

Example:

(import (srfi 216)) (define x 10) (parallel-execute (lambda () (set! x (* x x))) ; P1 (lambda () (set! x (+ x 1)))) ; P2 ;; May assign to x any of the following: ;; 101 - P1 sets x to 100 and then P2 increments x to 101. ;; 121 - P2 increments x to 11 and then P1 sets x to x * x. ;; 110 - P2 changes x from 10 to 11 between the two times that P1 accesses the value of x during the evaluation of (* x x). ;; 11 - P2 accesses x, then P1 sets x to 100, then P2 sets x. ;; 100 - P1 accesses x (twice), then P2 sets x to 11, then P 1 sets x.

`test-and-set!``cell`procedureTests the cell and returns the result of the test. In addition, if the test was false,

`test-and-set!`sets the cell contents to`true`before returning`false`.The

`test-and-set!`operation must be performed atomically. That is, the implementation must guarantee that, once a process has tested the cell and found it to be`false`, the cell contents will actually be set to`true`before any other process can test the cell. See Section 3.4.2, Subsection "Implementing Serializers".

#### Streams

`(cons-stream a b)`syntaxIs equivalent to

`(cons a (delay b))`. See SICP Section 3.5.1.Remark: The necessity to include

`cons-stream`is due to the fact that SICP does not introduce any syntax-altering constructs beyond writing your own metacircular interpreter. Please note that the`stream-cons`procedure from SRFI 41 (implementing "even" streams) would not be a drop-in replacement for`cons-stream`.

`the-empty-stream`constantA distinguishable object that cannot be the result of any

`cons-stream`operation. See SICP Section 3.5.1, footnote 54.Equivalent to the empty list.

`stream-null?``x`procedureReturns the value of

`true`if`x`is`the-empty-stream`, and the value of`false`otherwise. See SICP Section 3.5.1, footnote 54.Example:

(import (srfi 126)) (stream-null? the-empty-stream) ;; => #t (stream-null? (cons-stream 'a 'b)) ;; => #f

Equivalent to

`null?`.

### Example

(import scheme) (import (srfi 216)) (define (prime? n) ...) (define (timed-prime-test n) (newline) (display n) (start-prime-test n (runtime))) (define (start-prime-test n start-time) (if (prime? n) (report-prime (- (runtime) start-time)))) (define (report-prime elapsed-time) (display " *** ") (display elapsed-time))

### License

### Version history

#### 0.1

- Initial release