R7RS libraries

Sagittarius supports all R7RS libraries. However to avoid duplication, this section only describes the different procedures from R6RS. The same procedures are explicitly said 'the same as R6RS'.

Base library

[R7RS]R7RS base library.

These procedures/macros are the same as R6RS;

 * + - ... / < <= = => > >= 

 abs and append apply assoc assq assv 

 begin binary-port? boolean=? boolean? 
 bytevector-copy bytevector-length bytevector-u8-ref
 bytevector-u8-set! bytevector?

 caar cadr call-with-current-continuation call-with-port
 call-with-values call/cc car case cdar cddr cdr ceiling
 char->integer char<=? char<? char=? char>=? char>? char?
 close-input-port close-output-port close-port complex?
 cond cons current-error-port current-input-port current-output-port
 
 define define-record-type define-syntax denominator do dynamic-wind

 else eof-object eof-object? eq? eqv? error even?
 exact exact-integer-sqrt exact? expt

 floor flush-output-port for-each

 gcd guard

 if inexact inexact? input-port? integer->char integer?

 lambda lcm length let let* let*-values let-values
 letrec letrec* list list->string list->vector
 list-ref list-tail list?

 make-bytevector make-string make-vector map max member memq memv min
 modulo

 negative? newline not null? number->string number? numerator

 odd? or output-port?

 pair? peek-char port? positive? procedure?

 quasiquote quote quotient

 raise raise-continuable rational? rationalize
 read-char real? remainder reverse round

 set! set-car! set-cdr!
 string string->list string->number string->symbol string->utf8
 string-append string-copy string-for-each string-length string-ref
 string-fill! string-set!
 string<=? string<? string=? string>=? string>? string? substring
 symbol->string symbol=? symbol? syntax-rules

 textual-port? truncate 

 unless unquote unquote-splicing utf8->string

 values vector vector->list vector-fill! vector-for-each vector-length
 vector-map vector-ref vector-set! vector? 

 when with-exception-handler write-char 

 zero?

This is defined in (sagittarius);

cond-expand

Bytevectors

bytes must be a list of non negative exact integer and its value is up to 255.

Creates a bytevector whose content is values of bytes.

Returns a newly allocated bytevector whose contents are the concatenation of the contents in bytevectors.

NOTE: R6RS also has the same named procedure and does the same however the arguments lists are different.

to and from must be bytevectors. at must be a non negative exact integer in range of to size. Optional arguments start and end must be non negative exact integer in range of from and end must be bigger than end.

Copies content of from starting from start until end (exclusive) to to starting at. The operation is done destructively.

Lists

Returns a newly allocated copy of obj if it is a list. The list elements stays intact. So changing element's content affects original obj.

Stores value in element index of list.

Creates a list whose size is k.

If the optional argument fill is given then returning list is filled with fill, otherwise unspecified value is used.

Vectors

vector must be a vector whose elements of range from _start_to end (exclusive) are characters.

Returns a string constructed with the above range of characters.

Returns a vector whose elements are characters of string in range of start and end (exclusive).

Returns a newly allocated vector whose contents are the concatenation of the contents in vectors.

Returns a vector whose elements are elements of given _vector_between start and end.

to and from must be vectors. at must be a non negative exact integer in range of to size. Optional arguments start and end must be non negative exact integer in range of from and end must be bigger than end.

Copies content of from starting from start until end (exclusive) to to starting at. The operation is done destructively.

Strings

to and from must be strings. at must be a non negative exact integer in range of to size. Optional arguments start and end must be non negative exact integer in range of from and end must be bigger than end.

Copies content of from starting from start until end (exclusive) to to starting at. The operation is done destructively.

Calls proc with given strings elements and returns a string whose content is constructed by the results of proc.

Parameters

[SRFI-39] Returns a parameter object, which is an applicable object that can take zero or one argument.

The initial value is (_converter_ _init_) if _converter_is given, otherwise init.

If the parameter object is applied without an argument, then it returns the value associated with the parameter object.

If the parameter object is applied with an argument, then it changes the associated value with the given value which may converted by _converter_if the parameter object is created with converter.

[SRFI-39] A parameterize expression is used to change the values returned by specified parameter objects during the evaluation of body.

