summaryrefslogtreecommitdiffstats
path: root/eval.c
Commit message (Collapse)AuthorAgeFilesLines
* * eval.c (bind_macro_params): Bugfix: the :whole parameter mustKaz Kylheku2014-02-151-1/+4
| | | | | | | | | capture the entire form, not just the arguments. (expand): Apply rlcp to the result of macro expansion, if it has not set up source code location. (eval_init): Register rlcp as intrinsic. * txr.1: Start of macro documentation. Documented rlcp.
* First cut at implementation of macros.Kaz Kylheku2014-02-151-7/+207
| | | | | | | | | | | | | | | * eval.c (top_mb, defmacro_s, macro_time_s, whole_k, env_k): New global variables. (expand_params): Recurse to handle macro parameter lists too. (bind_macro_params, op_defmacro, expand_macro): New static functions. (expand): Evaluate defmacro forms and macro-time forms at expansion time. Recognize and expand macros (albeit not yet with proper lexical scoping: local bindings are not able to shadow a macro). (eval_init): Protect top_mb from GC and initialize it. Intern new symbols defmacro, macro-time, and :whole. Register defmacro operator in op_table. * match.h (env_k): Added declaration for existing external variable.
* Bugfix: parameters of defun were not being treated by expander.Kaz Kylheku2014-02-151-8/+56
| | | | | | | | | | | They need to be since they can contain evaluable initforms for default arguments. Ditto with lambda; lambda parameters were being treated using expand_vars, which is not appropriate. * eval.c (expand_opt_params, expand_params): New static functions. (expand_vars): Bugfix: added some missing rlcp's to propagate line number info. (expand): Move lambda to separate case, and expand its params
* * eval.c (bind_args, op_modplace): Use ~s consistentlyKaz Kylheku2014-02-151-14/+14
| | | | in error messages.
* * eval.c (bindings_helper): Fixed misspelling of "symbol" in exceptionKaz Kylheku2014-02-151-1/+1
| | | | message.
* Replacing acons_new_l and aconsq_new_l interfaces with onesKaz Kylheku2014-02-141-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | that return the new or old cons cell rather than a pointer to its cdr field. * eval.c (transform_op): use of acons_new_l replaced with acons_new_c. * hash.c (struct hash): acons_new_l_fun member replaced with acons_new_c_fun. (make_hash, make_similar_hash): initialize acons_new_l_fun member using either acons_new_c or aconsql_new_c. (gethash_l): function becomes an inline in hash.h. (gethash_c): new function, based on gethash_l. (inhash, gethash_n): updated w.r.t struct hash change. * hash.h (gethash_c): declared. (gethash_l): becomes an inline wrapper for gethash_c. * lib.c (acons_new_l, aconsql_new_l): functions removed. (acons_new_c, aconsql_new_c): new functions. (obj_init): use gethash_c and rplacd instead of gethash_l and set. * lib.h (acons_new_l, aconsql_new_l): declarations removed. (acons_new_c, aconsql_new_c): declared.
* * eval.c (eval_init): Registered hash_update_1 as intrinsic.Kaz Kylheku2014-02-141-0/+2
| | | | | | | | * hash.c (hash_update_1): New function. * hash.h (hash_update_1): Declared. * txr.1: Documented hash-update-1.
* Different approach: optional arguments on hash-isec and hash-uni allowKaz Kylheku2014-02-141-4/+2
| | | | | | | | | | | | | | | | | | | | | for more flexible joining of data from the hash tables. * eval.c (eval_init): Remove hash_guni and hash_gisec. Change registration for hash_uni and hash_isec to three arguments with one optional. * hash.c (hash_uni): Third parameter introduced, join_func. The default behavior changes: in the two argument case, clashing keys prefer the value from hash1 rather than hash2. For this reason, we now iterate over hash2 first, then hash1. (hash_guni): Removed. (hash_isec): Third parameter introduced, join_func. (hash_gisec): Removed. * hash.h (hash_uni, hash_isec): Declarations updated. (hash_guni, hash_gisec): Delarations removed. * txr.1: Documentation updated.
* * eval.c (eval_init): Register hash_guni and hash_gisec as intrinsics.Kaz Kylheku2014-02-141-0/+2
| | | | | | | | | | | * hash.c (hash_guni, hash_gisec): New functions. (hash_isec): Bugfix: since gethash was naively used, keys in hash2 associated with the value nil were erroneously omitted from the intersection. * hash.h (hash_guni, hash_gisec): Declared. * txr.1: Documented new functions.
* * eval.c (eval_init): Register inhash as intrinsic.Kaz Kylheku2014-02-141-0/+1
| | | | | | | | | * hash.c (inhash): New function. * hash.h (inhash): Declared. * txr.1: Documented inhash. Also, added surprisingly missing documentation for gethash!
* * eval.c (eval_init): Register new functions posqual, posql,Kaz Kylheku2014-02-111-0/+5
| | | | | | | | | | posq, pos, and pos_if as intrinsics. * lib.c (posqual, posql, posq, pos, pos_if): New functions. * lib.h (posqual, posql, posq, pos, pos_if): Declared. * txr.1: Documented
* * eval.c (eval_init): Turn a require argument into an optionalKaz Kylheku2014-02-111-3/+3
| | | | | | | | | | one for the functions some, all and none. * lib.c (some_satisfy, all_satisfy, none_satisfy): Add defaulting behavior for pred parameter. * txr.1: Document that the predicate function is optional in calls to some, all and none.
* * eval.c (if_fun): Bugfix: forgotten handling of optionalKaz Kylheku2014-02-111-1/+1
| | | | alternative argument.
* * eval.c (subst_vars): Bugfix: results of expressions notKaz Kylheku2014-02-111-6/+17
| | | | | | | | | | | | treated in the same way as variables: lists not stringified, causing expansions with parentheses, and sometimes errors due to unhandled objects. Also, use tostringp instead of format for stringifying objects. stringifying object. Bugfix.k * match.c (subst_vars): Added comment similar to the one in the subst_vars of eval.c. Removed superfluous conversion code where the str variable is already known to be a string.
* * eval.c (apply): Fix regression in dwim operator: not handlingKaz Kylheku2014-02-111-1/+1
| | | | | nil object properly. Since dwim now trivially delegates to apply, apply must recognize nil.
* * Makefile (OBJS): New object file, combi.o.Kaz Kylheku2014-02-111-545/+2
| | | | | | | | | | | | | | | | * dep.mk: Updated. * eval.c: Removed combination and permutation functions; they now reside in combi.c. (generate): Changed from static to external linkage. * eval.h (generate): Declared. * combi.c: New file. * combi.h: New file. * txr.vim: Regenerated.
* * eval.c (rcomb_gen_fun_common): Streamlined implementation.Kaz Kylheku2014-02-101-10/+9
| | | | Got rid of stack that is consed up on each call.
* Relaxed behavior: don't throw errors for impossible permutations,Kaz Kylheku2014-02-101-21/+25
| | | | | | | | | | | | | | | but return an empty list. * eval.c (perm_init_common): Do not throw error; return a nil state if permutation length exceeds sequence length. (perm_vec, perm_list, perm_str): Check for null return from perm_init_common and return empty list. (k_conses): Do not throw error; return empty list. (comb_list_gen_fun): Check for nil value out of k_conses. (comb): For vectors and strings, check length against k and return nil if necessary. For lists, comb_list_gen_fun handles it. * txr.1: Section order rearranged, and updated.
* * eval.c (rcomb_while_fun, rcomb_gen_fun_common,Kaz Kylheku2014-02-101-0/+121
| | | | | | | | rcomb_list_gen_fun, rcomb_list, rcomb_vec_gen_fun, rcomb_vec, rcomb_str_gen_fun, rcomb_str, rcomb): New static functions. (eval_init): Register rcomb as intrinsic. * txr.1: Documented rcomb.
* * eval.c (rperm, perm_str): Just in case, return a mutable emptyKaz Kylheku2014-02-101-2/+135
| | | | | | | | | | string, rather than null_string, which is a literal. (k_conses, comb_while_fun, comb_gen_fun_common, comb_list_gen_fun, comb_list, comb_vec_gen_fun, comb_vec, comb_str_gen_fun, comb_str, comb): New static functions. (eval_init): Registered comb as instrinsic. * txr.1: Documented comb.
* * eval.c (rperm_list, rperm_vec, rperm_str): n variable renamedKaz Kylheku2014-02-091-17/+212
| | | | | | | | | | | | | | | | | | to k, for consistency with rperm. (rperm): Likewise, and the behavior in the k == zero case is changed to return a single empty permutation. (perm_while_fun, perm_index, perm_gen_fun_common, perm_init_common, perm_vec_gen_fill, perm_vec_gen_fun, perm_vec, perm_list_gen_fill, perm_list_gen_fun, perm_list, perm_str_gen_fill, perm_str_gen_fun, perm_str, perm): New static functions. (eval_init): perm registered as intrinsic. * lib.c (vecref_l): Bugfix: allow negative indices, just like vecref. * lib.h (three, four): New macros. * txr.1: Updated documentation for rperm. Documented perm.
* * eval.c (nperm_while_fun, nperm_gen_fun, nperm_list,Kaz Kylheku2014-02-071-0/+96
| | | | | | | | nperm_vec_gen_fun, nperm_vec, nperm_str_gen_fun, nperm_str, nperm): New static functions. (eval_init): nperm registered as intrinsic. * txr.1: Documented nperm function.
* * hash.c (hash_grow, make_hash, make_similar_hash, copy_hash):Kaz Kylheku2014-02-061-1/+1
| | | | | | | | | | | | | | | Pass second argument to vector. * lib.c (vector): Takes additional argument specifying the value for the slots of the vector. (vector_list, sub_vec): Pass second argument to vector. * lib.h (vector): Declaration updated. * eval.c (eval_init): Register vector as two-argument function with one required arg. * txr.1: Updated.
* * eval.c (op_dwim): Gutted down to just a few lines.Kaz Kylheku2014-02-061-75/+1
| | | | | | | | | | | | Basically the dwim operator is just a Lisp-1 version of the call operator now. It doesn't have to do anything funny with non-function objects, since they are callable. * lib.c (chr_str, chr_str_set, vecref, vecref_l): Replace inappropriate internal assertions with error exceptions. * unwind.h (numeric_assert, range_bug_unless): Unused macros removed.
* Allow sequences and hashes to be called as functions.Kaz Kylheku2014-02-051-0/+10
| | | | | | | | | | | | | | | | This is already supported in the DWIM operator. * eval.c (apply): If object isn't a function, gather the arguments into an array and delegate to generic_funcall. * lib.c (generic_funcall): Changed from static to external linkage. Supports sequences and hashes as functions. Error messages fixed not to refer to "funcall". (funcall, funcall1, funcall2, funcall3, funcall4): Do not throw exception if fun is not of FUN type; instead, delegate to generic_funcall. Error messages fixed not to refer to "funcall". * lib.h (generic_function): Declared.
* * arith.c (lognot): Conform to new scheme for defaulting optional args.Kaz Kylheku2014-02-051-25/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (apply): Unconditionally use colon_k for missing optional args, for intrinsic functions. (eval_intrinsic, rangev, rangev_star, errno_wrap): Conform to new scheme for defaulting optional args. (reg_fun_mark): Function removed. (eval_init): Switch reduce_left and reduce_right back to reg_fun registration. * hash.c (gethash_n): Conform to new scheme for defaulting optional arguments. * lib.c (sub_list, replace_list, remove_if, keep_if, remove_if_lazy, keep_if_lazy, tree_find, count_if, some_satisfy, all_satisfy, none_satisfy, search_str, match_str, match_str_tree, sub_str, replace_str, cat_str, tok_str, intern, rehome_sym, sub_vec, replace_vec, lazy_str, sort, multi_sort, find, find_if, set_diff, obj_print, obj_pprint): Conform to new scheme for defaulting optional arguments. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_n5, func_n6, func_n7, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n5v, func_n6v, func_n7v): Remove references to removed mark_missing_args member of struct func. (func_set_mark_missing): Function removed. (generic_funcall): Unconditionally use colon_k for missing optional args, for intrinsic functions. * lib.h (struct func): mark_missing_args member removed. (func_set_mark_missing): Declaration removed. (default_arg, default_bool_arg): New inline functions. * rand.c (random): Left argument is not optional. (rnd): Conform to new scheme for defaulting optional arguments. * regex.c (search_regex, match_regex): Conform to new scheme for defaulting optional arguments. * stream.c (unget_char, unget_byte, put_string, put_char, put_byte, put_line): Conform to new scheme for defaulting optional arguments. * syslog.c (openlog_wrap): Conform to new scheme for defaulting optional arguments. * txr.1: Remove the specification that nil is a sentinel value in default arguments, where necessary. Use consistent syntax for specifying variable parts in argument lists. A few errors and omissions addressed.
* * eval.c (bind_args): Support optional parameters in theKaz Kylheku2014-02-051-5/+48
| | | | | | | | form (sym initform present-p-sym). Also, support the convention that a value of : explicitly passed for an optional argument produces the same behavior as if that argument value were missing. * txr.1: Document new conventions.
* * eval.c (apply): Pass missing optional arguments as colon_k.Kaz Kylheku2014-02-051-4/+15
| | | | | | | | | | | | | | | | | | | | | | | to functions for which this is requested. (reg_fun_mark): New static function. (eval_init): Register reduce_left and reduce_right as requiring marking for missing optionals. * lib.c (func_set_mark_missing): New function. (generic_funcall): Pass missing optional arguments as colon_k to functions for which this is requested. (reduce_left, reduce_right): Handle missing values of init and key. (func_f0, func_f1, func_f2, func_f3, func_f4, func_n0, func_n1, func_n2, func_n3, func_n4, func_n5, func_n6, func_n7, func_f0v, func_f1v, func_f2v, func_f3v, func_f4v, func_n0v, func_n1v, func_n2v, func_n3v, func_n4v, func_n5v, func_n6v, func_n7v): Initialize new mark_missing_args member of struct func. * lib.h (struct func): New bitfield member, mark_missing_args. (func_set_mark_missing): Declared. (missingp, null_or_missing_p): New inline functions. * txr.1: Updated descriptions of reduce-left and reduce-right.
* * eval.c (op_modplace): Fixing a few argument count mismatchesKaz Kylheku2014-02-031-2/+2
| | | | in format calls.
* Tighten up environment visibility semantics of default argumentKaz Kylheku2014-02-031-21/+8
| | | | | | | | | | | | | | | init forms, while streamlining the implementation. * eval.c (bind_args): Get rid of opt_init_parm array hack; turns out we already have a useful function for extending an environment object, namely env_vbind: hitherto unused! We now make a blank environment upfront and extend it destructively with env_vbind. Except that after evaluating an init form, we create a new environment: this is in case a lexical closure was made by the init form, in which event we don't want to be destructively manipulating the environment any more. * txr.1: Clarified.
* * eval.c (eval_init): Fix incorrect registration ofKaz Kylheku2014-02-031-1/+1
| | | | list_star_intrinsic, diagnosed by compiler.
* Adding list* since we get it "for free" thanks to theKaz Kylheku2014-02-021-0/+6
| | | | | | | | | new helper function that supports apply. * eval.c (list_star_intrinsic): New static function. (eval_init): Register list_star_intrinsic as list*. * txr.1: Document list*.
* append can now take additional leading arguments before the list.Kaz Kylheku2014-02-021-2/+13
| | | | | | | | | | | | | * eval.c (apply_frob_args): New static function. (apply_intrinsic): Process arguments with apply_frob_args. (eval_init): apply_intrinsic registered differently, as a variadic function with one mandatory arg. * lib.c (lastcons): New function. * lib.h (lastcons): Declared. * txr.1: Updated append documentation.
* * eval.c (apply): Support string and vector arglist.Kaz Kylheku2014-02-021-5/+9
| | | | | | | | | | | (do_eval_args): Support string or vector in dot position. * lib.c (tolist): New function. * lib.h (tolist): Declared. * txr.1: Document how apply and dot position in compound forms supports strings as well as vectors.
* * eval.c (do_eval_args): If the dotted position of the argumentKaz Kylheku2014-02-021-2/+6
| | | | | | | list evaluates to a vector, then convert the vector to a list. * txr.1: Document compound forms, and how they allow the dotted position and how it may be a vector.
* * eval.c (eval_init): Register vector_list function a second timeKaz Kylheku2014-02-021-0/+1
| | | | | | under the name vec, as a variadic function. * txr.1: Document vec.
* * eval.c (expand_op): When the variant is do, and the symbolKaz Kylheku2014-01-301-2/+3
| | | | | | | | | is an operator, then suppress the addition of the rest parameter in the dotted cons position at the end of the form, since this mechanism for applying additional arguments is only supported by function calls, not by special forms. * lib.h (and2, and3): New macros.
* * eval.c (expand_op): Fix broken do operator. In the case of the doKaz Kylheku2014-01-301-1/+1
| | | | | | | operator, we must feed the entire form to the expander, not the individual forms. That is to say (do operator arg) must expand the form (operator arg), whereas (op fun arg) just expands the forms fun and arg individually.
* Default argument initializer scoping rule change, allowingKaz Kylheku2014-01-291-6/+19
| | | | | | | | | | | | | things like (defun foo (s : (l (length s))) ...). Default arguments can be initialized by expressions that refer to the arguments. * eval.c (bind_args): By means of a local array, defer the evaluation of optional argument init forms until the lexical environment, including all the parameters, is captured. Then valuates the forms in the array, and set the variable values. * txr.1: Clarify the new scoping rules.
* * eval.c (eval_init): Registered existing make_catenated_stream asKaz Kylheku2014-01-281-0/+2
| | | | | | | | | | | | | | intrinsic. * stream.c (cat_get_line, cat_get_char, cat_get_byte): Do not remove the last stream from the stream list, so that there is some stream object there which can take the unget-char or unget-byte operations. (cat_unget_byte, cat_unget_char): New static functions. (cat_stream_ops): unget_char and unget_byte function pointers filled in. * txr.1: Documented catenated-streams.
* * stream.c (remove_path, rename_path): New functions.Kaz Kylheku2014-01-281-1/+2
| | | | | | | | | | | * stream.h (remove_path, rename_path): Declared. * utf8.c (w_remove, w_rename): New functions. * utf8.h (w_remove, w_rename): Declared. * eval.c (eval_init): Registered remove_path and rename_path as intrinsics.
* * eval.c (meta_meta_p, meta_meta_strip): New static functions.Kaz Kylheku2014-01-281-1/+23
| | | | | | | | | | | | | | | (transform_op): Recognize compounded metas, and strip one level off. (eval_init): Intern sys:expand function so we have access to the form expander from TXR Lisp. * lib.c (obj_print, obj_pprint): Fix: wasn't rendering metanumbers. * parser.y (list): Support @ in front of anything. If it's an atom, treat it similarly to a metasymbol or metanumber. * txr.1: Documented meta-meta arguments in nested op. * genvim.txr, txr.vim: Support coloring for compounded meta syntax.
* * regex.c (match_regex_right): New function.Kaz Kylheku2014-01-261-0/+2
| | | | | | * regex.h (match_regex_right): Declared. * eval.c (eval_init): Register match_regex_right as instrinsic.
* * hash.c (hash_update): New function.Kaz Kylheku2014-01-241-0/+2
| | | | | | | | | | | | * hash.h (hash_update): Declared. * lib.c (update): New function. * lib.h (update): Declared. * eval.c (eval_init): Register hash_update and update as intrinsics. * txr.1: Documented.
* * eval.c (expand): Bugfix in expansion of dohash: neglectedKaz Kylheku2014-01-231-1/+3
| | | | to insert result form into the expanded output.
* * eval.c (expand_op): Takes sym argument to distinguish op and do.Kaz Kylheku2014-01-231-3/+6
| | | | | | | | The dwim operator is deleted when the symbol is do. (expand): Expand do_s form with expand_op, not only op_s. Pass down symbol. * txr.1: Document do operator.
* * eval.c (do_eval): Fix incorrect, recently introduced codeKaz Kylheku2014-01-231-10/+10
| | | | | rearrangement that gives precedence to operator lookup over function lookup.
* Bugfix: @(require ...) not expanding forms.Kaz Kylheku2014-01-231-8/+1
| | | | | | | | | | * eval.c (expand_forms): Static function becomes external. (expand_form): Remove case which handles do_s. * eval.h (expand_forms): Declared. * parser.y (elem): Expand both do_s and require_s forms by using expand_forms.
* * lib.c (conses, lazy_conses, func_set_env): New functions.Kaz Kylheku2014-01-231-0/+3
| | | | | | | | | | | (lazy_conses_func): New static function. * lib.h (conses, lazy_conses, func_set_env): Declared. * eval.c (eval_init): conses, lazy_conses and func_set_env registered as intrinsics. * txr.1: Documented.
* Changes to the list collection mechanism to improveKaz Kylheku2014-01-221-14/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the extension of list operations over vectors and strings. * eval.c (do_eval_args, bindings_helper, op_each, subst_vars, supplement_op_syms, mapcarv, mappendv): Switch from list_collect_* macros to functions. * lib.c (copy_list): Switch from list_collect* macros to functions. Use list_collect_nconc for the final terminator. Doing a copy there with list_collect_append was actually wasteful, and now that list_collect_append calls copy_list in places, it triggered runaway recursion. (make_like): Bugfix: list_vector was used instead of vector_list. (to_seq, list_collect, list_collect_nconc, list_collect_append): New functions. (append2, appendv, nappend2, sub_list, replace_list, ldiff, remq, remql, remqual, remove_if, keep_if, proper_plist_to_alist, improper_plist_to_alist, split_str, split_str_set, tok_str, list_str, chain, andf, orf, lis_vector, mapcar, mapcon, mappend, merge, set_diff, env): Switch from list_collect* macros to functions. (replace_str, replace_vec): Allow single item replacement sequence. * lib.h (to_seq): Declared. (list_collect, list_collect_nconc, list_collect_append): Macros removed, replaced by function declarations of the same name. These functions return the new ptail since they cannot assign to it, requiring all uses to be updated to do the assignment of the returned value. (list_collect_decl): Use val rather than obj_t *. * match.c (vars_to_bindings, h_coll, subst_vars, extract_vars, extract_bindings, do_output_line, do_output, v_gather, v_collect): Switch from list_collect* macros to functions. * parser.y (o_elems_transform): Likewise. * regex.c (dv_compile_regex, regsub): Likewise. * txr.c (txr_main): Likewise.