sigildocs

(scheme base)

(scheme base) - R7RS Base Library

The core R7RS library containing fundamental procedures, syntax, and values. This provides the standard Scheme interface for portable code.

See: R7RS Small §6.1-6.14

For Sigil-specific extensions, use (sigil core) instead.

Exports

eq?procedure

Test object identity

Re-exported from (sigil core)

eqv?procedure

Test equivalence

Re-exported from (sigil core)

equal?procedure

Test structural equality

Re-exported from (sigil core)

notprocedure

Boolean negation

Re-exported from (sigil core)

boolean?procedure

Test if value is a boolean

Re-exported from (sigil core)

pair?procedure

Test if value is a pair

Re-exported from (sigil core)

consprocedure

Construct pair

Re-exported from (sigil core)

carprocedure

Get first element of pair

Re-exported from (sigil core)

cdrprocedure

Get rest of pair

Re-exported from (sigil core)

set-car!procedure

Set first element of pair

Re-exported from (sigil core)

set-cdr!procedure

Set rest of pair

Re-exported from (sigil core)

caarprocedure

Get the car of the car: (car (car x)).

(caar '((1 2) 3))  ; => 1

Re-exported from (sigil core)

cadrprocedure

Get the car of the cdr (second element): (car (cdr x)).

(cadr '(1 2 3))  ; => 2

Re-exported from (sigil core)

cdarprocedure

Get the cdr of the car: (cdr (car x)).

(cdar '((1 2 3) 4))  ; => (2 3)

Re-exported from (sigil core)

cddrprocedure

Get the cdr of the cdr (tail after second): (cdr (cdr x)).

(cddr '(1 2 3 4))  ; => (3 4)

Re-exported from (sigil core)

null?procedure

Test if value is null

Re-exported from (sigil core)

list?procedure

Test if value is a proper list

Re-exported from (sigil core)

listprocedure

Create a list from arguments

Re-exported from (sigil core)

make-listprocedure

Create a list of n copies of fill.

(make-list 3 'a)  ; => (a a a)
(make-list 5)     ; => (#f #f #f #f #f)
(make-list 0 'x)  ; => ()

If fill is omitted, #f is used.

Re-exported from (sigil core)

lengthprocedure

Get length of list or vector

Re-exported from (sigil core)

appendprocedure

Concatenate any number of lists into one.

Returns a new list with elements from all lists in order. The last list is shared (not copied).

(append '(1 2) '(3 4))        ; => (1 2 3 4)
(append '(a) '(b) '(c d))     ; => (a b c d)
(append '(1 2) '())           ; => (1 2)

Re-exported from (sigil core)

reverseprocedure

Reverse the order of elements in a list.

Returns a new list with elements in reverse order.

(reverse '(1 2 3))    ; => (3 2 1)
(reverse '(a b c d))  ; => (d c b a)
(reverse '())         ; => ()

Re-exported from (sigil core)

list-refprocedure

Re-exported from (sigil core)

memqprocedure

Find element in list using eq?

Re-exported from (sigil core)

memvprocedure

Find element in list using eqv?

Re-exported from (sigil core)

memberprocedure

Find element in list using equal?

Re-exported from (sigil core)

assqprocedure

Find pair in alist using eq?

Re-exported from (sigil core)

assvprocedure

Find pair in alist using eqv?

Re-exported from (sigil core)

assocprocedure

Find pair in alist using equal?

Re-exported from (sigil core)

mapprocedure

Apply a procedure to each element of a list, returning a new list.

(map (lambda (x) (* x 2)) '(1 2 3))  ; => (2 4 6)
(map symbol->string '(a b c))        ; => ("a" "b" "c")

For multi-list mapping, use list-map from (sigil list):

(import (sigil list))
(list-map + '(1 2 3) '(10 20 30))    ; => (11 22 33)

Re-exported from (sigil core)

for-eachprocedure

Apply a procedure to each element of a list for side effects.

Like map, but doesn't collect results—used for side effects like printing.

(for-each println '("a" "b" "c"))  ; prints a, b, c on separate lines
(for-each (lambda (x) (set! sum (+ sum x))) '(1 2 3))

For multi-list iteration, use list-for-each from (sigil list):

(import (sigil list))
(list-for-each (lambda (a b) (println "~a" (+ a b))) '(1 2) '(10 20))

Re-exported from (sigil core)

symbol?procedure

Test if value is a symbol

Re-exported from (sigil core)

Convert symbol to string

Re-exported from (sigil core)

Convert string to symbol

Re-exported from (sigil core)

number?procedure

Test if value is a number

Re-exported from (sigil core)

integer?procedure

Test if value is an integer

Re-exported from (sigil core)

Test if value is an exact integer

Re-exported from (sigil math)

exact?procedure

Test if number is exact

Re-exported from (sigil math)

inexact?procedure

Test if number is inexact

Re-exported from (sigil math)

exactprocedure

Convert to exact number

Re-exported from (sigil math)

inexactprocedure

Convert to inexact number

Re-exported from (sigil math)

=procedure

Numeric equality

Re-exported from (sigil core)

<procedure

Numeric less than

Re-exported from (sigil core)

>procedure

Numeric greater than

Re-exported from (sigil core)

<=procedure

Numeric less than or equal

Re-exported from (sigil core)

>=procedure

Numeric greater than or equal

Re-exported from (sigil core)

zero?procedure

Check if a number is zero.

(zero? 0)    ; => #t
(zero? 1)    ; => #f
(zero? -1)   ; => #f
(zero? 0.0)  ; => #t

Re-exported from (sigil core)

positive?procedure

Check if a number is positive (greater than zero).

(positive? 5)    ; => #t
(positive? 0)    ; => #f
(positive? -3)   ; => #f
(positive? 0.1)  ; => #t

Re-exported from (sigil core)

negative?procedure

Check if a number is negative (less than zero).

(negative? -5)   ; => #t
(negative? 0)    ; => #f
(negative? 3)    ; => #f
(negative? -0.1) ; => #t

Re-exported from (sigil core)

odd?procedure

odd? - Test if an integer is odd (odd? 3) => #t (odd? 4) => #f

Re-exported from (sigil core)

even?procedure

even? - Test if an integer is even (even? 4) => #t (even? 3) => #f

Re-exported from (sigil core)

maxprocedure

Return maximum of arguments

Re-exported from (sigil math)

minprocedure

Return minimum of arguments

Re-exported from (sigil math)

+procedure

Add numbers

Re-exported from (sigil core)

-procedure

Subtract numbers or negate

Re-exported from (sigil core)

*procedure

Multiply numbers

Re-exported from (sigil core)

/procedure

Divide numbers or reciprocal

Re-exported from (sigil core)

floorprocedure

Round toward negative infinity

Re-exported from (sigil math)

ceilingprocedure

Round toward positive infinity

Re-exported from (sigil math)

truncateprocedure

Round toward zero

Re-exported from (sigil math)

roundprocedure

Round to nearest integer

Re-exported from (sigil math)

quotientprocedure

Integer division (truncate)

Re-exported from (sigil math)

gcdprocedure

Greatest common divisor

Re-exported from (sigil math)

lcmprocedure

Least common multiple

Re-exported from (sigil math)

exptprocedure

Exponentiation (base^exponent)

Re-exported from (sigil math)

squareprocedure

Square of a number

Re-exported from (sigil math)

Floor division quotient

Re-exported from (sigil math)

Floor division remainder

Re-exported from (sigil math)

floor/procedure

Floor division returning quotient and remainder

Re-exported from (sigil math)

Truncating division quotient

Re-exported from (sigil math)

Truncating division remainder

Re-exported from (sigil math)

truncate/procedure

Truncating division returning quotient and remainder

Re-exported from (sigil math)

Convert number to string with optional radix

Re-exported from (sigil core)

Parse string as number

Re-exported from (sigil core)

char?procedure

Test if value is a character

Re-exported from (sigil core)

char=?procedure

Character equality

Re-exported from (sigil core)

char<?procedure

Character less-than

Re-exported from (sigil core)

char>?procedure

Character greater-than

Re-exported from (sigil core)

char<=?procedure

Character less-than-or-equal

Re-exported from (sigil core)

char>=?procedure

Character greater-than-or-equal

Re-exported from (sigil core)

char->integerprocedure

Convert character to code point

Re-exported from (sigil core)

integer->charprocedure

Convert code point to character

Re-exported from (sigil core)

string?procedure

Test if value is a string

Re-exported from (sigil core)

make-stringprocedure

Create a string of n copies of char.

(make-string 3 #\a)  ; => "aaa"
(make-string 5)      ; => "     "
(make-string 0 #\x)  ; => ""

If char is omitted, space is used.

Re-exported from (sigil core)

stringprocedure

Create string from characters

Re-exported from (sigil core)

string-lengthprocedure

Get string length

Re-exported from (sigil core)

string-refprocedure

Get character at index

Re-exported from (sigil core)

string-set!procedure

Set character at index in string

Re-exported from (sigil core)

string=?procedure

String equality

Re-exported from (sigil core)

string<?procedure

Compare strings lexicographically (less than).

Characters are compared by their Unicode code points.

(string<? "apple" "banana")  ; => #t
(string<? "abc" "abd")       ; => #t
(string<? "abc" "abc")       ; => #f

Re-exported from (sigil string)

string>?procedure

Compare strings lexicographically (greater than).

(string>? "banana" "apple")  ; => #t
(string>? "abc" "abc")       ; => #f

Re-exported from (sigil string)

string<=?procedure

Compare strings lexicographically (less than or equal).

(string<=? "abc" "abd")  ; => #t
(string<=? "abc" "abc")  ; => #t
(string<=? "abd" "abc")  ; => #f

Re-exported from (sigil string)

string>=?procedure

Compare strings lexicographically (greater than or equal).

(string>=? "abd" "abc")  ; => #t
(string>=? "abc" "abc")  ; => #t
(string>=? "abc" "abd")  ; => #f

Re-exported from (sigil string)

substringprocedure

Extract substring

Re-exported from (sigil core)

string-appendprocedure

Concatenate strings

Re-exported from (sigil core)

string-copyprocedure

Copy a string, optionally with start and end indices. (string-copy str) -> new string copy (string-copy str start) -> copy from start to end (string-copy str start end) -> copy from start to end

Re-exported from (sigil core)

string-copy!procedure

Re-exported from (sigil core)

string-fill!procedure

Re-exported from (sigil core)

string-upcaseprocedure

Convert string to uppercase

Re-exported from (sigil core)

Convert string to lowercase

Re-exported from (sigil core)

Convert string to foldcase

Re-exported from (sigil core)

string->listprocedure

Convert string to list of characters

Re-exported from (sigil core)

list->stringprocedure

Convert list of characters to string

Re-exported from (sigil core)

Apply procedure to each character of a string for side effects. (string-for-each display "abc") displays abc

Re-exported from (sigil core)

string-mapprocedure

Apply procedure to each character, return string of results. (string-map char-upcase "abc") => "ABC"

Re-exported from (sigil core)

Convert a vector of characters to a string. (vector->string #(#a #b #c)) => "abc"

Re-exported from (sigil core)

Convert a string to a vector of characters. (string->vector "abc") => #(#a #b #c) (string->vector "hello" 1 4) => #(#e #l #l)

Re-exported from (sigil core)

vector?procedure

Test if value is a vector

Re-exported from (sigil core)

make-vectorprocedure

Create vector with optional fill

Re-exported from (sigil core)

vector-lengthprocedure

Get vector length

Re-exported from (sigil core)

vector-refprocedure

Get vector element at index

Re-exported from (sigil core)

vector-set!procedure

Set vector element at index

Re-exported from (sigil core)

vector->listprocedure

Convert a vector to a list. (vector->list vec) -> list (vector->list vec start) -> list from start to end (vector->list vec start end) -> list from start to end

Re-exported from (sigil core)

list->vectorprocedure

Convert a list to a vector. (list->vector lst) -> vector

Re-exported from (sigil core)

vector-copyprocedure

Copy a vector, optionally with start and end indices. (vector-copy vec) -> new vector copy (vector-copy vec start) -> copy from start to end (vector-copy vec start end) -> copy from start to end

Re-exported from (sigil core)

vector-copy!procedure

Re-exported from (sigil core)

vector-fill!procedure

Fill a vector with a value. (vector-fill! vec fill) -> fills entire vector (vector-fill! vec fill start) -> fills from start to end (vector-fill! vec fill start end) -> fills from start to end

Re-exported from (sigil core)

Apply procedure to each element of a vector for side effects. (vector-for-each display #(1 2 3)) displays 123

Re-exported from (sigil core)

vector-mapprocedure

Apply procedure to each element, return vector of results. (vector-map (lambda (x) (* x 2)) #(1 2 3)) => #(2 4 6)

Re-exported from (sigil core)

bytevector?procedure

Test if value is a bytevector

Re-exported from (sigil core)

Create bytevector of given size, optionally filled with a byte value

Re-exported from (sigil core)

bytevectorprocedure

Re-exported from (sigil core)

Get bytevector length

Re-exported from (sigil core)

Get byte at index

Re-exported from (sigil core)

Set byte at index

Re-exported from (sigil core)

Copy a bytevector, optionally with start and end indices. (bytevector-copy bv) -> new bytevector copy (bytevector-copy bv start) -> copy from start to end (bytevector-copy bv start end) -> copy from start to end

Re-exported from (sigil core)

Re-exported from (sigil core)

Append multiple bytevectors. (bytevector-append #u8(1 2) #u8(3 4)) => #u8(1 2 3 4)

Re-exported from (sigil core)

utf8->stringprocedure

Convert UTF-8 bytevector to string

Re-exported from (sigil io)

string->utf8procedure

Convert string to UTF-8 bytevector

Re-exported from (sigil io)

procedure?procedure

Test if value is a procedure

Re-exported from (sigil core)

applyprocedure

Apply procedure to arguments

Re-exported from (sigil core)

valuesprocedure

Return multiple values

Re-exported from (sigil core)

Call producer and pass values to consumer

Re-exported from (sigil core)

dynamic-windprocedure

dynamic-wind - establish before/after thunks around body R7RS: (dynamic-wind before thunk after) Calls before, then thunk, then after. If a continuation captured inside thunk is invoked from outside, after is called on exit and before on re-entry.

Re-exported from (sigil core)

errorprocedure

Convenience function to raise an error exception. (error "message" irritant ...)

Re-exported from (sigil core)

error-object?procedure

Test if a value is an error object (exception).

Re-exported from (sigil core)

Get the message from an error object.

Re-exported from (sigil core)

Get the irritants from an error object.

Re-exported from (sigil core)

Get the type/kind of an error object.

Re-exported from (sigil core)

file-error?procedure

Test if an error is file-related.

Re-exported from (sigil core)

read-error?procedure

Test if an error is read-related.

Re-exported from (sigil core)

raiseprocedure

Raise an exception (non-continuable). The compiler compiles direct calls to OP_RAISE (which handles stack trace attachment and searches the VM exception handler stack). This Scheme wrapper exists for first-class use (e.g. apply/map).

Re-exported from (sigil core)

Raise a continuable exception. The handler can return a value to continue execution.

Re-exported from (sigil core)

Install an exception handler and execute thunk (R6RS style). Handler is a procedure taking the exception. Thunk is the body to execute.

Re-exported from (sigil core)

input-port?procedure

Test if value is an input port

Re-exported from (sigil core)

output-port?procedure

Test if value is an output port

Re-exported from (sigil core)

textual-port?procedure

Test if port is textual

Re-exported from (sigil core)

binary-port?procedure

Test if port is binary

Re-exported from (sigil core)

port?procedure

Test if value is a port

Re-exported from (sigil core)

Re-exported from (sigil core)

Re-exported from (sigil core)

Re-exported from (sigil core)

close-portprocedure

Close a port

Re-exported from (sigil core)

Close an input port

Re-exported from (sigil core)

Close an output port

Re-exported from (sigil core)

port-open?procedure

Test if port is open

Re-exported from (sigil core)

Create input port from string

Re-exported from (sigil io)

Create output string port

Re-exported from (sigil io)

Get accumulated string from output string port

Re-exported from (sigil io)

Flush output port buffer

Re-exported from (sigil io)

read-charprocedure

Read a single character from a port.

Returns the next character, or the end-of-file object if the port is exhausted.

(read-char port)  ; => #\H
(read-char port)  ; => #\e

Re-exported from (sigil io)

peek-charprocedure

Look at the next character without consuming it.

Returns the next character that would be read, but leaves it in the input stream.

(peek-char port)  ; => #\H
(peek-char port)  ; => #\H (still there)
(read-char port)  ; => #\H (now consumed)

Re-exported from (sigil io)

read-lineprocedure

Read a line of text from a port.

Returns all characters up to and not including the newline. Returns the end-of-file object if already at end of input.

When reading from a pipe port in an async context, yields to the scheduler while waiting for data.

;; Read all lines from a file
(let loop ((lines '()))
  (let ((line (read-line port)))
    (if (eof-object? line)
        (reverse lines)
        (loop (cons line lines)))))

Re-exported from (sigil io)

read-stringprocedure

Read a specific number of characters from a port.

Returns a string with up to n characters. May return fewer if end-of-file is reached.

(read-string 10 port)  ; => "Hello, Wor"

Re-exported from (sigil io)

read-u8procedure

Read a single byte from a binary port.

Returns an integer 0-255, or the end-of-file object.

(read-u8 port)  ; => 72 (ASCII 'H')

Re-exported from (sigil io)

peek-u8procedure

Look at the next byte without consuming it.

Returns the byte as an integer 0-255, or the EOF object.

Re-exported from (sigil io)

write-u8procedure

Write a single byte to a binary port.

The byte must be an integer 0-255.

(write-u8 72 port)  ; writes ASCII 'H'

Re-exported from (sigil io)

Read bytes from a port into a bytevector.

With one argument, reads up to n bytes. With a bytevector argument, fills it and returns the count read.

(read-bytevector 1024 port)  ; => #u8(72 101 108 ...)

Re-exported from (sigil io)

Read bytes into existing bytevector

Re-exported from (sigil io)

Write a bytevector to a port.

Writes all bytes from the bytevector to the port.

(write-bytevector #u8(72 101 108 108 111) port)  ; writes "Hello"

Re-exported from (sigil io)

Create input port from bytevector

Re-exported from (sigil io)

Create output bytevector port

Re-exported from (sigil io)

Get accumulated bytevector from output bytevector port

Re-exported from (sigil io)

char-ready?procedure

Check if character is available to read

Re-exported from (sigil io)

u8-ready?procedure

Check if byte is available to read

Re-exported from (sigil io)

write-charprocedure

Write a single character to a port.

(write-char #\A port)
(write-char #\newline port)

Re-exported from (sigil io)

write-stringprocedure

Write a string to a port.

Outputs the string's characters. Optional start and end indices write a substring.

(write-string "Hello, World!" port)
(write-string "Hello" port 0 4)  ; writes "Hell"

Re-exported from (sigil io)

newlineprocedure

Print newline to port

Re-exported from (sigil core)

eof-objectprocedure

Return the EOF object

Re-exported from (sigil core)

eof-object?procedure

Test if value is EOF

Re-exported from (sigil core)

call-with-port - R7RS procedure for safe port handling Calls proc with port as argument, closes port when proc returns, and returns the result of proc.

Usage: (call-with-port (open-input-file "data.txt") (lambda (port) (read-line port)))

Re-exported from (sigil core)

Create a parameter object

Re-exported from (sigil core)

featuresprocedure

Return list of implementation feature identifiers

Re-exported from (sigil core)

Re-exported from (srfi srfi-9)