Guile Procedures
Guile Procedures
acons
Like `assq', `assv' and `assoc', except that only the value
associated with KEY in ALIST is returned. These functions are
equivalent to
Reassociate KEY in ALIST with VAL: find any existing ALIST entry
for KEY and associate it with the new VAL. If ALIST does not
contain an entry for KEY, add a new one. Return the (possibly new)
alist.
Delete the first entry in ALIST associated with KEY, and return the
resulting alist.
assv-remove!
ARRAY1, ... must have the same number of dimensions as RA0 and have
a range for each index which includes the range for the
corresponding index in RA0. PROC is applied to each tuple of
elements of ARRAY1, ... and the result is stored as the
corresponding element in RA0. The value returned is unspecified.
The order of application is unspecified.
array-for-each
Another example:
(define (apl:index-generator n)
(let ((v (make-uniform-vector n 1)))
(array-index-map! v (lambda (i) i))
v))
array-equal?
For example:
(array-slice-for-each 1
(lambda (xy angle)
(array-set! angle (atan (array-ref xy 1) (array-ref xy 0))))
xys angles)
array-slice-for-each-in-order
For example:
If KV is a bit vector, then those entries where it has `#t' are the
ones in V which are set to OBJ. V must be at least as long as KV.
When OBJ is `#t' it's like KV is OR'ed into V. Or when OBJ is `#f'
it can be seen as an ANDNOT.
(define bv #*01000010)
(bit-set*! bv #*10010001 #t)
bv
==> #*11010011
(define bv #*01000010)
(bit-set*! bv #u32(5 2 7) #t)
bv
==> #*01100111
bit-count*
If KV is a bit vector, then those entries where it has `#t' are the
ones in V which are considered. KV and V must be the same length.
For example,
Throws (such as errors) that are not caught from within PROC are
caught by `with-continuation-barrier'. In that case, a short
message is printed to the current error port and `#f' is returned.
(eq? x x) ==> #t
(eq? x y) ==> #f
Numbers and characters are not equal to any other object, but the
problem is they're not necessarily `eq?' to themselves either. This
is even so when the number comes directly from a variable,
- Variable: O_RDONLY
Open the file read-only.
- Variable: O_WRONLY
Open the file write-only.
- Variable: O_RDWR
Open the file read/write.
- Variable: O_APPEND
Append to the file instead of truncating.
- Variable: O_CREAT
Create the file if it does not already exist.
See the Unix documentation of the `open' system call for additional
flags.
close
stat:dev
The device containing the file.
stat:ino
The file serial number, which distinguishes this file from all
other files on the same device.
stat:mode
The mode of the file. This includes file type information and
the file permission bits. See `stat:type' and `stat:perms'
below.
stat:nlink
The number of hard links to the file.
stat:uid
The user ID of the file's owner.
stat:gid
The group ID of the file.
stat:rdev
Device ID; this entry is defined only for character or block
special files.
stat:size
The size of a regular file in bytes.
stat:atime
The last access time for the file.
stat:mtime
The last modification time for the file.
stat:ctime
The last modification time for the attributes of the file.
stat:blksize
The optimal block size for reading or writing the file, in
bytes.
stat:blocks
The amount of disk space that the file occupies measured in
units of 512 byte blocks.
stat:type
A symbol representing the type of file. Possible values are
regular, directory, symlink, block-special, char-special,
fifo, socket and unknown
stat:perms
An integer representing the access permission bits.
lstat
READS, WRITES and EXCEPTS can be lists or vectors, with each member
a port or a file descriptor. The value returned is a list of three
corresponding lists or vectors containing only the members which
meet the specified requirement. The ability of port buffers to
provide input or accept output is taken into account. Ordering of
the input lists or vectors is not preserved.
The optional arguments SECS and USECS specify the timeout. Either
SECS can be specified alone, as either an integer or a real number,
or both SECS and USECS can be specified as integers, in which case
USECS is an additional timeout expressed in microseconds. If SECS
is omitted or is `#f' then select will wait for as long as it takes
for one of the other conditions to be satisfied.
F_DUPFD
Duplicate a file descriptor
F_GETFD
Get flags associated with the file descriptor.
F_SETFD
Set flags associated with the file descriptor to VALUE.
F_GETFL
Get flags associated with the open file.
F_SETFL
Set flags associated with the open file to VALUE
F_GETOWN
Get the process ID of a socket's owner, for `SIGIO' signals.
F_SETOWN
Set the process that owns a socket to VALUE, for `SIGIO'
signals.
FD_CLOEXEC
The value used to indicate the "close on exec" flag with
`F_GETFL' or `F_SETFL'.
fsync
- Variable: R_OK
Test for read permission.
- Variable: W_OK
Test for write permission.
- Variable: X_OK
Test for execute permission.
- Variable: F_OK
Test for existence of the file. This is implied by each of
the other tests, so there's no need to combine it with them.
It's important to note that `access?' does not simply indicate what
will happen on attempting to read or write a file. In normal
circumstances it does, but in a set-UID or set-GID program it
doesn't because `access?' tests the real ID, whereas an open or
execute attempt uses the effective ID.
E.g., `(umask #o022)' sets the mask to octal 22, decimal 18.
mkstemp!
POSIX doesn't specify the permissions mode of the file, on GNU and
most systems it's `#o600'. An application can use `chmod' to relax
that if desired. For example `#o666' less `umask', which is usual
for ordinary file creation,
Given the foreign void pointer FUNC_PTR, its argument and return
types ARG_TYPES and RETURN_TYPE, return a procedure that will pass
arguments to the foreign function and return appropriate values.
r
Open an existing file for input.
w
Open a file for output, creating it if it doesn't already
exist or removing its contents if it does.
a
Open a file for output, creating it if it doesn't already
exist. All writes to the port will go to the end of the file.
The "append mode" can be turned off while the port is in use
see fcntl
b
Open the underlying file in binary mode, if supported by the
system. Also, open the file using the binary-compatible
character encoding "ISO-8859-1", ignoring the default port
encoding.
+
Open the port for both input and output. E.g., `r+': open an
existing file for both input and output.
0
Create an "unbuffered" port. In this case input and output
operations are passed directly to the underlying port
implementation without additional buffering. This is likely
to slow down I/O operations. The buffering mode can be
changed while a port is in use see setvbuf
l
Add line-buffering to the port. The port output buffer will
be automatically flushed whenever a newline character is
written.
- Scheme Procedure: gc
Scans all of SCM objects and reclaims for further use those that
are no longer accessible.
gettext
You can put a single object into a guardian more than once and you
can put a single object into more than one guardian. The object
will then be returned multiple times by the guardian procedures.
This procedure does not have any side effects on other ports or
revealed counts.
dup->fdes
Return the "tail" of LST beginning with its Kth element. The first
element of the list is considered to be element 0.
(remainder 13 4) ==> 1
(remainder -13 4) ==> -1
modulo
(modulo 13 4) ==> 1
(modulo -13 4) ==> 3
euclidean-quotient
(logand) ==> -1
(logand 7) ==> 7
(logand #b111 #b011 #b001) ==> 1
logior
(logior) ==> 0
(logior 7) ==> 7
(logior #b000 #b001 #b011) ==> 3
logxor
(logxor) ==> 0
(logxor 7) ==> 7
(logxor #b000 #b001 #b011) ==> 2
(logxor #b000 #b001 #b011 #b011) ==> 1
logtest
(modulo-expt 2 3 5)
==> 3
integer-expt
(integer-expt 2 5) ==> 32
(integer-expt -3 3) ==> -27
(integer-expt 5 -3) ==> 1/125
(integer-expt 0 0) ==> 1
ash
(logcount #b10101010)
==> 4
(logcount 0)
==> 0
(logcount -2)
==> 1
integer-length
(integer-length #b10101010)
==> 8
(integer-length 0)
==> 0
(integer-length #b1111)
==> 4
number->string
- Scheme Procedure: 1+ x
Return X+1.
-
- Scheme Procedure: 1- x
Return X-1.
*
See also close, for a procedure which can close file descriptors.
close-output-port
See also close, for a procedure which can close file descriptors.
specialize-port-encoding!
none
no buffering
line
line buffering
block
block buffering, using a newly allocated buffer of SIZE bytes.
If SIZE is omitted, a default size will be used.
- Variable: SEEK_SET
Seek from the beginning of the file.
- Variable: SEEK_CUR
Seek from the current position.
- Variable: SEEK_END
Seek from the end of the file.
The value returned is the new position in the file. This means
that the current position of a port can be obtained using:
The first line of a file is 0. But you might want to add 1 when
printing line numbers, since starting from 1 is traditional in
error messages, and likely to be more natural to non-programmers.
set-port-line!
For a case-lambda procedure, the arity returned is the one with the
lowest minimum number of arguments, and the highest maximum number
of arguments.
(delay EXP)
(make-promise (lambda () EXP))
force
* attempt to fill the entire string, unless the START and/or END
arguments are supplied. i.e., START defaults to 0 and END
defaults to `(string-length str)'
SIGNUM is the signal number, which can be specified using the value
of variables such as `SIGINT'.
The return value indicates the time remaining for the previous
alarm, if any. The new value replaces the previous alarm. If
there was no previous alarm, the return value is zero.
setitimer
The return value will be a list of two cons pairs representing the
current state of the given timer. The first pair is the seconds
and microseconds of the timer `it_interval', and the second pair is
the seconds and microseconds of the timer `it_value'. `ITIMER_PROF'
or `ITIMER_VIRTUAL' are not supported on some platforms and will
always error. `(provided? 'ITIMER_PROF)' and `(provided?
'ITIMER_VIRTUAL)' report whether those timers are supported.
getitimer
The return value will be a list of two cons pairs representing the
current state of the given timer. The first pair is the seconds
and microseconds of the timer `it_interval', and the second pair is
the seconds and microseconds of the timer `it_value'. `ITIMER_PROF'
or `ITIMER_VIRTUAL' are not supported on some platforms and will
always error. `(provided? 'ITIMER_PROF)' and `(provided?
'ITIMER_VIRTUAL)' report whether those timers are supported.
pause
The equality calls are always `(pred x elem)', ie.: the given X is
first. This means for instance elements greater than 5 can be
deleted with `(delete 5 lst <)'.
LST is not modified, but the returned list might share a common
tail with LST.
delete!
The equality calls are always `(pred x elem)', ie.: the given X is
first. This means for instance elements greater than 5 can be
deleted with `(delete 5 lst <)'.
When elements are equal, only the first in LST is retained. Equal
elements can be anywhere in LST, they don't have to be adjacent.
The returned list will have the retained elements in the same order
as they were in LST.
LST is not modified, but the return might share a common tail with
LST.
When elements are equal, only the first in LST is retained. Equal
elements can be anywhere in LST, they don't have to be adjacent.
The returned list will have the retained elements in the same order
as they were in LST.
The return is two values (see Multiple Values), the first being a
list of all elements from LST which satisfy PRED, the second a list
of those which do not.
The elements in the result lists are in the same order as in LST
but the order in which the calls `(PRED elem)' are made on the list
elements is unspecified.
infix
Insert the separator between list elements. An empty string
will produce an empty list.
strict-infix
Like `infix', but will raise an error if given the empty list.
suffix
Insert the separator after every list element.
prefix
Insert the separator before each list element.
string-copy
(string-upcase! y)
==> "ARRDEFG"
y
==> "ARRDEFG"
string-upcase
y
==> "ARRDEFG"
(string-downcase! y)
==> "arrdefg"
y
==> "arrdefg"
string-downcase
char-set
The char-set itself.
len
The number of character ranges the char-set contains
ranges
A list of lists where each sublist a range of code points and
their associated characters
log2-binary-factors
(log2-binary-factors 6) ==> 1
(log2-binary-factors -8) ==> 3
copy-bit
tms:clock
The current real time, expressed as time units relative to an
arbitrary base.
tms:utime
The CPU time units used by the calling process.
tms:stime
The CPU time units used by the system on behalf of the calling
process.
tms:cutime
The CPU time units used by terminated child processes of the
calling process, whose status has been collected (e.g., using
`waitpid').
tms:cstime
Similarly, the CPU times units used by the system on behalf of
terminated child processes.
get-internal-run-time
If `setlocale' has been called (see Locales), month and day names
are from the current locale and in the locale character set.
strptime
string
The string itself.
start
The start index of the string into its stringbuf
length
The length of the string
shared
If this string is a substring, it returns its parent string.
Otherwise, it returns `#f'
read-only
`#t' if the string is read-only
stringbuf-chars
A new string containing this string's stringbuf's characters
stringbuf-length
The number of characters in this stringbuf
stringbuf-mutable
`#t' if this stringbuf is mutable
stringbuf-wide
`#t' if this stringbuf's characters are stored in a 32-bit
buffer, or `#f' if they are stored in an 8-bit buffer
%symbol-dump
symbol
The symbol itself
hash
Its hash value
interned
`#t' if it is an interned symbol
stringbuf-chars
A new string containing this symbols's stringbuf's characters
stringbuf-length
The number of characters in this stringbuf
stringbuf-mutable
`#t' if this stringbuf is mutable
stringbuf-wide
`#t' if this stringbuf's characters are stored in a 32-bit
buffer, or `#f' if they are stored in an 8-bit buffer
string?
-43. (if present and not `#f') thunk for computing the number of
characters that can be read from the port without blocking.
You can modify weak hash tables in exactly the same way you would
modify regular hash tables. (see Hash Tables)
make-weak-value-hash-table
Return `#t' if OBJ is the specified weak hash table. Note that a
doubly weak hash table is neither a weak key nor a weak value hash
table.
weak-value-hash-table?
Generally only the superuser can set the process group IDs.
getpw
`getrlimit' returns two values, the soft and the hard limit. If no
limit is set for the resource in question, the returned limit will
be `#f'.
setrlimit
PID equal to 0
All processes in the current process group.
PID equal to -1
If the process is privileged, all processes except for some
special system processes. Otherwise, all processes with the
current effective user ID.
- Variable: SIGHUP
Hang-up signal.
- Variable: SIGINT
Interrupt signal.
waitpid
- Variable: WNOHANG
Return immediately even if there are no child processes to be
collected.
- Variable: WUNTRACED
Report status information for stopped processes as well as
terminated processes.
will set the access time to one hour in the past and the
modification time to the current time.
E.g.,
- Variable: LOCK_SH
Shared lock. More than one process may hold a shared lock for
a given file at a given time.
- Variable: LOCK_EX
Exclusive lock. Only one process may hold an exclusive lock
for a given file at a given time.
- Variable: LOCK_UN
Unlock the file.
- Variable: LOCK_NB
Don't block when locking. This is combined with one of the
other operations using `logior'. If `flock' would block an
`EWOULDBLOCK' error is thrown.
AI_PASSIVE
Socket address is intended for `bind'.
AI_CANONNAME
Request for canonical host name, available via
`addrinfo:canonname'. This makes sense mainly when DNS
lookups are involved.
AI_NUMERICHOST
Specifies that NAME is a numeric host address string (e.g.,
`"127.0.0.1"'), meaning that name resolution will not be used.
AI_NUMERICSERV
Likewise, specifies that SERVICE is a numeric port string
(e.g., `"80"').
AI_ADDRCONFIG
Return only addresses configured on the local system. It is
highly recommended to provide this flag when the returned
socket addresses are to be used to make connections;
otherwise, some of the returned addresses could be unreachable
or use a protocol that is not supported.
AI_V4MAPPED
When looking up IPv6 addresses, return mapped IPv4 addresses
if there is no IPv6 address available at all.
AI_ALL
If this flag is set along with `AI_V4MAPPED' when looking up
IPv6 addresses, return all IPv6 addresses as well as all IPv4
addresses, the latter mapped to IPv6 format.
(catch 'getaddrinfo-error
(lambda ()
(getaddrinfo "www.gnu.org" "gopher"))
(lambda (key errcode)
(cond ((= errcode EAI_SERVICE)
(display "doesn't know about Gopher!\n"))
((= errcode EAI_NONAME)
(display "www.gnu.org not found\n"))
(else
(format #t "something wrong: ~a\n"
(gai-strerror errcode))))))
EAI_AGAIN
The name or service could not be resolved at this time. Future
attempts may succeed.
EAI_BADFLAGS
HINT_FLAGS contains an invalid value.
EAI_FAIL
A non-recoverable error occurred when attempting to resolve
the name.
EAI_FAMILY
HINT_FAMILY was not recognized.
EAI_NONAME
Either NAME does not resolve for the supplied parameters, or
neither NAME nor SERVICE were supplied.
EAI_NODATA
This non-POSIX error code can be returned on some systems (GNU
and Darwin, at least), for example when NAME is known but
requests that were made turned out no data. Error handling
code should be prepared to handle it when it is defined.
EAI_SERVICE
SERVICE was not recognized for the specified socket type.
EAI_SOCKTYPE
HINT_SOCKTYPE was not recognized.
EAI_SYSTEM
A system error occurred. In C, the error code can be found in
`errno'; this value is not accessible from Scheme, but in
practice it provides little information about the actual error
cause.
- Variable: SOL_SOCKET
- Variable: SO_DEBUG
- Variable: SO_LINGER
The value returned is a pair of integers `(ENABLE . TIMEOUT)'.
On old systems without timeout support (ie.: without `struct
linger'), only ENABLE has an effect but the value in Guile is
always a pair.
setsockopt
- Variable: SOL_SOCKET
- Variable: SO_DEBUG
VALUE is an integer.
- Variable: SO_LINGER
VALUE is a pair of integers `(ENABLE . TIMEOUT)'. On old
systems without timeout support (ie.: without `struct
linger'), only ENABLE has an effect but the value in Guile is
always a pair.
For IP level (`IPPROTO_IP') the following OPTNAMEs are defined
(when provided by the system). See `man ip' for what they mean.
- Variable: IP_MULTICAST_IF
This sets the source interface used by multicast traffic.
- Variable: IP_MULTICAST_TTL
This sets the default TTL for multicast traffic. This
defaults to 1 and should be increased to allow traffic to pass
beyond the local network.
- Variable: IP_ADD_MEMBERSHIP
0
Stop receiving data for this socket. If further data arrives,
reject it.
1
Stop trying to transmit data from this socket. Discard any
data waiting to be sent. Stop looking for acknowledgement of
data already sent; don't retransmit it if it is lost.
2
Stop both reception and transmission.
The format of ADDRESS and ARGS depends on the family of the socket.
The values of the following variables can also be used for ADDRESS:
- Variable: INADDR_ANY
Allow connections from any address.
- Variable: INADDR_LOOPBACK
The address of the local host using the loopback device.
- Variable: INADDR_BROADCAST
The broadcast address on the local network.
- Variable: INADDR_NONE
No address.
SOCK does not become part of the connection and will continue to
accept new requests.
getsockname
The value returned is the number of bytes read from the socket.
Note that the data is read directly from the socket file
descriptor: any unread buffered port data is ignored.
send
The return value is a pair. The `car' is the number of bytes read.
The `cdr' is a socket address object which is where the data came
from, or `#f' if the origin is unknown.
Data is read directly from the socket file descriptor, any buffered
port data is ignored.
regexp/icase
Consider uppercase and lowercase letters to be the same when
matching.
regexp/newline
If a newline appears in the target string, then permit the `^'
and `$' operators to match immediately after or immediately
before the newline, respectively. Also, the `.' and `[^...]'
operators will never match a newline character. The intent of
this flag is to treat the target string as a buffer containing
many lines of text, and the regular expression as a pattern
that may match a single one of those lines.
regexp/basic
Compile a basic (``obsolete'') regexp instead of the extended
(``modern'') regexps that are the default. Basic regexps do
not consider `|', `+' or `?' to be special characters, and
require the `{...}' and `(...)' metacharacters to be
backslash-escaped (see Backslash Escapes). There are several
other differences between basic and extended regular
expressions, but these are the most significant.
regexp/extended
Compile an extended regular expression rather than a basic
regexp. This is the default behavior; this flag will not
usually be needed. If a call to `make-regexp' includes both
`regexp/basic' and `regexp/extended' flags, the one which
comes last will override the earlier one.
regexp-exec
regexp/notbol
Operator `^' always fails (unless `regexp/newline' is used).
Use this when the beginning of the string should not be
considered the beginning of a line.
regexp/noteol
Operator `$' always fails (unless `regexp/newline' is used).
Use this when the end of the string should not be considered
the end of a line.