diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2012-02-21 18:13:52 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2012-02-21 18:13:52 -0800 |
commit | 72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a (patch) | |
tree | 2232b5a5374c92d566f087f2bc5e5067a5fb8fd4 /lib.h | |
parent | 216c446da541d2a2e68c57feee04bafce00013e5 (diff) | |
download | txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.gz txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.tar.bz2 txr-72d59307630fd1bd9ee1c06cdad4cfb634bc9a3a.zip |
Introducing optional arguments.
* debug.c (help, show_bindings): put_string arguments reversed.
* eval.c (bind_args): Support colon notation in interpreted
function lambda lists for optional arguments. Improved error checking.
(apply): Allow optional arguments to be left out.
(dwim_loc): Reversed arguments to replace_str, replace_vec,
replace_list.
(eval_init): Numerous intrinsics now have arguments that are optional.
New function rand introduced which reverses arguments relative to
random. New intrinsic function hash introduced for alternative
construction of hashes.
* gc.c (sweep): Reversed arguments to put_char.
* hash.c (weak_keys_k, weak_vals_k, equal_based_k): New keyword
symbol variables.
(hashv): New function.
(hash_init): Intern new symbols.
* hash.h (weak_keys_k, weak_vals_k, equal_based_k, hashv): Declared.
* lib.c (colon_k): New keyword symbol variable.
(replace_list, replace_str, replace_vec): Arguments rearranged.
(tree_find): testfun becomes optional argument.
(int_str): base becomes optional argument.
(func_f0, func_f1, func_f2, func_f3, func_f4, func_n0,
func_n1, func_n2, func_n3, func_n4, func_f0v, func_f1v,
func_f2v, func_f3v, func_f4v, func_n0v, func_n1v,
func_n2v, func_n3v, func_n4v, func_interp): Initialize optargs to zero.
(func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): New functions.
(cobj_print_op): Reversed arguments to put_string.
(find): testfun and keyfun become optional arguments.
(replace): Parameters rearranged and arguments rearranged in calls to
replace_list, replace_str and replace_vec.
(obj_init): colon_k initialized.
(obj_print, obj_pprint): Arguments reversed, and stream defaults
to std_output. Arguments reversed in calls to put_char and put_string.
(dump): Arguments reversed in call to put_char.
* lib.h (struct func): sizes of minparam, fixparam bitfields
adjusted. New bitfield optargs. New unnamed bitfield added so
the previous ones add up to 16 bits.
(colon_k): Declared.
(func_n0o, func_n1o, func_n2o, func_n3o, func_n4o): Declared.
(replace_list, replace_str, replace_vec, replace): Declarations updated.
* match.c (debuglf, dump_shell_string, dump_byte_string, dump_var,
do_output_line, extract): Reversed arguments to put_char and
Diffstat (limited to 'lib.h')
-rw-r--r-- | lib.h | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -89,8 +89,10 @@ struct package { struct func { type_t type; - unsigned minparam : 15; + unsigned fixparam : 7; /* total non-variadic parameters */ + unsigned optargs : 7; /* fixparam - optargs = required args */ unsigned variadic : 1; + unsigned : 1; functype_t functype : 16; val env; union { @@ -291,7 +293,7 @@ extern val error_s, type_error_s, internal_error_s; extern val numeric_error_s, range_error_s; extern val query_error_s, file_error_s, process_error_s; -extern val nothrow_k, args_k; +extern val nothrow_k, args_k, colon_k; extern val null_string; extern val null_list; /* (nil) */ @@ -337,7 +339,7 @@ val append2(val list1, val list2); val nappend2(val list1, val list2); val appendv(val lists); val sub_list(val list, val from, val to); -val replace_list(val list, val from, val to, val items); +val replace_list(val list, val items, val from, val to); val lazy_appendv(val lists); val ldiff(val list1, val list2); val flatten(val list); @@ -420,7 +422,7 @@ val length_str(val str); const wchar_t *c_str(val str); val search_str(val haystack, val needle, val start_num, val from_end); val search_str_tree(val haystack, val tree, val start_num, val from_end); -val replace_str(val str_in, val from, val to, val items); +val replace_str(val str_in, val items, val from, val to); val sub_str(val str_in, val from_num, val to_num); val cat_str(val list, val sep); val split_str(val str, val sep); @@ -482,6 +484,11 @@ val func_n1v(val (*fun)(val, val rest)); val func_n2v(val (*fun)(val, val, val rest)); val func_n3v(val (*fun)(val, val, val, val rest)); val func_n4v(val (*fun)(val, val, val, val, val rest)); +val func_n0o(val (*fun)(void), int reqargs); +val func_n1o(val (*fun)(val), int reqargs); +val func_n2o(val (*fun)(val, val), int reqargs); +val func_n3o(val (*fun)(val, val, val), int reqargs); +val func_n4o(val (*fun)(val, val, val, val), int reqargs); val func_interp(val env, val form); val func_get_form(val fun); val func_get_env(val fun); @@ -520,7 +527,7 @@ val vector_list(val list); val list_vector(val vector); val copy_vec(val vec); val sub_vec(val vec_in, val from, val to); -val replace_vec(val vec_in, val from, val to, val items); +val replace_vec(val vec_in, val items, val from, val to); val cat_vec(val list); val lazy_stream_cons(val stream); val lazy_str(val list, val term, val limit); @@ -559,7 +566,7 @@ val set_diff(val list1, val list2, val testfun, val keyfun); val length(val seq); val sub(val seq, val from, val to); val ref(val seq, val ind); -val replace(val seq, val from, val to, val items); +val replace(val seq, val items, val from, val to); val env(void); val obj_print(val obj, val stream); val obj_pprint(val obj, val stream); |