A Racket value is represented by a pointer-sized value. The low bit is
a mark bit: a 1 in the low bit indicates an immediate integer, a 0
indicates a (word-aligned) pointer.
For most Racket types, a constructor is provided for creating values
of the type. For example, scheme_make_pair takes two
Scheme_Object* values and returns the cons of the
values.
Racket values should never be allocated on the stack, and they should
never contain pointers to values on the stack. Besides the problem of
restricting the value’s lifetime to that of the stack frame,
allocating values on the stack creates problems for continuations and
threads, both of which copy into and out of the stack.
11.4 Value Functions🔗ℹ
Returns the character value. The ch value must be a legal
Unicode code point (and not a surrogate, for example). The first 256
characters are represented by constant Racket values, and others are
allocated.
Like
scheme_make_char, but the result is
NULL if
ch
is not a legal Unicode code point.
Returns the character value. This is a macro that directly accesses
the array of constant characters when ch is less than 256.
Returns the character value, assuming that ch is less than 256. (This is a macro.)
Returns the integer value; i must fit in a fixnum. (This is a macro.)
Returns the integer value. If i does not fit in a fixnum,
a bignum is returned.
Creates an integer given the high and low
intptr_ts of a signed
integer. Note that on 64-bit platforms where
long long is the
same as
intptr_t, the resulting integer has 128 bits. (See also
Racket BC Integers.)
Creates an integer given the high and low intptr_ts of an unsigned
integer. Note that on 64-bit platforms where long long is the
same as intptr_t, the resulting integer has 128 bits.
Extracts the integer value. Unlike the
SCHEME_INT_VAL macro,
this procedure will extract an integer that fits in a
intptr_t from
a Racket bignum. If
o fits in a
intptr_t, the extracted
integer is placed in
*i and 1 is returned; otherwise, 0 is
returned and
*i is unmodified.
Creates a new floating-point value.
Creates a new single-precision floating-point value. The procedure is
available only when Racket is compiled with single-precision
numbers enabled.
Converts a Racket real number to a double-precision floating-point
value.
Makes a Racket byte string from a nul-terminated C string. The
bytes string is copied.
Makes a byte string value with size len. A copy of bytes
is made if copy is not 0. The string bytes should
contain len bytes; bytes can contain the nul byte at any
position, and need not be nul-terminated if copy is
non-zero. However, if len is negative, then the nul-terminated
length of bytes is used for the length, and if copy is
zero, then bytes must be nul-terminated.
Allocates a new Racket byte string.
Creates a new byte string by appending the two given byte strings.
Makes a Racket string from a nul-terminated byte string that is a
locale-specific encoding of a character string; a new string is
allocated during decoding. The “locale in the name of this function
thus refers to bytes, and not the resulting string (which is
internally stored as UCS-4).
Makes a Racket string from a nul-terminated byte string that is a
UTF-8 encoding. A new string is allocated during decoding. The
“utf8” in the name of this function thus refers to bytes, and
not the resulting string (which is internally stored as UCS-4).
Makes a string value, based on len UTF-8-encoding bytes (so the
resulting string is len characters or less). The string
bytes should contain at least len bytes; bytes can
contain the nul byte at any position, and need not be
null-terminated. However, if len is negative, then the
nul-terminated length of bytes is used for the length.
Makes a Racket string from a nul-terminated UCS-4 string. The
chars string is copied.
Makes a string value with size len. A copy of chars is
made if copy is not 0. The string chars should
contain len characters; chars can contain the nul
character at any position, and need not be nul-terminated
if copy is non-zero. However, if len is negative, then
the nul-terminated length of chars is used for the length, and
if copy is zero, then the chars must be nul-terminated.
Allocates a new Racket string.
Creates a new string by appending the two given strings.
Converts a Racket character string into a Racket byte string via UTF-8.
Converts a Racket byte string into a Racket character string via UTF-8.
Converts a Racket character string into a Racket byte string via the locale’s encoding.
Converts a Racket byte string into a Racket character string via the locale’s encoding.
Finds (or creates) the symbol matching the given nul-terminated, ASCII
string (not UTF-8). The case of
name is (non-destructively) normalized
before interning if
scheme_case_sensitive is 0.
Creates or finds a symbol given the symbol’s length in UTF-8-encoding
bytes. The case of name is not normalized.
Creates an uninterned symbol from a nul-terminated, UTF-8-encoding
string. The case is not normalized.
Creates an uninterned symbol given the symbol’s length in
UTF-8-encoded bytes.
Creates or finds a keyword given the keywords length in UTF-8-encoding
bytes. The case of name is not normalized, and it should
not include the leading hash and colon of the keyword’s printed form.
Allocates a new vector.
Allocates an uninitialized flvector.
The result type is effectively an alias for Scheme_Object*.
Allocates an uninitialized fxvector.
The result type is effectively an alias for Scheme_Object*.
Creates a new box containing the value v.
Creates a new weak box containing the value v.
Creates a new type (not a Racket value). The type tag is valid across
all
places.
Creates a C-pointer object that encapsulates
ptr and uses
typetag to identify the type of the pointer. The
SCHEME_CPTRP macro recognizes objects created by
scheme_make_cptr. The
SCHEME_CPTR_VAL macro extracts
the original
ptr from the Racket object, and
SCHEME_CPTR_TYPE extracts the type tag.
The
SCHEME_CPTR_OFFSETVAL macro returns
0
for the result Racket object.
The ptr can refer to either memory managed by the garbage
collector or by some other memory manager. Beware, however, of
retaining a ptr that refers to memory released by another
memory manager, since the enclosing memory range might later become
managed by the garbage collector (in which case ptr might
become an invalid pointer that can crash the garbage collector).
Like
scheme_make_cptr, but
ptr is never treated as
referencing memory managed by the garbage collector.
Creates a C-pointer object that encapsulates both ptr and offset.
The SCHEME_CPTR_OFFSETVAL macro returns offset
for the result Racket object (and the macro be used to change the offset,
since it also works on objects with no offset).
The ptr can refer to either memory managed by the garbage
collector or by some other memory manager; see also
scheme_make_cptr.
Installs a printer to be used for printing (or writing or displaying)
values that have the type tag type.
The type of printer is defined as follows:
typedef void (*Scheme_Type_Printer)(Scheme_Object *v, int dis, |
Scheme_Print_Params *pp); |
Such a printer must print a representation of the value using
scheme_print_bytes and scheme_print_string. The
first argument to the printer, v, is the value to be printed.
The second argument indicates whether v is printed via
write or display. The last argument is to be passed
on to scheme_print_bytes or scheme_print_string to
identify the printing context.
Writes the content of
str —
starting from
offset and
running
len bytes —
into a printing context determined by
pp. This function is for use by a printer that is installed
with
scheme_set_type_printer.
Writes the content of
str —
starting from
offset and
running
len characters —
into a printing context determined
by
pp. This function is for use by a printer that is installed
with
scheme_set_type_printer.
void | | scheme_set_type_equality | ( | Scheme_Type type, | | | | | Scheme_Equal_Proc equalp, | | | | | Scheme_Primary_Hash_Proc hash1, | | | | | Scheme_Secondary_Hash_Proc hash2) |
|
Installs an equality predicate and associated hash functions for
values that have the type tag type. The equalp predicate
is only applied to values that both have tag type.
The type of equalp, hash1, and hash2 are defined as
follows:
typedef int (*Scheme_Equal_Proc)(Scheme_Object* obj1, |
Scheme_Object* obj2, |
void* cycle_data); |
typedef intptr_t (*Scheme_Primary_Hash_Proc)(Scheme_Object* obj, |
intptr_t base, |
void* cycle_data); |
typedef intptr_t (*Scheme_Secondary_Hash_Proc)(Scheme_Object* obj, |
void* cycle_data); |
The two hash functions are used to generate primary and secondary keys
for double hashing in an equal?-based hash table. The result
of the primary-key function should depend on both obj and
base.
The cycle_data argument in each case allows checking and hashing
on cyclic values. It is intended for use in recursive checking or
hashing via scheme_recur_equal,
scheme_recur_equal_hash_key, and
scheme_recur_equal_hash_key. That is, do not call plain
scheme_equal, scheme_equal_hash_key, or
scheme_equal_hash_key for recursive checking or hashing on
sub-elements of the given value(s).