Inclusion

files must be strings.

Includes files as if it's written there. include-ci reads files case insensitively.

Multiple-value definition

expression is evaluated and the formals are bound to the return values in the same way that the formals in lambdaexpression are matched to the arguments in a procedure call.

Numerical operations

Returns #t if obj is exact integer. Otherwise #f.

These procedures implement number-theoretic (integer) division. It is an error if n2 is zero.

The procedure ending / returns two integers; the other procedures return an integer. All the procedures compute a quotient nq and remainder nr such that _n1_ = _n2_*_nq_ + _nr_. for each of the division operators, there are three procedures defined as follows;

(<operator>/ _n1_ _n2_)
nq nr

(<operator>-quotient _n1_ _n2_)
nq

(<operator>-remainder _n1_ _n2_)
nr

The remainder nr is determined by the choice of integer _nq_:_nr_ = _n1_ - _n2_*_nq_. Each set of operations uses a different choice of nq:

floor: _nq_ = [_n1_/_n2_]``truncate: _nq_ = truncate(_n1_/_n2_)Examples;

(floor/ 5 2)
2 1

(floor/ -5 2)
-3 1

(floor/ 5 -2)
-3 -1

(floor/ -5 -2)
2 -1

(truncate/ 5 2)
2 1

(truncate/ -5 2)
-2 -1

(truncate/ 5 -2)
-2 1

(truncate/ -5 -2)
2 -1

(truncate/ -5.0 -2)
2.0 -1.0

Function square z

Returns the square of z.

Error objects

Raises an &syntax with syntax-violation.

The macro is defined like this;

