LIBFTH(3) | Library Functions Manual | LIBFTH(3) |
libfth
—
#include <fth.h>
% cat hello.c #include <fth.h> int main(int argc, char *argv[]) { fth_init(); fth_printf("%s, World%c\n", "Hello", '!'); return (EXIT_SUCCESS); }
% cc -I/usr/local/include/fth -c
hello.c
% cc hello.o -o hello
-L/usr/local/lib -lfth -lm
% ./hello ⇒ Hello,
World!
% cat libhello.c #include <fth.h> /* * hello-prim ( str1 -- str2 ) * intro hello-prim ⇒ "Hello, World!" */ static void ficl_hello_primitive(ficlVm *vm) { FTH intro, world, result; FTH_STACK_CHECK(vm, 1, 1); intro = fth_pop_ficl_cell(vm); world = fth_variable_ref("world"); result = fth_make_string_format("%S, %S!", intro, world); fth_push_ficl_cell(vm, result); } /* * hello-proc ( str1 -- str2 ) * intro hello-proc ⇒ "Hello, World!" */ static FTH fth_hello_procedure(FTH intro) { FTH world, result; world = fth_variable_ref("world"); result = fth_make_string_format("%S, %S!", intro, world); return (result); } void Init_libhello(void) { fth_define_variable("intro", fth_make_string("Hello"), NULL); fth_define_constant("world", fth_make_string("World"), NULL); FTH_PRI1("hello-prim", ficl_hello_primitive, NULL); FTH_PROC("hello-proc", fth_hello_procedure, 1, 0, 0, NULL); }
% cc -fPIC -I/usr/local/include/fth
-c libhello.c
% cc -shared -o libhello.so
libhello.o -L/usr/local/lib -lfth -lm
fth
and load the new library with
dl-load ./libhello.so
Init_libhello
fth
and load the library direct from the
command line
% fth -S "./libhello.so
Init_libhello"
hello-prim
and
hello-proc
as well as the variable
intro
and the constant world
are available. In the following, ‘%
’ is
the shell prompt and ‘ok
’ is the forth
prompt
% fth -Qq ok dl-load ./libhello.so Init_libhello ok intro hello-prim ⇒ "Hello, World!" ok intro hello-proc ⇒ "Hello, World!" ok "Goodbye" to intro ok intro hello-prim ⇒ "Goodbye, World!" ok "Bye" hello-proc ⇒ "Bye, World!" ok bye %
% fth -S "./libhello.so Init_libhello" \ -e 'intro hello-prim . cr' \ -e 'intro hello-proc . cr' \ -e '"Goodbye" to intro' \ -e 'intro hello-prim . cr' \ -e '"Bye" hello-proc . cr'
% fth -ve "install
libhello.so" -e ""
dl-load libhello
Init_libhello
FTH ary = fth_make_array_var(2, FTH_ZERO, FTH_ONE); fth_array_length(ary); ⇒ 2 fth_array_ref(ary, 0); ⇒ 0 fth_array_push(ary, FTH_TWO); ⇒ #( 0 1 2 ) fth_array_length(ary); ⇒ 3 fth_array_shift(ary); ⇒ 0 fth_array_shift(ary); ⇒ 1 fth_array_shift(ary); ⇒ 2 fth_array_length(ary); ⇒ 0 FTH ary_each(FTH val, FTH data, ficlIndex idx) { return (fth_string_sformat(data, "array[%d]: %S\n", idx, val)); } FTH ary_map(FTH val, FTH data) { return (fth_number_mul(val, data)); } ary = fth_make_array_var(3, FTH_ZERO, FTH_ONE, FTH_TWO); fth_array_each_with_index(ary, ary_each, fth_make_empty_string()); ⇒ "array[0]: 0\n ..." fth_array_map(ary, ary_map, INT_TO_FIX(10)); ⇒ #( 0 10 20 )
FTH_ARRAY_P
(obj)fth_array_append
(FTH array1,
FTH array2)fth_array_clear
(FTH
array)fth_array_compact
(FTH
array)fth_array_copy
(FTH array)fth_array_delete
(FTH array,
ficlInteger index)fth_array_delete_key
(FTH
array, FTH key)fth_array_each
(FTH array,
FTH (*func)(FTH value, FTH data), FTH
data)/* * #( 0 1 ) value ary * each { val } * "%s\n" #( val ) fth-print * end-each */ static FTH ary_each(FTH val, FTH data) { fth_printf("%S\n", val); return (data); } fth_array_each(hs, ary_each, FTH_NIL);
fth_array_each_with_index
(FTH
array, FTH (*func)(FTH value, FTH data, ficlInteger
idx), FTH data)/* * #( 0 1 ) value ary * each { val } * "%d: %s\n" #( i val ) fth-print * end-each */ static FTH ary_each(FTH val, FTH data, ficlInteger idx) { fth_printf("%d: %S\n", idx, val); return (data); } fth_array_each_with_index(hs, ary_each, FTH_NIL);
fth_array_equal_p
(FTH obj1,
FTH obj2)fth_array_fill
(FTH array,
FTH value)fth_array_find
(FTH array,
FTH key)fth_array_index
(FTH array,
FTH key)fth_array_insert
(FTH array,
ficlInteger index, FTH
value)fth_array_join
(FTH array,
FTH sep)fth_array_length
(FTH obj)fth_array_map
(FTH array,
FTH (*func)(FTH value, FTH data), FTH
data)/* * #( 0 1 ) map * *key* 10 + * end-map ⇒ #( 10 11 ) */ static FTH ary_map(FTH val, FTH data) { return (fth_number_add(val, data)); } fth_array_map(ary, ary_map, INT_TO_FIX(10)); ⇒ #( 10 11 )
fth_array_member_p
(FTH array,
FTH key)fth_array_pop
(FTH array)fth_array_push
(FTH array,
FTH value)fth_array_ref
(FTH array,
ficlInteger index)fth_array_reject
(FTH array,
FTH proc_or_xt, FTH args)/* * #( 0 1 2 3 4 ) lambda: <{ n1 n2 -- f }> * n1 n2 > * ; #( 2 ) array-reject! ⇒ #( 0 1 2 ) * \ or a bit shorter: * #( 0 1 2 3 4 ) <'> > 2 array-reject! ⇒ #( 0 1 2 ) */ FTH prc = fth_proc_ref(">"); FTH ary = fth_make_array_var(5, FTH_ZERO, FTH_ONE, FTH_TWO, FTH_THREE, FTH_FOUR): fth_array_reject(ary, prc, FTH_TWO); ⇒ #( 0 1 2 )
fth_array_reverse
(FTH
array)fth_array_set
(FTH array,
ficlInteger index, FTH
value)fth_array_shift
(FTH
array)fth_array_sort
(FTH array,
FTH proc_or_xt)FTH ary_sort(FTH a, FTH b) { if (fth_number_less_p(a, b)) return (FTH_ONE_NEG); if (fth_number_equal_p(a, b)) return (FTH_ZERO); return (FTH_ONE); } FTH prc = fth_make_proc_from_func("int-sort", ary_sort, 0, 2, 0, 0); FTH ary = fth_make_array_var(3, FTH_TWO, FTH_ONE, FTH_ZERO); fth_array_sort(ary, prc); ⇒ #( 0 1 2 )
fth_array_subarray
(FTH array,
ficlInteger start, ficlInteger
end)fth_array_to_array
(FTH
array)fth_array_to_list
(FTH
obj)fth_array_uniq
(FTH array)fth_array_unshift
(FTH array,
FTH value)fth_make_array_len
(ficlInteger
len)fth_make_array_var
(ficlInteger
len, ...)fth_make_array_with_init
(ficlInteger
len, FTH init)fth_make_empty_array
(void)fth_array_assoc
(FTH assoc,
FTH key)fth_array_assoc_ref
(FTH assoc,
FTH key)fth_array_assoc_remove
(FTH
assoc, FTH key)fth_assoc
(FTH assoc,
FTH key, FTH value)fth_array_assoc_set
(FTH assoc,
FTH key, FTH value)FTH_LIST_P
(obj)FTH_CONS_P
(obj)FTH_PAIR_P
(obj)fth_car
(FTH list)fth_cadr
(FTH list)fth_caddr
(FTH list)fth_cadddr
(FTH list)fth_cdr
(FTH list)fth_cddr
(FTH list)fth_cons
(FTH value,
FTH list)fth_cons_2
(FTH obj1,
FTH obj2, FTH list)fth_list_append
(FTH args)fth_list_copy
(FTH list)fth_list_length
(FTH obj)fth_list_member_p
(FTH list,
FTH key)fth_list_ref
(FTH list,
ficlInteger index)fth_list_reverse
(FTH
list)fth_list_set
(FTH list,
ficlInteger index, FTH
value)fth_list_to_array
(FTH
list)fth_make_empty_list
(void)fth_make_list_len
(ficlInteger
len)fth_make_list_var
(ficlInteger
len, ...)fth_make_list_with_init
(ficlInteger
len, FTH init)fth_acons
(FTH key,
FTH value, FTH alist)fth_list_assoc
(FTH alist,
FTH key)fth_list_assoc_ref
(FTH alist,
FTH key)fth_list_assoc_remove
(FTH
alist, FTH key)fth_list_assoc_set
(FTH alist,
FTH key, FTH value)fth_file_atime
(const char
*name)fth_file_basename
(const char
*name, const char *ext)fth_file_basename("/home/mike/cage.snd", NULL); ⇒ "cage" fth_file_basename("/home/mike/cage.snd", ".snd"); ⇒ "cage" fth_file_basename("/home/mike/cage.snd", "nd"); ⇒ "cage.s" fth_file_basename("/home/mike/cage.snd", " "); ⇒ "cage.snd"
fth_file_chmod
(const char
*name, mode_t mode)fth_file_copy
(const char *src,
const char *dst)fth_file_ctime
(const char
*name)fth_file_delete
(const char
*name)fth_file_dirname
(const char
*name)fth_file_install
(const char
*src, const char *dst, mode_t
mode)fth_file_length
(const char
*name)fth_file_match_dir
(FTH string,
FTH regexp)fth_file_mkdir
(const char
*name, mode_t mode)fth_file_mkfifo
(const char
*name, mode_t mode)fth_file_mtime
(const char
*name)fth_file_realpath
(const char
*name)HOME
. If
realpath(3) function exists, returns resolved path,
otherwise returns name with ‘~’
replacement.fth_file_rename
(const char
*src, const char *dst)fth_file_rmdir
(const char
*name)fth_file_split
(const char
*name)fth_file_symlink
(const char
*src, const char *dst)fth_file_block_p
(const char
*name)-b
.fth_file_character_p
(const char
*name)-c
.fth_file_directory_p
(const char
*name)-d
.fth_file_executable_p
(const char
*name)-x
.fth_file_exists_p
(const char
*name)-e
.fth_file_fifo_p
(const char
*name)-p
.fth_file_grpowned_p
(const char
*name)-G
.fth_file_owned_p
(const char
*name)-O
.fth_file_readable_p
(const char
*name)-r
.fth_file_setgid_p
(const char
*name)-g
.fth_file_setuid_p
(const char
*name)-u
.fth_file_socket_p
(const char
*name)-S
.fth_file_sticky_p
(const char
*name)-k
.fth_file_symlink_p
(const char
*name)-h
.fth_file_writable_p
(const char
*name)-w
.fth_file_zero_p
(const char
*name)FTH hs = fth_hash_set(FTH_FALSE, fth_symbol("a"), fth_make_array_var(3, FTH_ZERO, FTH_ONE, FTH_TWO)); fth_printf("%S\n", hs); fth_hash_set(hs, fth_symbol("b"), fth_make_string("text")); fth_printf("%S\n", hs); fth_hash_ref(hs, fth_symbol("a")); ⇒ #( 0 1 2 ) fth_hash_ref(hs, fth_symbol("b")); ⇒ "text" fth_hash_ref(hs, fth_symbol("c")); ⇒ #f fth_hash_delete(hs, fth_symbol("a")); ⇒ '( 'a #( 0 1 2 ) ) fth_printf("%S\n", hs); ⇒ #{ 'b ⇒ "text" } fth_hash_clear(hs); fth_printf("%S\n", hs); ⇒ #{} FTH hs_each(FTH key, FTH val, FTH data) { return (fth_string_sformat(data, "%S: %S\n", key, val)); } FTH hs_map(FTH key, FTH val, FTH data) { (void)key; return (fth_number_mul(val, data)); } fth_hash_set(fth_symbol("a"), FTH_SIX); fth_hash_each(hs, hs_each, fth_make_empty_string()); ⇒ "'a: 6\n" fth_hash_map(hs, hs_map, INT_TO_FIX(10)); ⇒ #{ 'a ⇒ 60 }
C functions follow handling Hash Object Types:
FTH_HASH_P
(obj)fth_hash_clear
(FTH hash)fth_hash_copy
(FTH hash)fth_hash_delete
(FTH hash,
FTH key)fth_hash_each
(FTH hash,
FTH (*func)(FTH key, FTH val, FTH data),
FTH data)/* * #{ 'a 0 'b 1 } value hs * lambda: <{ key val -- }> * "%s=%s\n" #( key val ) fth-print * ; hash-each */ static FTH hs_each(FTH key, FTH val, FTH data) { fth_printf("%S=%S\n", key, val); return (data); } fth_hash_each(hs, hs_each, FTH_NIL);
fth_hash_equal_p
(FTH obj1,
FTH obj2)fth_hash_find
(FTH hash,
FTH key)fth_hash_keys
(FTH hash)fth_hash_length
(FTH obj)fth_hash_map
(FTH hash,
FTH (*func)(FTH key, FTH val, FTH data),
FTH data)/* * #{ 'a 0 'b 1 } value hs * lambda: <{ key val -- val }> * val 10 + * ; hash-map */ static FTH hs_map(FTH key, FTH val, FTH data) { (void)key; return (fth_number_add(val, data); } fth_hash_map(hs, hs_map, INT_TO_FIX(10)); ⇒ #{ 'a => 10 'b => 11 }
fth_hash_member_p
(FTH hash,
FTH key)fth_hash_ref
(FTH hash,
FTH key)fth_hash_set
(FTH hash,
FTH key, FTH value)fth_hash_to_array
(FTH
hash)/* #{ 'a 0 'b 1 } value hs */ FTH ary = fth_hash_to_array(hs); ⇒ #( #( 'a 0 ) #( 'b 1 ) )
fth_hash_values
(FTH hash)fth_make_hash
(void)fth_make_hash_len
(int
hashsize)FTH_DEFAULT_HASH_SIZE
.Usage of properties
:
FTH pr = fth_properties(FTH_FALSE); ⇒ #{} fth_hash_length(pr); ⇒ 0 FTH obj = fth_make_string("string"); pr = fth_properties(obj); ⇒ #f fth_hash_length(pr); ⇒ 0 fth_property_set(obj, fth_symbol("a"), fth_make_string("hello")); pr = fth_properties(obj); ⇒ #{ 'a "hello" } fth_property_ref(obj, fth_symbol("a")); ⇒ "hello" fth_hash_length(pr); ⇒ 1
fth_properties
(FTH obj)fth_property_ref
(FTH obj,
FTH key)fth_property_set
(FTH obj,
FTH key, FTH value)Usage of object-properties
:
FTH obj = fth_make_string("string"); FTH pr = fth_object_properties(obj); ⇒ #f fth_hash_length(pr); ⇒ 0 fth_object_property_set(obj, fth_symbol("a"), fth_make_string("hello")); pr = fth_object_properties(obj); ⇒ #{ 'a "hello" } fth_object_property_ref(obj, fth_symbol("a")); ⇒ "hello" fth_hash_length(pr); ⇒ 1
fth_object_properties
(FTH
obj)fth_object_property_ref
(FTH
obj, FTH key)fth_object_property_set
(FTH
obj, FTH key, FTH
value)Usage of word-properties
:
FTH obj = fth_proc_ref("noop"); FTH pr = fth_word_properties(obj); ⇒ #f fth_hash_length(pr); ⇒ 0 fth_word_property_set(obj, fth_symbol("a"), fth_make_string("hello")); pr = fth_word_properties(obj); ⇒ #{ 'a "hello" } fth_word_property_ref(obj, fth_symbol("a")); ⇒ "hello" fth_hash_length(pr); ⇒ 1
fth_word_properties
(FTH
obj)fth_word_property_ref
(FTH obj,
FTH key)fth_word_property_set
(FTH obj,
FTH key, FTH value)FTH_HOOK_P
(obj)fth_add_hook
(FTH hook,
FTH proc)fth_hook_apply
(FTH hook,
FTH args, const char
*caller)fth_hook_arity
(FTH hook)fth_hook_clear
(FTH hook)fth_hook_empty_p
(FTH
hook)fth_hook_equal_p
(FTH obj1,
FTH obj2)fth_hook_member_p
(FTH hook,
FTH name)fth_hook_names
(FTH hook)fth_hook_to_array
(FTH
hook)fth_make_hook
(const char
*name, int arity, const char
*doc)fth_make_hook_with_arity
(const char
*name, int req, int opt,
int rest, const char *doc)fth_make_simple_hook
(int
arity)fth_remove_hook
(FTH hook,
FTH name)fth_run_hook
(FTH hook,
int len, ...)fth_run_hook_again
(FTH hook,
int len, ...)fth_run_hook_bool
(FTH hook,
int len, ...)FTH_IO_P
(obj)fth_io_close
(FTH io)fth_io_closed_p
(FTH obj)fth_io_eof_p
(FTH io)fth_io_equal_p
(FTH obj1,
FTH obj2)fth_io_filename
(FTH io)fth_io_fileno
(FTH io)fth_io_flush
(FTH io)fth_io_getc
(FTH io)fth_io_input_p
(FTH obj)fth_io_output_p
(FTH obj)fth_io_length
(FTH obj)fth_io_mode
(FTH io)fth_io_nopen
(const char *host,
int port, int domain,
int type, int fam)FICL_FAM_CLIENT
or FICL_FAM_SERVER
.
/* port = 17: Quote Of The Day (qotd of inetd(1)) */ int fam = FICL_FAM_CLIENT; FTH io = fth_io_nopen("localhost", 17, AF_INET6, SOCK_STREAM, fam); while (!fth_io_eof_p(io)) fth_printf("%s", fth_io_read(io)); fth_io_close(io); /* * A server at port 2002 at one terminal (test_server): * * % ./test_server ⇒ the server will print to *stdout* * when a client sends */ int fam = FICL_FAM_SERVER; FTH io = fth_io_nopen("localhost", 2002, AF_INET6, SOCK_STREAM, fam); while (!fth_io_eof_p(io)) fth_io_write(fth_io_stdout, fth_io_read(io)); fth_io_close(io); /* * A client at port 2002 at another terminal (test_client): * * % ls -lAF | ./test_client ⇒ sends it to the server */ int fam = FICL_FAM_CLIENT; FTH io = fth_io_nopen("localhost", 2002, AF_INET6, SOCK_STREAM, fam); while (!fth_io_eof_p(fth_io_stdin)) fth_io_write(io, fth_io_read(fth_io_stdin)); fth_io_close(io);
fth_io_open
(const char *name,
int fam)FICL_FAM_READ
,
FICL_FAM_WRITE
and
FICL_FAM_READ
|
FICL_FAM_WRITE
.
FTH io = fth_io_open("foo", FICL_FAM_WRITE); fth_io_write(io, "hello\n"); fth_io_write(io, "world\n"); fth_io_close(io); FTH io = fth_io_open("foo", FICL_FAM_READ); fth_printf("%s", fth_io_read(io); ⇒ "hello\n" fth_printf("%s", fth_io_read(io); ⇒ "world\n" fth_io_close(io); /* or */ FTH io = fth_io_open("foo", FICL_FAM_READ | FICL_FAM_WRITE); fth_io_write(io, "hello\n"); fth_io_write(io, "world\n"); fth_io_rewind(io); fth_printf("%s", fth_io_read(io); ⇒ "hello\n" fth_printf("%s", fth_io_read(io); ⇒ "world\n" fth_io_close(io);
fth_io_output_p
(FTH obj)fth_io_popen
(FTH cmd,
int fam)FICL_FAM_READ
,
FICL_FAM_WRITE
and
FICL_FAM_READ
|
FICL_FAM_APPEND
which correspond to popen(3) open modes
“r”, “w” and “r+”.
/* read example (popen(3) mode == "r"): */ FTH fs = fth_make_string("ls"); FTH io = fth_io_popen(fs, FICL_FAM_READ); while (!fth_io_eof_p(io)) fth_printf("%s", fth_io_read(io)); fth_io_close(io); /* write example (popen(3) mode == "w"): */ FTH fs = fth_make_string("cat"); FTH io = fth_io_popen(fs, FICL_FAM_WRITE); fth_io_write(io, "hello\n"); fth_io_close(io); /* read-write example (popen(3) mode == "r+"): */ FTH fs = fth_make_string("cat"); FTH io = fth_io_popen(fs, FICL_FAM_READ | FICL_FAM_APPEND); fth_io_write(io, "hello\n"); fth_printf("%s", fth_io_read(io)); fth_io_close(io);
fth_io_pos_ref
(FTH io)fth_io_pos_set
(FTH io,
ficl2Integer pos)fth_io_ptr
(FTH io)fth_io_putc
(FTH io,
int c)fth_io_read
(FTH io)fth_io_read_line
(FTH io)fth_io_readlines
(FTH io)fth_io_rewind
(FTH io)fth_io_sopen
(FTH string,
int fam)FICL_FAM_READ
,
FICL_FAM_WRITE
and
FICL_FAM_READ
|
FICL_FAM_APPEND
which correspond to open modes “r”, “w” and
“r+”.
/* read example (mode == "r"): */ FTH fs = fth_make_string("string\n"); FTH io = fth_io_sopen(fs, FICL_FAM_READ); while (!fth_io_eof_p(io)) fth_printf("%s", fth_io_read(io)); fth_io_close(io); /* write example (mode == "w"): */ FTH fs = fth_make_empty_string(); FTH io = fth_io_sopen(fs, FICL_FAM_WRITE); fth_io_write(io, "hello\n"); fth_io_close(io); /* read-write example (mode == "r+"): */ FTH fs = fth_make_empty_string(); FTH io = fth_io_sopen(fs, FICL_FAM_READ | FICL_FAM_APPEND); fth_io_write(io, "hello\n"); fth_io_rewind(io); fth_printf("%s", fth_io_read(io)); fth_io_close(io);
fth_io_to_string
(FTH io)fth_io_write
(FTH io,
const char *line)fth_io_write_and_flush
(FTH io,
const char *line)fth_io_write_format
(FTH io,
FTH fmt, FTH args)fth_io_writelines
(FTH io,
FTH array-of-lines)fth_readlines
(const char
*name)fth_writelines
(const char
*name, FTH array-of-lines)fth_get_exit_status
(void)fth_set_exit_status
(int
status)fth_set_io_stdin
(FTH io)fth_set_io_stdout
(FTH io)fth_set_io_stderr
(FTH io)fth_gethostbyaddr
(FTH ip)fth_gethostbyname
(FTH
host)fth_getservbyname
(FTH
serv)fth_getservbyport
(FTH
port)fth_tmpfile
(void)fth_io_tmpfile
(void)fth_init
(void)fth_exit
(int n)fth_reset
(void)Evaluation Functions
fth_catch_eval
(const char
*buffer)fth_catch_exec
(ficlWord
*word)fth_eval
(const char
*buffer)undef
, if buffer evaluates
to FTH_BYE, exits program, if buffer evaluates to a
single value, removes it from stack and returns it, if
buffer evaluates to more than one values, removes
them from stack and returns them as Array object.Loading Source Files
fth_add_load_lib_path
(const char
*path)fth_unshift_load_lib_path
(const char
*path)*load-lib-path*
if not already
there.fth_add_load_path
(const char
*path)fth_unshift_load_path
(const char
*path)*load-path*
if not already there.fth_add_loaded_files
(const char
*file)*loaded-files*
if not already there.fth_basename
(const char
*path)fth_find_file
(FTH name)fth_install_file
(FTH
fname)*load-path*
or
*load-lib-path*
. Warns if no writable path could
be found.fth_dl_load
(const char *lib,
const char *func)fth_load_file
(const char
*name)fth_require_file
(const char
*name)*loaded-files*
. Before loading,
before-load-hook is called. If
this hook returns #f, nothing is loaded and the return value is #f. If
loading finishes successfully, the return value is #t, otherwise an
exception is thrown. After loading,
after-load-hook is called. If
name has no file extension,
FTH_FILE_EXTENSION
‘.fs’ or
‘.so’ will be added. If name or
name plus extension doesn't exist, try all path
names from either *load-path*
or
*load-lib-path*
with name.
If name begins with ‘~’, replace it
with HOME
. fth_load_file
can load the same file more than once, while
fth_require_file
and
fth_dl_load
load files only once.
fth_dl_load
calls func to
initializes the dynamic library.fth_load_init_file
(const char
*init_file)fth_load_global_init_file
(void)FTH_INIT_FILE
, if
FTH_INIT_FILE
is not set, try to load
HOME
/.fthrc instead.
before-load-hook and
after-load-hook are called.Various Functions
fth_add_feature
(const char
*name)fth_provided_p
(const char
*name)fth_provided_p
tests if feature
name exists in the list.fth_apropos
(FTH regexp)fth_find_in_wordlist
(const char
*name)fth_gethostname
(void)fth_sethostname
(FTH fs)fth_getrusage
(void)fth_parse_word
(void)FTH parse_test(void) { return (fth_make_string(fth_parse_word())); } fth_make_proc_from_func("parse-test", parse_test, 0, 0, 0, 0); fth_eval("parse-test make-array"); ⇒ "make-array"
fth_uname
(void)fth_version
(void)fth_short_version
(void)fth_wordlist_each
(int
(*func)(ficlWord *word, FTH data), FTH
data)FTH_EXACT_P
(obj)fth_exact_p
(obj)FTH_FIXNUM_P
(obj)fth_fixnum_p
(obj)FTH_NUMBER_P
(obj)fth_number_p
(obj)FTH_FLOAT_P
(obj)FTH_INTEGER_P
(obj)FTH_LONG_LONG_P
(obj)fth_integer_p
(obj)FTH_UNSIGNED_P
(obj)fth_unsigned_p
(obj)fth_isinf
(ficlFloat f)fth_isnan
(ficlFloat f)FTH_LLONG_P
(obj)FTH_ULLONG_P
(obj)fth_ullong_p
(obj)fth_make_float
(ficlFloat
f)fth_float_copy
(FTH x)fth_make_llong
(ficl2Integer
d)fth_make_ullong
(ficl2Unsigned
ud)fth_llong_copy
(FTH obj)fth_make_int
(ficlInteger
n)fth_make_unsigned
(ficlUnsigned
u)fth_make_long_long
(ficl2Integer
d)fth_make_ulong_long
(ficl2Unsigned
ud)fth_float_ref
(FTH x)fth_real_ref
(FTH x)fth_int_ref
(FTH x)fth_unsigned_ref
(FTH x)fth_long_long_ref
(FTH x)fth_ulong_long_ref
(FTH x)fth_float_ref_or_else
(FTH x,
ficlFloat fallback)fth_int_ref_or_else
(FTH x,
ficlInteger fallback)FTH_COMPLEX_P
(obj)fth_make_complex
(ficlComplex
z)fth_make_polar
(ficlFloat real,
ficlFloat theta)fth_make_rectangular
(ficlFloat
real, ficlFloat image)fth_complex_ref
(FTH x)ficlStackPopComplex
(ficlStack
*stack)ficlStackPushComplex
(ficlStack
*stack, ficlComplex cp)FTH_BIGNUM_P
(obj)fth_make_bignum
(ficlBignum
bn)fth_bignum_copy
(FTH m)fth_bignum_ref
(FTH obj)ficlStackPopBignum
(ficlStack
*stack)ficlStackPushBignum
(ficlStack
*stack, ficlBignum bn)FTH_RATIO_P
(obj)fth_make_ratio
(FTH num,
FTH den)fth_make_ratio_from_float
(ficlFloat
f)fth_make_ratio_from_int
(ficlInteger
num, ficlInteger den)fth_make_rational
(ficlRatio
r)fth_ratio_ref
(FTH obj)fth_denominator
(FTH x)fth_numerator
(FTH x)fth_ratio_floor
(FTH x)fth_rationalize
(FTH x,
FTH err)ficlStackPopRatio
(ficlStack
*stack)ficlStackPushRatio
(ficlStack
*stack, ficlRatio r)fth_frandom
(ficlFloat f)fth_random
(ficlFloat f)fth_srand
(ficlInteger n)fth_exact_to_inexact
(FTH
x)fth_inexact_to_exact
(FTH
x)fth_number_equal_p
(FTH x,
FTH y)fth_number_less_p
(FTH x,
FTH y)fth_number_add
(FTH x,
FTH y)fth_number_div
(FTH x,
FTH y)fth_number_mul
(FTH x,
FTH y)fth_number_sub
(FTH x,
FTH y)fth_gc_marked_p
(FTH obj)fth_gc_protected_p
(FTH
obj)fth_gc_permanent_p
(FTH
obj)fth_gc_mark
(FTH obj)fth_gc_unmark
(FTH obj)fth_gc_protect
(FTH obj)fth_gc_unprotect
(FTH obj)fth_gc_permanent
(FTH obj)fth_gc_on
(void)fth_gc_off
(void)fth_gc_run
(void)fth_instance_ref_gen
(FTH
obj)fth_instance_ref_obj
(FTH
obj)fth_instance_ref_gen
returns the GEN-struct of obj,
fth_instance_ref_obj
returns the OBJ-struct of
obj for
fth_make_object_type_from.fth_instance_p
(FTH obj)fth_object_is_instance_of
(FTH
obj, FTH type)fth_make_instance
(FTH obj,
void *gen)fth_instance_flag_p
(FTH obj,
int flag)fth_instance_type_p
(FTH obj,
fobj_t type)fth_make_object_type
(const char
*name)fth_object_type_p
(FTH
obj)fth_make_object_type
creates a new object-type name and adds
name to the feature list, creates a constant
fth-name of object-type and returns the new
object-type name. The new created object-type can be
used to bind words to it. fth_object_type_p
checks
if obj is an object-type.fth_make_object_type_from
(const char
*name, FTH base)fth_object_name
(FTH obj)fth_set_object_apply
(FTH obj,
void *fnc, int req,
int opt, int rest)fth_set_object_copy
(FTH obj,
FTH (*fnc)(FTH obj))fth_set_object_dump
(FTH obj,
FTH (*fnc)(FTH obj))fth_set_object_equal_p
(FTH
obj, FTH (*fnc)(FTH obj1, FTH
obj2))fth_set_object_free
(FTH obj,
void (*fnc)(FTH obj))fth_set_object_inspect
(FTH
obj, FTH (*fnc)(FTH obj))fth_set_object_length
(FTH obj,
FTH (*fnc)(FTH obj))fth_set_object_mark
(FTH obj,
void (*fnc)(FTH obj))fth_set_object_to_array
(FTH
obj, FTH (*fnd)(FTH obj))fth_set_object_to_string
(FTH
obj, FTH (*fnc)(FTH obj))fth_set_object_value_ref
(FTH
obj, FTH (*fnc)(FTH obj, FTH
index))fth_set_object_value_set
(FTH
obj, FTH (*fnc)(FTH obj, FTH
index, FTH value))object-
xxx
function to object-type obj.fth_cycle_next
(FTH obj)fth_cycle_pos_0
(FTH obj)fth_cycle_pos_ref
(FTH
obj)fth_cycle_pos_set
(FTH obj,
ficlInteger index)fth_object_cycle_ref
(FTH
obj)fth_object_cycle_set
(FTH obj,
FTH value)fth_hash_id
(FTH obj)fth_object_apply
(FTH obj,
FTH args)fth_set_object_apply(vct_tag, vct_ref, 1, 0, 0); /* C */ <'> enved-ref fth-enved 1 set-object-apply \ Forth
fth_object_copy
(FTH obj)fth_object_dump
(FTH obj)fth_to_c_dump
(FTH obj)fth_object_empty_p
(FTH
obj)fth_object_equal_p
(FTH obj1,
FTH obj2)fth_object_id
(FTH obj)fth_object_find
(FTH obj,
FTH key)fth_object_index
(FTH obj,
FTH key)fth_object_member_p
(FTH obj,
FTH key)fth_object_inspect
(FTH
obj)fth_to_c_inspect
(FTH obj)fth_object_length
(FTH
obj)fth_object_range_p
(FTH obj,
ficlInteger index)fth_object_sort
(FTH obj,
FTH proc)fth_object_to_array
(FTH
obj)fth_object_to_string
(FTH
obj)fth_to_c_string
(FTH obj)fth_object_value_ref
(FTH obj,
ficlInteger index)fth_object_value_set
(FTH obj,
ficlInteger index, FTH
value)ficl_to_fth
(FTH obj)fth_to_ficl
(FTH obj)fth_pop_ficl_cell
(ficlVm
*vm)fth_push_ficl_cell
(ficlVm *vm,
FTH obj)fth_port_close
(FTH port)fth_port_flush
(FTH port)fth_port_display
(FTH port,
FTH obj)fth_port_getc
(FTH port)fth_port_gets
(FTH port)fth_port_putc
(FTH port,
int c)fth_port_puts
(FTH port,
const char *str)fth_set_read_cb
(in_cb cb)fth_set_print_cb
(out_cb
cb)fth_set_error_cb
(out_cb
cb)fth_set_print_and_error_cb
(out_cb
cb)fth_port_to_string
(FTH
port)#
’b
, B
,
o
and O
conversion prepend
a zero before output, for x
and
X
conversion prepend a ‘0x’
respective ‘0X’ before output. For
a
, A
,
e
, E
,
f
, F
,
g
and G
conversion the
result will always have a decimal point.-
’0
’
(zero)l
’ll
’z
’%
aAeEfFgG
bBdoOpuUxX
c
D
object-dump
.I
object-inspect
.M
object->string
, in addition, strings will be
enclosed in double quotations ("string").qQs
S
object->string
.fth_debug
(const char *fmt,
...)#<DEBUG(C): ...>
and returns the
written bytes.fth_die
(const char *fmt,
...)fth_warning
(const char *fmt,
...)#<warning: ...>
continuing execution,
or in #<die: ...>
and exit the
interpreter with return code 1 (EXIT_FAILURE).
fth_warning returns the written
bytes.fth_error
(const char
*str)fth_errorf
(const char *fmt,
...)fth_verrorf
(const char *fmt,
va_list ap)fth_format
(const char *fmt,
...)fth_vformat
(const char *fmt,
va_list ap)fth_fprintf
(FILE *fp,
const char *fmt, ...)fth_ioprintf
(FTH io,
const char *fmt, ...)fth_port_printf
(FTH port,
const char *fmt, ...)fth_vfprintf
(FILE *fp,
const char *fmt, va_list
ap)fth_vioprintf
(FTH io,
const char *fmt, va_list
ap)fth_port_vprintf
(FTH port,
const char *fmt, va_list
ap)fth_read
(void)fth_print
(const char
*str)fth_printf
(const char *fmt,
...)fth_vprintf
(const char *fmt,
va_list ap)fth_asprintf
(char **result,
const char *fmt, ...)fth_vasprintf
(char **result,
const char *fmt, va_list
ap)fth_snprintf
(char *buffer,
size_t size, const char *fmt,
...)fth_vsnprintf
(char *buffer,
size_t size, const char *fmt,
va_list ap)fth_word_defined_p
(FTH
obj)FTH x = (FTH)FICL_WORD_NAME_REF("bye"); fth_word_defined_p(x); ⇒ 1 fth_variable_set("hello", FTH_FALSE); FTH x = (FTH)FICL_WORD_NAME_REF("hello"); fth_word_defined_p(x); ⇒ 1 fth_word_defined_p(FTH_FALSE); ⇒ 0
fth_word_type_p
(FTH obj,
int type)FTH x = (FTH)FICL_WORD_NAME_REF("bye"); fth_word_type_p(x, FW_WORD); ⇒ 1 fth_word_type_p(x, FW_KEYWORD); ⇒ 0
FTH_PROC_P
(obj)FTH_WORD_P
(obj)fth_define_procedure
(const char
*name, void *func, int
req, int opt, int rest,
const char *doc)fth_define_void_procedure
(const char
*name, void *func, int
req, int opt, int rest,
const char *doc)fth_documentation_ref
(FTH
obj)fth_documentation_set
(FTH obj,
FTH doc)fth_get_optarg
(ficlInteger
req, FTH def)fth_get_optkey
(FTH key,
FTH def)fth_get_optkey_fix
(FTH key,
int def)fth_get_optkey_int
(FTH key,
ficlInteger def)fth_get_optkey_2int
(FTH key,
ficl2Integer def)fth_get_optkey_str
(FTH key,
char *def)fth_make_proc
(ficlWord *word,
int req, int opt,
int rest)ficlWord *xt = FICL_WORD_NAME_REF("+"); FTH prc = fth_make_proc(xt, 2, 0, 0); fth_proc_call(prc, __func__, 2, FTH_ONE, FTH_TWO); ⇒ 3
fth_make_proc_from_func
(const char
*name, void *func, int
void_p, int req, int opt,
int rest)fth_proc_apply
(FTH proc,
FTH args, const char
*caller)If proc is not a Proc object, returns #f, If proc doesn't leave a return value on stack, returns #f, if proc leaves a single value on stack, returns it, if proc leaves more than one values on stack, returns them as Array object.
fth_proc_arity
(FTH proc)fth_proc_call
(FTH proc,
const char *caller, int len,
...)If proc is not a Proc object, returns #f, If proc doesn't leave a return value on stack, returns #f, if proc leaves a single value on stack, returns it, if proc leaves more than one values on stack, returns them as Array object.
fth_proc_name
(FTH obj)fth_proc_source_ref
(FTH
proc)fth_proc_source_set
(FTH proc,
FTH source)fth_proc_to_xt
(FTH proc)fth_source_file
(FTH obj)fth_source_line
(FTH obj)fth_source_ref
(FTH obj)fth_source_set
(FTH obj,
FTH source)fth_word_doc_set
(ficlWord
*word, const char *str)fth_xt_apply
(const char *name,
FTH args, const char
*caller)If the xt with name doesn't leave a return value on stack, returns #f, if a single value remains on stack, returns it, if more than one values remain on stack, returns them as Array object.
FTH fs = fth_make_string("hello, world!"); FTH re = fth_make_regexp(", (.*)!"); FTH ary = fth_make_array_var(2, re, fs); fth_xt_apply("regexp-match", ary, __func__); ⇒ 8 fth_xt_apply("*re1*", FTH_FALSE, __func__) ⇒ "world"
fth_xt_call
(const char *name,
FTH args, const char
*caller)If the xt with name doesn't leave a return value on stack, returns #f, if a single value remains on stack, returns it, if more than one values remain on stack, returns them as Array object.
FTH fs = fth_make_string("hello, world!"); FTH re = fth_make_regexp(", (.*)!"); fth_xt_call("regexp-match", __func__, 2, re, fs); ⇒ 8 fth_xt_call("*re1*", __func__, 0); ⇒ "world"
fth_word_ref
(const char
*name)fth_proc_ref
(const char
*name)fth_variable_obj
(const char
*name)fth_define
(const char *name,
FTH value)fth_define_constant
(const char
*name, FTH value, const char
*doc)help
word. Returns
value where C integers are converted to FTH Fixnums,
any other objects remain untouched.fth_define_variable
(const char
*name, FTH value, const char
*doc)fth_define
() for
constants above. Returns value.fth_defined_p
(const char
*name)fth_trace_var
(FTH obj,
FTH proc_or_xt)to
.
FTH test_var; FTH trace_cb(FTH val) { test_var = fth_number_mul(val, FTH_TWO); return (val); } fth_variable_set("trace-foo", FTH_ONE); FTH prc = fth_make_proc_from_func("trace-cb", trace_cb, 0, 1, 0, 0); FTH obj = (FTH)FICL_WORD_NAME_REF("trace-foo"); fth_trace_var(obj, prc); fth_string_eval(fth_make_string("2 to trace-foo")); ⇒ test_var == 4 fth_untrace_var(obj);
fth_untrace_var
(FTH obj)fth_var_ref
(FTH obj)fth_var_set
(FTH obj,
FTH value)fth_variable_ref
(const char
*name)fth_variable_set
(const char
*name, FTH value)fth_regexp_var_ref
().
FTH_REGEXP_P
(obj)fth_make_regexp
(const char
*reg)FTH re = fth_make_regexp("bar"); FTH fs = fth_make_string("foobar"); fth_regexp_search(re, fs, 0, -1); ⇒ 3 FTH re = fth_make_regexp("(B|b)+"); FTH fs = fth_make_string("foobar"); fth_regexp_search(re, fs, 0, -1); ⇒ 3
fth_regexp_find
(const char
*reg, const char *str)fth_regexp_find_flags
(const char
*reg, const char *str, int
cflags)fth_regexp_find
() but with the extra
option cflags, which can be set to an ored value
from the following constants:
fth_regexp_match
(FTH regexp,
FTH string)FTH re = fth_make_regexp("foo"); FTH fs = fth_make_string("foobar"); fth_regexp_match(re, fs); ⇒ 3 FTH re = fth_make_regexp("(bar)"); FTH fs = fth_make_string("foobar"); fth_regexp_match(re, fs); ⇒ 3 FTH re = fth_make_regexp(".*(bar)"); FTH fs = fth_make_string("foobar"); fth_regexp_match(re, fs); ⇒ 6 fth_object_value_ref(re, 0); ⇒ "foobar" fth_object_value_ref(re, 1); ⇒ "bar" fth_object_value_ref(re, 2); ⇒ #f
fth_regexp_replace
(FTH regexp,
FTH string, FTH replace)FTH re = fth_make_regexp("(bar)"); FTH fs = fth_make_string("foobar"); FTH rp = fth_make_string("BAR"); fth_regexp_replace(re, fs, rp); ⇒ "fooBAR" FTH re = fth_make_regexp("(foo)"); FTH fs = fth_make_string("foo-bar"); FTH rp = fth_make_string("***\\1***"); fth_regexp_replace(re, fs, rp); ⇒ "***foo***-bar"
fth_regexp_search
(FTH regexp,
FTH string, ficlInteger start,
ficlInteger range)FTH re = fth_make_regexp("foo"); FTH fs = fth_make_string("foobar"); fth_regexp_search(re, fs, 0, 2); ⇒ 0 (means #t) FTH re = fth_make_regexp("(bar)"); FTH fs = fth_make_string("foobar"); fth_regexp_search(re, fs, 0, 2); ⇒ -1 (means #f) fth_regexp_search(re, fs, 3, 2); ⇒ 3 fth_object_value_ref(re, 0); ⇒ "bar" fth_object_value_ref(re, 1); ⇒ "bar" fth_object_value_ref(re, 2); ⇒ #f
fth_regexp_var_ref
(ficlInteger
index)FTH_STRING_P
(obj)FTH fs = fth_make_string("hello"); FTH_STRING_P(fs); ⇒ 1 FTH fs = FTH_NIL; FTH_STRING_P(fs); ⇒ 0
FTH_CHAR_P
(obj)fth_char_p
(obj)FTH ch = CHAR_TO_FTH('A'); FTH_CHAR_P(ch); ⇒ 1 FTH ch = INT_TO_FIX(65); FTH_CHAR_P(ch); ⇒ 1 FTH ch = INT_TO_FIX(10); FTH_CHAR_P(ch); ⇒ 0
fth_make_empty_string
(void)FTH fs = fth_make_empty_string(); ⇒ "" fth_string_length(fs); ⇒ 0
fth_make_string
(const char
*str)FTH fs = fth_make_string("hello"); ⇒ "hello" fth_string_length(fs); ⇒ 5 FTH fs = fth_make_string(""); ⇒ "" fth_string_length(fs); ⇒ 0
fth_make_string_format
(const char
*fmt, ...)I
fth_to_c_inspectS
fth_to_c_stringM
fth_to_c_string_2D
fth_to_c_dumpFTH arg = fth_make_array_var(1, fth_make_string("foo")); FTH fs = fth_make_string_format("%I", arg); ⇒ '#<array[1]: #<string[3]: "foo">>' FTH fs = fth_make_string_format("%S", arg); ⇒ '#( "foo" )' FTH fs = fth_make_string_format("%M", arg); ⇒ '#( "foo" )' FTH fs = fth_make_string_format("%D", arg); ⇒ '#( "foo" )'
fth_make_string_len
(const char
*str, ficlInteger len)FTH fs = fth_make_string_len(" ", 0); ⇒ "" FTH fs = fth_make_string_len(" ", 3); ⇒ " " FTH fs = fth_make_string_len("xxxxx", 3); ⇒ "xxx" FTH fs = fth_make_string_len("xxx", 5); ⇒ "xxx"
fth_make_string_or_false
(const char
*str)FTH fs = fth_make_string_or_false("hello"); ⇒ "hello" fth_string_length(fs); ⇒ 5 FTH fs = fth_make_string_or_false(""); ⇒ #f fth_string_length(fs); ⇒ -1 (means #f)
fth_string_append
(FTH string1,
FTH string2)FTH s1 = fth_make_string("foo"); FTH s2 = fth_make_string("bar"); fth_string_append(s1, s2); ⇒ "foobar"
fth_string_capitalize
(FTH
string)FTH fs = fth_make_string("foO"); fth_string_capitalize(fs); ⇒ "Foo" fth_printf("%S", fs); ⇒ "Foo"
fth_string_c_char_ref
(FTH
string, ficlInteger index)FTH fs = fth_make_string("foo"); char c = fth_string_c_char_ref(fs, 1); ⇒ 111
fth_string_c_char_set
(FTH
string, ficlInteger index, char
c)FTH fs = fth_make_string("foo"); char c = fth_string_c_char_set(fs, 1, 'e'); ⇒ 101 fth_printf("%S", fs); ⇒ "feo"
fth_string_char_ref
(FTH
string, ficlInteger index)FTH fs = fth_make_string("foo"); FTH ch = fth_string_char_ref(fs, 1); ⇒ 111
fth_string_char_set
(FTH
string, ficlInteger index, FTH
ch)FTH fs = fth_make_string("foo"); FTH ch = fth_string_char_set(fs, 1, CHAR_TO_FTH('e')); ⇒ 101 fth_printf("%S", fs); ⇒ "feo"
fth_string_chomp
(FTH
string)FTH fs = fth_make_string("foo\n"); fth_string_chomp(fs); ⇒ "foo" FTH fs = fth_make_string("bar"); fth_string_chomp(fs); ⇒ "bar"
fth_string_copy
(FTH
string)FTH s1 = fth_make_string("foo"); FTH s2 = fth_string_copy(s1); s1 == s2 ⇒ 0 fth_string_equal_p(s1, s2); ⇒ 1
fth_string_delete
(FTH string,
ficlInteger index)FTH fs = fth_make_string("foo"); fth_string_delete(fs, 1); ⇒ 111 ('o') fth_printf("%S", fs); ⇒ "fo"
fth_string_downcase
(FTH
string)FTH fs = fth_make_string("Foo"); fth_string_downcase(fs); ⇒ "foo" fth_printf("%S", fs); ⇒ "foo"
fth_string_equal_p
(FTH obj1,
FTH obj2)FTH s1 = fth_make_string("foo"); FTH s2 = fth_make_string("bar"); FTH s3 = fth_make_string("foo"); fth_string_equal_p(s1, s2); ⇒ 0 fth_string_equal_p(s1, s3); ⇒ 1 fth_string_equal_p(s3, s3); ⇒ 1
fth_string_eval
(FTH
string)ficlVm *vm = FTH_FICL_VM(); FTH fs = fth_make_string("3 4 +"); fth_string_eval(fs); ⇒ puts 7 on stack ficlStackPopInteger(vm->dataStack); ⇒ 7 ficlStackPushInteger(vm->dataStack, 7); ⇒ puts 7 on stack FTH fs = fth_make_string("3 4 + +"); fth_string_eval(fs); ⇒ puts 14 on stack ficlStackPopInteger(vm->dataStack); ⇒ 14 ficlStackPushInteger(vm->dataStack, 7); ⇒ puts 7 on stack FTH fs = fth_make_string("3 4 + + . cr"); fth_string_eval(fs); ⇒ prints 14
fth_string_fill
(FTH string,
FTH char)FTH fs = fth_make_string("foo"); fth_string_fill(fs, CHAR_TO_FTH('a')); ⇒ "aaa" fth_printf("%S", fs); ⇒ "aaa"
fth_string_find
(FTH string,
FTH key)FTH fs = fth_make_string("hello world"); FTH rs fth_make_string("l"); fth_string_find(fs, rs); ⇒ "llo world" FTH rs = fth_make_string("ell"); fth_string_find(fs, rs); ⇒ "ello world" FTH rs = fth_make_regexp("ell"); fth_string_find(fs, rs); ⇒ "ello world" FTH rs = fth_make_regexp("k"); fth_string_find(fs, rs); ⇒ #f
fth_string_format
(FTH string,
FTH args)FTH fmt = fth_make_string("%04d %8.2f %b %X %o"); FTH args = fth_make_array_var(5, INT_TO_FIX(128), fth_make_float(M_PI), INT_TO_FIX(255), INT_TO_FIX(255), INT_TO_FIX(255)); fth_string_format(fmt, args); ⇒ "0128 3.14 11111111 FF 377" FTH fmt = fth_make_string("we print %S"); FTH arg = INT_TO_FIX(10); fth_string_format(fmt, arg); ⇒ "we print 10" FTH fs = fth_make_string("simple string"); fth_string_format(fs, FTH_FALSE); ⇒ "simple string" fth_string_format(fs, FTH_NIL); ⇒ "simple string" FTH fs = fth_make_empty_string(); fth_string_format(fs, args); ⇒ ""
fth_string_greater_p
(FTH obj1,
FTH obj2)FTH s1 = fth_make_string("foo"); FTH s2 = fth_make_string("bar"); FTH s3 = fth_make_string("foo"); fth_string_greater_p(s1, s2); ⇒ 0 fth_string_greater_p(s1, s3); ⇒ 0 fth_string_greater_p(s3, s3); ⇒ 0
fth_string_index
(FTH string,
FTH key)FTH fs = fth_make_string("hello world"); FTH rs fth_make_string("l"); fth_string_index(fs, rs); ⇒ 2 FTH rs = fth_make_string("orl"); fth_string_index(fs, rs); ⇒ 7 FTH rs = fth_make_string("k"); fth_string_index(fs, rs); ⇒ -1 (means #f)
fth_string_insert
(FTH string,
ficlInteger index, FTH
value)FTH fs = fth_make_string("foo"); fth_string_insert(fs, 1, INT_TO_FIX(10)); ⇒ "f10oo"
fth_string_length
(FTH
string)FTH fs = fth_make_string("hello"); fth_string_length(fs); ⇒ 5 fth_string_length((FTH)5); ⇒ -1 (means #f)
fth_string_less_p
(FTH obj1,
FTH obj2)FTH s1 = fth_make_string("foo"); FTH s2 = fth_make_string("bar"); FTH s3 = fth_make_string("foo"); fth_string_less_p(s1, s2); ⇒ 0 fth_string_less_p(s1, s3); ⇒ 0 fth_string_less_p(s3, s3); ⇒ 0
fth_string_member_p
(FTH
string, FTH key)FTH fs = fth_make_string("hello world"); FTH rs fth_make_string("l"); fth_string_member_p(fs, rs); ⇒ 1 FTH rs = fth_make_string("ell"); fth_string_member_p(fs, rs); ⇒ 1 FTH rs = fth_make_string("k"); fth_string_member_p(fs, rs); ⇒ 0 FTH rs = fth_make_regexp("ell"); fth_string_member_p(fs, rs); ⇒ 1
fth_string_not_equal_p
(FTH
obj1, FTH obj2)FTH s1 = fth_make_string("foo"); FTH s2 = fth_make_string("bar"); FTH s3 = fth_make_string("foo"); fth_string_not_equal_p(s1, s2); ⇒ 1 fth_string_not_equal_p(s1, s3); ⇒ 0 fth_string_not_equal_p(s3, s3); ⇒ 0
fth_string_pop
(FTH
string)FTH fs = fth_make_string("foo"); fth_string_pop(fs); ⇒ 111 ('o') fth_string_pop(fs); ⇒ 111 ('o') fth_string_pop(fs); ⇒ 102 ('f') fth_string_pop(fs); ⇒ #f
fth_string_push
(FTH string,
FTH value)FTH fs = fth_make_string("foo"); fth_string_push(fs, fth_make_string(" ")); ⇒ "foo " fth_string_push(fs, INT_TO_FIX(10)); ⇒ "foo 10"
fth_string_ref
(FTH
string)FTH fs = fth_make_string("hello"); fth_string_ref(fs); ⇒ "hello" FTH fs = fth_make_empty_string(); fth_string_ref(fs); ⇒ "" FTH fs = FTH_FALSE; fth_string_ref(fs); ⇒ NULL
fth_string_replace
(FTH string,
FTH from, FTH to)FTH fs = fth_make_string("foo"); FTH from = fth_make_string("o"); FTH to = fth_make_string("a"); fth_string_replace(fs, from, to); ⇒ "faa" fth_printf("%S", fs); ⇒ "faa" FTH fs = fth_make_string("foo"); FTH from = fth_make_string("oo"); FTH to = fth_make_string("a"); fth_string_replace(fs, from, to); ⇒ "fa" fth_printf("%S", fs); ⇒ "fa" FTH fs = fth_make_string("foo"); FTH from = fth_make_string("o"); FTH to = fth_make_string(""); fth_string_replace(fs, from, to); ⇒ "f" fth_printf("%S", fs); ⇒ "f"
fth_string_reverse
(FTH
string)FTH fs = fth_make_string("foo"); fth_string_reverse(fs); ⇒ "oof"
fth_string_scat
(FTH string,
const char *str)FTH fs = fth_make_empty_string(); ⇒ "" fth_string_scat(fs, "hello"); ⇒ "hello"
fth_string_sformat
(FTH string,
const char *fmt, ...)FTH fs = fth_make_string("we want to "); fth_string_sformat(fs, "print %d times %f\n", 10, 3.14); ⇒ "we want to print 10 times 3.140000\n"
fth_string_shift
(FTH
string)FTH fs = fth_make_string("foo"); fth_string_shift(fs); ⇒ 102 ('f') fth_string_shift(fs); ⇒ 111 ('o') fth_string_shift(fs); ⇒ 111 ('o') fth_string_shift(fs); ⇒ #f
fth_string_sncat
(FTH string,
const char *str, ficlInteger
len)FTH fs = fth_make_empty_string(); ⇒ "" fth_string_sncat(fs, ", ", 2); ⇒ "hello, "
fth_string_split
(FTH string,
FTH sep)FTH fs = fth_make_string("foo:bar:baz:"); FTH sp = fth_make_string(":"); fth_string_split(fs, sp); ⇒ #( "foo" "bar" "baz") FTH sp = fth_make_regexp(":"); fth_string_split(fs, sp); ⇒ #( "foo" "bar" "baz") FTH fs = fth_make_string("foo bar baz"); fth_string_split(fs, FTH_NIL); ⇒ #( "foo" "bar" "baz")
fth_string_substring
(FTH
string, ficlInteger start,
ficlInteger end)FTH fs = fth_make_string("hello world"); fth_string_substring(fs, 2, 4); ⇒ "ll" fth_string_substring(fs, 0, -1); ⇒ "hello world" fth_string_substring(fs, -4, -2); ⇒ "orl" fth_string_substring(fs, -4, fth_string_length(fs)); ⇒ "orld"
fth_string_to_array
(FTH
string)FTH fs = fth_make_string("foo"); fth_string_to_array(fs); ⇒ #( 102 111 111 )
fth_string_unshift
(FTH string,
FTH value)FTH fs = fth_make_string("foo"); fth_string_unshift(fs, fth_make_string(" ")); ⇒ " foo" fth_string_unshift(fs, INT_TO_FIX(10)); ⇒ "10 foo"
fth_string_upcase
(FTH
string)FTH fs = fth_make_string("Foo"); fth_string_upcase(fs); ⇒ "FOO" fth_printf("%S", fs); ⇒ "FOO"
fth_string_vformat
(const char
*fmt, FTH args)FTH args = fth_make_array_var(2, INT_TO_FIX(10), fth_make_float(3.14)); fth_string_vformat("print %d times %f", args); ⇒ "print 10 times 3.140000"
fth_string_vsformat
(FTH
string, const char *fmt, va_list
ap)FTH_SYMBOL_P
(obj)fth_string_or_symbol_p
(FTH
obj)fth_string_or_symbol_ref
(FTH
obj)fth_symbol
(const char
*name)fth_symbol_equal_p
(FTH obj1,
FTH obj2)fth_symbol_p
(const char
*name)fth_symbol_ref
(FTH obj)FTH_KEYWORD_P
(obj)fth_keyword
(const char
*name)fth_keyword_equal_p
(FTH obj1,
FTH obj2)fth_keyword_p
(const char
*name)fth_keyword_ref
(FTH obj)FTH_EXCEPTION_P
(obj)fth_exception
(const char
*name)fth_exception_equal_p
(FTH
obj1, FTH obj2)fth_exception_last_message_ref
(FTH
exc)fth_exception_last_message_set
(FTH
exc, FTH msg)fth_exception_message_ref
(FTH
exc)fth_exception_message_set
(FTH
exc, FTH msg)fth_exception_ref
(FTH
obj)fth_make_exception
(const char
*name, const char *message)fth_symbol_or_exception_p
(FTH
obj)fth_symbol_or_exception_ref
(FTH
obj)fth_symbol_to_exception
(FTH
obj)Memory Allocation
The allocation functions always return a valid pointer. If memory is exhausted, abort the program.
fth_calloc
(size_t size,
size_t eltsize)fth_malloc
(size_t size)fth_realloc
(void *p,
size_t size)fth_free
(void *p)fth_strdup
(const char *s)fth_strndup
(const char *s,
size_t size)String Functions
The string functions return always NUL terminated strings.
fth_strcat
(char *d,
size_t size, const char *s)fth_strncat
(char *d,
size_t size, const char *s,
size_t count)fth_strcpy
(char *d,
size_t size, const char *s)fth_strncpy
(char *d,
size_t size, const char *s,
size_t count)fth_strlen
(const char *s)fth_strnlen
(const char *s, size_t
maxsize)Evaluate, Repl, and Throw Exception
fth_evaluate
(ficlVm *vm,
const char *buffer)fth_execute_xt
(ficlVm *vm,
ficlWord *word)fth_repl
(int argc,
char **argv)fth_throw
(FTH exc,
const char *fmt, ...)fth_throw_error
(FTH exc,
FTH args)/* * ARGS: any object */ fth_throw_error(FTH_BAD_ARITY, proc); ⇒ #<bad-arity in test-proc> /* * ARGS: nil or #() */ fth_throw_error(FTH_BAD_ARITY, FTH_NIL); ⇒ #<bad-arity: proc has bad arity> /* * ARGS: #( string ) */ fth_throw_error(FTH_BAD_ARITY, FTH_LIST_1(fth_make_string("test-proc")); ⇒ #<bad-arity in test-proc> /* * ARGS: #( fmt arg1 arg2 arg3 ) */ fth_throw_error(FTH_BAD_ARITY, FTH_LIST_4(fth_make_string("%s: %s args require, got %s"), proc, FTH_TWO, FTH_THREE)); ⇒ #<bad-arity in test-proc: 2 args required, got 3>
fth_throw_list
(FTH exc,
FTH args)fth_throw_error
except for replacing
format signs ~A and ~S with %s. This function exists for usage in
snd(1) where these signs appear.Miscellaneous
fth_getenv
(const char *name,
char *def)fth_popen
(const char *command,
const char *type)FTH_POPEN_SHELL
is
set, this shell will be used to execute command. If
the environment variable is not set, us the original
popen(3) function to execute
comment.fth_set_argv
(int from,
int to, char **argv)fth_strerror
(int n)pop_cstring
(ficlVm *vm)push_cstring
(ficlVm *vm,
char *s)push_forth_string
(ficlVm *vm,
char *s)FTH_DICTIONARY_SIZE
FTH_LOCALS_SIZE
FTH_RETURN_SIZE
FTH_STACK_SIZE
libfth
is
based on Ficl, Forth-inspired command
language, version 4.0.31 written by John Sadler.
libfth
and this manual page were written by
Michael Scholz
⟨mi-scholz@users.sourceforge.net⟩.
2025/01/22 | NetBSD 10.99.12 |