(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?procedureTest object identity
Re-exported from (sigil core)
eqv?procedureTest equivalence
Re-exported from (sigil core)
equal?procedureTest structural equality
Re-exported from (sigil core)
notprocedureBoolean negation
Re-exported from (sigil core)
boolean?procedureTest if value is a boolean
Re-exported from (sigil core)
pair?procedureTest if value is a pair
Re-exported from (sigil core)
consprocedureConstruct pair
Re-exported from (sigil core)
carprocedureGet first element of pair
Re-exported from (sigil core)
cdrprocedureGet rest of pair
Re-exported from (sigil core)
set-car!procedureSet first element of pair
Re-exported from (sigil core)
set-cdr!procedureSet rest of pair
Re-exported from (sigil core)
caarprocedurecadrprocedureGet the car of the cdr (second element): (car (cdr x)).
(cadr '(1 2 3)) ; => 2Re-exported from (sigil core)
cdarprocedurecddrprocedureGet the cdr of the cdr (tail after second): (cdr (cdr x)).
(cddr '(1 2 3 4)) ; => (3 4)Re-exported from (sigil core)
null?procedureTest if value is null
Re-exported from (sigil core)
list?procedureTest if value is a proper list
Re-exported from (sigil core)
listprocedureCreate a list from arguments
Re-exported from (sigil core)
make-listprocedureCreate 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)
lengthprocedureGet length of list or vector
Re-exported from (sigil core)
appendprocedureConcatenate 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)
reverseprocedureReverse 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-refprocedureRe-exported from (sigil core)
memqprocedureFind element in list using eq?
Re-exported from (sigil core)
memvprocedureFind element in list using eqv?
Re-exported from (sigil core)
memberprocedureFind element in list using equal?
Re-exported from (sigil core)
assqprocedureFind pair in alist using eq?
Re-exported from (sigil core)
assvprocedureFind pair in alist using eqv?
Re-exported from (sigil core)
assocprocedureFind pair in alist using equal?
Re-exported from (sigil core)
mapprocedureApply 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-eachprocedureApply 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?procedureTest if value is a symbol
Re-exported from (sigil core)
symbol->stringprocedureConvert symbol to string
Re-exported from (sigil core)
string->symbolprocedureConvert string to symbol
Re-exported from (sigil core)
number?procedureTest if value is a number
Re-exported from (sigil core)
integer?procedureTest if value is an integer
Re-exported from (sigil core)
exact-integer?procedureTest if value is an exact integer
Re-exported from (sigil math)
exact?procedureTest if number is exact
Re-exported from (sigil math)
inexact?procedureTest if number is inexact
Re-exported from (sigil math)
exactprocedureConvert to exact number
Re-exported from (sigil math)
inexactprocedureConvert to inexact number
Re-exported from (sigil math)
=procedureNumeric equality
Re-exported from (sigil core)
<procedureNumeric less than
Re-exported from (sigil core)
>procedureNumeric greater than
Re-exported from (sigil core)
<=procedureNumeric less than or equal
Re-exported from (sigil core)
>=procedureNumeric greater than or equal
Re-exported from (sigil core)
zero?procedureCheck if a number is zero.
(zero? 0) ; => #t
(zero? 1) ; => #f
(zero? -1) ; => #f
(zero? 0.0) ; => #tRe-exported from (sigil core)
positive?procedureCheck if a number is positive (greater than zero).
(positive? 5) ; => #t
(positive? 0) ; => #f
(positive? -3) ; => #f
(positive? 0.1) ; => #tRe-exported from (sigil core)
negative?procedureCheck if a number is negative (less than zero).
(negative? -5) ; => #t
(negative? 0) ; => #f
(negative? 3) ; => #f
(negative? -0.1) ; => #tRe-exported from (sigil core)
odd?procedureodd? - Test if an integer is odd (odd? 3) => #t (odd? 4) => #f
Re-exported from (sigil core)
even?procedureeven? - Test if an integer is even (even? 4) => #t (even? 3) => #f
Re-exported from (sigil core)
maxprocedureReturn maximum of arguments
Re-exported from (sigil math)
minprocedureReturn minimum of arguments
Re-exported from (sigil math)
+procedureAdd numbers
Re-exported from (sigil core)
-procedureSubtract numbers or negate
Re-exported from (sigil core)
*procedureMultiply numbers
Re-exported from (sigil core)
/procedureDivide numbers or reciprocal
Re-exported from (sigil core)
floorprocedureRound toward negative infinity
Re-exported from (sigil math)
ceilingprocedureRound toward positive infinity
Re-exported from (sigil math)
truncateprocedureRound toward zero
Re-exported from (sigil math)
roundprocedureRound to nearest integer
Re-exported from (sigil math)
quotientprocedureInteger division (truncate)
Re-exported from (sigil math)
gcdprocedureGreatest common divisor
Re-exported from (sigil math)
lcmprocedureLeast common multiple
Re-exported from (sigil math)
exptprocedureExponentiation (base^exponent)
Re-exported from (sigil math)
squareprocedureSquare of a number
Re-exported from (sigil math)
floor-quotientprocedureFloor division quotient
Re-exported from (sigil math)
floor-remainderprocedureFloor division remainder
Re-exported from (sigil math)
floor/procedureFloor division returning quotient and remainder
Re-exported from (sigil math)
truncate-quotientprocedureTruncating division quotient
Re-exported from (sigil math)
truncate-remainderprocedureTruncating division remainder
Re-exported from (sigil math)
truncate/procedureTruncating division returning quotient and remainder
Re-exported from (sigil math)
number->stringprocedureConvert number to string with optional radix
Re-exported from (sigil core)
string->numberprocedureParse string as number
Re-exported from (sigil core)
char?procedureTest if value is a character
Re-exported from (sigil core)
char=?procedureCharacter equality
Re-exported from (sigil core)
char<?procedureCharacter less-than
Re-exported from (sigil core)
char>?procedureCharacter greater-than
Re-exported from (sigil core)
char<=?procedureCharacter less-than-or-equal
Re-exported from (sigil core)
char>=?procedureCharacter greater-than-or-equal
Re-exported from (sigil core)
char->integerprocedureConvert character to code point
Re-exported from (sigil core)
integer->charprocedureConvert code point to character
Re-exported from (sigil core)
string?procedureTest if value is a string
Re-exported from (sigil core)
make-stringprocedureCreate 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)
stringprocedureCreate string from characters
Re-exported from (sigil core)
string-lengthprocedureGet string length
Re-exported from (sigil core)
string-refprocedureGet character at index
Re-exported from (sigil core)
string-set!procedureSet character at index in string
Re-exported from (sigil core)
string=?procedureString equality
Re-exported from (sigil core)
string<?procedureCompare strings lexicographically (less than).
Characters are compared by their Unicode code points.
(string<? "apple" "banana") ; => #t
(string<? "abc" "abd") ; => #t
(string<? "abc" "abc") ; => #fRe-exported from (sigil string)
string>?procedureCompare strings lexicographically (greater than).
(string>? "banana" "apple") ; => #t
(string>? "abc" "abc") ; => #fRe-exported from (sigil string)
string<=?procedureCompare strings lexicographically (less than or equal).
(string<=? "abc" "abd") ; => #t
(string<=? "abc" "abc") ; => #t
(string<=? "abd" "abc") ; => #fRe-exported from (sigil string)
string>=?procedureCompare strings lexicographically (greater than or equal).
(string>=? "abd" "abc") ; => #t
(string>=? "abc" "abc") ; => #t
(string>=? "abc" "abd") ; => #fRe-exported from (sigil string)
substringprocedureExtract substring
Re-exported from (sigil core)
string-appendprocedureConcatenate strings
Re-exported from (sigil core)
string-copyprocedureCopy 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!procedureRe-exported from (sigil core)
string-fill!procedureRe-exported from (sigil core)
string-upcaseprocedureConvert string to uppercase
Re-exported from (sigil core)
string-downcaseprocedureConvert string to lowercase
Re-exported from (sigil core)
string-foldcaseprocedureConvert string to foldcase
Re-exported from (sigil core)
string->listprocedureConvert string to list of characters
Re-exported from (sigil core)
list->stringprocedureConvert list of characters to string
Re-exported from (sigil core)
string-for-eachprocedureApply procedure to each character of a string for side effects. (string-for-each display "abc") displays abc
Re-exported from (sigil core)
string-mapprocedureApply procedure to each character, return string of results. (string-map char-upcase "abc") => "ABC"
Re-exported from (sigil core)
vector->stringprocedureConvert a vector of characters to a string. (vector->string #(#a #b #c)) => "abc"
Re-exported from (sigil core)
string->vectorprocedureConvert 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?procedureTest if value is a vector
Re-exported from (sigil core)
make-vectorprocedureCreate vector with optional fill
Re-exported from (sigil core)
vector-lengthprocedureGet vector length
Re-exported from (sigil core)
vector-refprocedureGet vector element at index
Re-exported from (sigil core)
vector-set!procedureSet vector element at index
Re-exported from (sigil core)
vector->listprocedureConvert 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->vectorprocedureConvert a list to a vector. (list->vector lst) -> vector
Re-exported from (sigil core)
vector-copyprocedureCopy 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!procedureRe-exported from (sigil core)
vector-fill!procedureFill 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)
vector-for-eachprocedureApply 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-mapprocedureApply 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?procedureTest if value is a bytevector
Re-exported from (sigil core)
make-bytevectorprocedureCreate bytevector of given size, optionally filled with a byte value
Re-exported from (sigil core)
bytevectorprocedureRe-exported from (sigil core)
bytevector-lengthprocedureGet bytevector length
Re-exported from (sigil core)
bytevector-u8-refprocedureGet byte at index
Re-exported from (sigil core)
bytevector-u8-set!procedureSet byte at index
Re-exported from (sigil core)
bytevector-copyprocedureCopy 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)
bytevector-copy!procedureRe-exported from (sigil core)
bytevector-appendprocedureAppend multiple bytevectors. (bytevector-append #u8(1 2) #u8(3 4)) => #u8(1 2 3 4)
Re-exported from (sigil core)
utf8->stringprocedureConvert UTF-8 bytevector to string
Re-exported from (sigil io)
string->utf8procedureConvert string to UTF-8 bytevector
Re-exported from (sigil io)
procedure?procedureTest if value is a procedure
Re-exported from (sigil core)
applyprocedureApply procedure to arguments
Re-exported from (sigil core)
valuesprocedureReturn multiple values
Re-exported from (sigil core)
call-with-valuesprocedureCall producer and pass values to consumer
Re-exported from (sigil core)
dynamic-windproceduredynamic-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)
errorprocedureConvenience function to raise an error exception. (error "message" irritant ...)
Re-exported from (sigil core)
error-object?procedureTest if a value is an error object (exception).
Re-exported from (sigil core)
error-object-messageprocedureGet the message from an error object.
Re-exported from (sigil core)
error-object-irritantsprocedureGet the irritants from an error object.
Re-exported from (sigil core)
error-object-typeprocedureGet the type/kind of an error object.
Re-exported from (sigil core)
file-error?procedureTest if an error is file-related.
Re-exported from (sigil core)
read-error?procedureTest if an error is read-related.
Re-exported from (sigil core)
raiseprocedureRaise 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-continuableprocedureRaise a continuable exception. The handler can return a value to continue execution.
Re-exported from (sigil core)
with-exception-handlerprocedureInstall 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?procedureTest if value is an input port
Re-exported from (sigil core)
output-port?procedureTest if value is an output port
Re-exported from (sigil core)
textual-port?procedureTest if port is textual
Re-exported from (sigil core)
binary-port?procedureTest if port is binary
Re-exported from (sigil core)
port?procedureTest if value is a port
Re-exported from (sigil core)
current-input-portvariableRe-exported from (sigil core)
current-output-portvariableRe-exported from (sigil core)
current-error-portvariableRe-exported from (sigil core)
close-portprocedureClose a port
Re-exported from (sigil core)
close-input-portprocedureClose an input port
Re-exported from (sigil core)
close-output-portprocedureClose an output port
Re-exported from (sigil core)
port-open?procedureTest if port is open
Re-exported from (sigil core)
open-input-stringprocedureCreate input port from string
Re-exported from (sigil io)
open-output-stringprocedureCreate output string port
Re-exported from (sigil io)
get-output-stringprocedureGet accumulated string from output string port
Re-exported from (sigil io)
flush-output-portprocedureFlush output port buffer
Re-exported from (sigil io)
read-charprocedureRead 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) ; => #\eRe-exported from (sigil io)
peek-charprocedureLook 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-lineprocedureRead 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-stringprocedureRead 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-u8procedureRead 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-u8procedureLook 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-u8procedureWrite 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-bytevectorprocedureRead 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-bytevector!procedureRead bytes into existing bytevector
Re-exported from (sigil io)
write-bytevectorprocedureWrite 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)
open-input-bytevectorprocedureCreate input port from bytevector
Re-exported from (sigil io)
open-output-bytevectorprocedureCreate output bytevector port
Re-exported from (sigil io)
get-output-bytevectorprocedureGet accumulated bytevector from output bytevector port
Re-exported from (sigil io)
char-ready?procedureCheck if character is available to read
Re-exported from (sigil io)
u8-ready?procedureCheck if byte is available to read
Re-exported from (sigil io)
write-charprocedureWrite a single character to a port.
(write-char #\A port)
(write-char #\newline port)Re-exported from (sigil io)
write-stringprocedureWrite 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)
newlineprocedurePrint newline to port
Re-exported from (sigil core)
eof-objectprocedureReturn the EOF object
Re-exported from (sigil core)
eof-object?procedureTest if value is EOF
Re-exported from (sigil core)
call-with-portprocedurecall-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)
make-parameterprocedureCreate a parameter object
Re-exported from (sigil core)
featuresprocedureReturn list of implementation feature identifiers
Re-exported from (sigil core)
define-record-typevariableRe-exported from (srfi srfi-9)