(define-syntax syntax-error
  (syntax-rules ()
    ((_ msg args ...)
     (syntax-violation 'syntax-error msg (quote args ...)))))

Returns #t if obj is condition object. This is a renaming exported procedure of consition?.

Returns irritants if the given err satisfies irritants-condition?. Otherwise #f.

Returns error message if the given err satisfies message-condition?. Otherwise #f.

I/O

Returns #t if obj is a file related condition, otherwise #f.

Renaming export of i/o-read-error?.

Return #t if given input-port or output-port is open, respectively. Otherwise #f.

Renaming export of port-ready?.

input-port must be a binary input port.

Peeks or reads a byte from given input-port.

input-port must be a binary input port.

Reads len from input-port and returns a bytevector.

_ _ _ (start 0) (end (bytevector-length bv))

input-port must be a binary input port.

Reads end - start size of data from input-port and put it into bv from start index.

u8 must be a byte. output-port must be a binary output port.

Writes u8 to output-port.

_ _ _ (start 0) (end (bytevector-length bv))

output-port must be a binary output port.

Writes bv from start to end (exclusive) to output-port.

input-port must be a textual input port.

Reads line from input-port. For convenience, \n, \rand \r\n are considered end of line.

input-port must be a textual input port.

Reads k length of string from input-port.

_ _ _ (start 0) (end (string-length str))

output-port must be a binary output port.

Writes bv from start to end (exclusive) to output-port.

Returns binary or textual input port whose source is _bv_or string, respectively.

Returns binary or textual output port. The port is opened on memory.

Retrieves buffered bytevector or string from given output-ports, respectively.

System interface

Function features

Returns a list of the feature identifiers which cond-expandtreas as true.

Differ from R6RS

The following procedures or macros are re-defined to strictly follow either R6RS or R7RS. It is users' responsibility to make sure proper ones are used in their script.

Function equal? a b

Returns #t if a and b are equivalent.

The difference between the one from (rnrs base) is that this procedure inspect record fields as well. For example:

(import (rnrs))
(define-record-type (<pare> kons pare?)
  (fields (mutable a kar set-kar!)
	  (mutable d kdr set-kdr!)))

(let ((a (kons 'a 'b))
      (b (kons 'a 'b)))
  (equal? a b))
(import (scheme base))
(define-record-type (<pare> kons pare?)
  (fields (mutable a kar set-kar!)
	  (mutable d kdr set-kdr!)))

(let ((a (kons 'a 'b))
      (b (kons 'a 'b)))
  (equal? a b))
#t

Binds macro transformer trans to var.

The difference between the one from (rnrs base) and these macros is that these macro create scope. Thus the following is unbound variable error:

(import (scheme base))
(let-syntax ()
  (define foo 'foo))
foo
&undefined

Case-lambda library

[R7RS] This library exports the case-lambda syntax.

Exported macro is the same as R6RS;

case-lambda

Char library

[R7RS]This library exports procedures for dealing with Unicode character operations.

These procedures are the same as R6RS;

 char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>?
 char-downcase char-foldcase char-lower-case? char-numeric? char-upcase
 char-upper-case? char-whitespace? string-ci<=? string-ci<?
 string-ci=? string-ci>=? string-ci>? string-downcase string-foldcase
 string-upcase

[R7RS+] Converts given character to it's numeric value. If the given character does not have numeric value, then it returns #f.

This procedure is extended from R7RS definition.

(digit-value #\1)
1

(digit-value #\x0664)
4

(digit-value #\x0EA6)
#f

(digit-value #\xbc)
1/4

(digit-value #\xbf0)
10

Complex library

[R7RS]This library exports procedures for complex numbers.

These procedures are the same as R6RS;

angle imag-part magnitude make-polar make-rectangular real-part

CxR library

[R7RS]This library exports twenty-four procedures which are the compositions of from three to four car and cdr operations.

These procedures are the same as R6RS;

caaaar caaadr
caaar caadar
caaddr caadr
cadaar cadadr
cadar caddar
cadddr caddr
cdaaar cdaadr
cdaar cdadar
cdaddr cdadr
cddaar cddadr
cddar cdddar
cddddr cdddr

Eval library

[R7RS]This library exports exports procedures for evaluating Scheme data as programs.

These procedures are the same as R6RS;

environment eval

File library

[R7RS]This library exports procedures for accessing files.

These procedures are the same as R6RS;

 call-with-input-file call-with-output-file
 delete-file file-exists?
 open-input-file open-output-file
 with-input-from-file with-output-to-file

Returns file binary input or output port associated with given file, respectively.

Inexact library

[R7RS]This library exports procedures for inexact value.

These procedures are the same as R6RS;

acos asin atan cos exp finite? infinite? log nan? sin sqrt tan

Lazy library

[R7RS]This library exports procedures and syntax keywords for lazy evaluation.

These procedures/macros are the same as R6RS;

delay force make-promise promise?

The expression (delay-force _expression_) is conceptually similar to (delay (force _expression_)), with the difference that forcing the result of delay-force will in effect result in a tail call to (force _expression_), while forcing the result of (delay (force _expression_)) might not.

Load library

[R7RS]This library exports procedures for loading Scheme expressions from files.

Reads expression in file and evaluates it until it gets to end of file. If environment is passed, then the evaluation is done in that environment. Otherwise it is done in current environment.

Process-Context library

[R7RS] This library exports procedures for accessing with the program's calling context.

These procedures are the same as R6RS; command-line exit

Exist process without any cleanup. The optional argument _obj_is given then it's translated to proper return value of the process.

name must be a string.

Retrieves environment variable associated to name.

Returns alist of environment variables.

Read library

[R7RS]This library exports procedures for reading Scheme objects.

Renaming export of read/ss.

Repl library

[R7RS]This library library exports the interaction-environment procedure.

Returns interaction environment.

Time library

[R7RS]This library provides access to time-related values.

Returns the number of jiffies as an exact integer.

Returns an exact integer representing the number of jiffies per SI second.

Returns an inexact number representing the current time on International Atomic Time (TAI) scale.

Write library

[R7RS]This library exports procedures for writing Scheme objects.

This procedures is the same as R6RS display

Writes a representation of obj to output-port.

If the obj contains cyclic, the procedure writes with datum label.

Renaming export of write/ss and write, respectively.

R5RS library

[R7RS]The (scheme r5rs) library provides the identifiers defined by R5RS, except that transcript-on and transcript-off are not present. Note that the exact and inexact procedures appear under their R5RS names inexact->exact and exact->inexact respectively. However, if an implementation does not provide a particular library such as the complex library, the corresponding identifiers will not appear in this library either. This library exports procedures for writing Scheme objects.