summaryrefslogtreecommitdiffstats
path: root/lib.h
Commit message (Collapse)AuthorAgeFilesLines
* Adding mismatch function.Kaz Kylheku2016-12-121-0/+1
| | | | | | | | | | * eval.c (eval_init): Register mismatch intrinsic. * lib.c (mismatch): New function. * lib.c (mismatch): Declared. * txr.1: Documented mismatch.
* New function: endp.Kaz Kylheku2016-12-101-0/+1
| | | | | | | | | | | | | This improves compatibility with other Lisp dialects in a small way. * eval.c (eval_init): Register endp intrinsic. * lib.c (endp): New function. * lib.h (endp): Declared. * txr.1: Documented endp.
* Adding curry_1234_1 function.Kaz Kylheku2016-12-011-0/+1
| | | | | | | * lib.c (do_curry_1234_1): New static function. (curry_1234_1): New function * lib.h: (curry_1234_1): Declared.
* Expander warns about unbound variables.Kaz Kylheku2016-11-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_exception): New static function. (eval_error): Reduced to wrapper around eval_exception. (eval_warn): New function. (me_op): Bind the rest symbol in a shadowing env to suppress watnings about unbound rest. (do_expand): Throw a warning when a bindable symbol is traversed that has no binding. (expand): Don't install atoms as last_form_expanded. * lib.c (warning_s, restart_s, continue_s): New symbol variables. (obj_init): Initialize new symbol variables. * lib.h (warning_s, restart_s, continue_s): Declared. * lisplib.c (except_set_entries): New entries for ignwarn and macro-time-ignwarn. * parser.c (repl_warning): New static function. (repl): Use repl_warning function as a handler for warning exceptions: to print their message and then continue by throwing a continue exception. * parser.y (warning_continue): New static function. (parse_once): Use warning_continue to ignore warnings. In other words, we suppress warnings from Lisp that is mixed into TXR pattern language code, because this produces too many false positives. * share/txr/stdlib/except.tl (ignwarn, macro-time-ignwarn): New macros. * share/txr/stdlib/place.tl (call-update-expander, call-clobber-expander, call-delete-expander): Ignore warnings around calls to sys:expand, because of some gensym-related false positives (we expand code into which we inserted some gensyms, without having inserted the constructs which bind them. * tests/011/macros-2.txr: Suppress unbound variable warnings from a test case. * tests/012/ifa.tl: Bind unbound x y variables in one test case. * tests/012/struct.tl: Suppress unbound variable warnings in some test cases. * uwind.c (uw_throw): If a warning is unhandled, then print its message with a "warning" prefix and then throw a continue exception. (uw_register_subtype): Eliminate the check for sub already being a subtype of sup. This allows us to officially register new types against t. (uw_late_init): Register continue exception type as a subtype of the restart type. Formally register warning type. * txr.1: Documented ignwarn.
* Completion of fallback list implementation.Kaz Kylheku2016-11-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | * lib.c (find_symbol): New function. (symbol_present): Search the fallback list also to determine whether the symbol is visible. * lib.h (find_symbol): Declared. * parser.y (sym_helper): Implement a new behavior for qualified symbols. Interning new symbols is only allowed for packages that have an empty fallback list. * parser.c (get_visible_syms): New static function. (find_matching_syms): Use get_visible_syms to get the list of eligible symbols. This way the fallback list of the package is included if it is the current package. * share/txr/stdlib/package.tl (defpackage): Do not insert a default (:use usr) if there is no :usr clause. Since defpackage is very new, no need for backward compatibility; the amount of code depending on this is likely zero. * txr.1: Documented fallback list feature.
* Start of fallback package list implementation.Kaz Kylheku2016-11-161-1/+4
| | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register package-fallback-list and set-package-fallback-list intrinsics. * lib.c (package_fallback_list, set_package_fallback_list, intern_fallback): New functions * lib.h (package_fallback_list, set_package_fallback_list, intern_fallback): Declared. * parser.y (sym_helper): Slightly restructure function so that the symbol interning is done separately in the various cases. In the unqualified symbol case, use intern_fallback to search the fallback list of the current package. * share/txr/stdlib/package.tl (defpackage): Implement :fallback clause.
* Implementing package foreign symbol concept.Kaz Kylheku2016-11-101-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register new intrinsics: package-local-symbols, package-foreign-symbols, use-sym, unuse-sym, use-package, unuse-package, unintern. * gc.c (mark_obj): Mark new hidhash member of struct package. * lib.c (make_package): Initialize new hidhash member of struct package. (lookup_package): New static function. (find_package): Allow string or symbol argument. (get_package): New static function. (delete_package, package_symbols): Use get_package for flexible package argument; delete_package removes symbols from other packages via unuse_package. (package_local_symbols, package_foreign_symbols): New functions. (use_sym, unuse_sym): New functions. (resolve_package_designators): New static function. (use_package, unuse_package): New functions. (symbol_present): New static function. (intern): Revised with get_package for flexible package argument. (unintern): New function. (rehome_sym): Use get_package. Semantics revised. (obj_print_impl): Use symbol_present function to determine whether object is visible in *package* and can be printed without a prefix, rather than naive home package test. * lib.h (struct package): New member, hidhash. (package_local_symbols, package_foreign_symbols, use_sym, unuse_sym, use_package, unuse_package, unintern): Declared. * txr.1: Documentation updated. Extended section introducing the design of packages, and argument conventions. New functions described. Existing function descriptions revised, particularly rehome-sym. Missing description of delete-package added.
* Implement *package* special var; package overhaul.Kaz Kylheku2016-11-081-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (load): Rebind *package* in the local dynamic environment already established for the sake of *load-path*. By doing this we cause *package* to be restored to its prior value, which allows the loaded file to alter it. Common Lisp works this way. (eval_init): Register *package* variable, with the user package as its default value. * lib.c (package_s): New symbol variable. (intern, rehome_sym): Default the package argument to the current package, not to user_package. (get_user_package, get_system_package, get_keyword_package): Functions removed. (get_current_package): New function. (obj_print_impl): Revise symbol printing. Keyword and uninterned symbols are printed with : and #: prefixes. The remainder are printed with a package prefix if their home package isn't the current package. * lib.h (keyword_package, user_package, system_package): These macros are just straight aliases for the global variables, not going through the lookup mechanism, which was pointless. (cur_package): New macro. (package_s): Declared. (get_current_package): Declared. * lisplib.c (lisplib_try_load): Establish a local dynamic environment, and bind the *package* variable to the user package which the library modules expect. * parser.c (find_matching_syms, provide_completions): Treat unqualified symbols in the current package rather than user package. * parser.y (sym_helper): Intern unqualified symbols in the current package, not user package. * txr.1: Document that the variables user-package, system-package and keyword-package should not be modified. Document the *package* special variable, and that intern and rehome-sym default their package argument to its value. (Here we get rid of wrong references to the undocumented variable *user-package*).
* New negated equality test functions.Kaz Kylheku2016-11-011-1/+3
| | | | | | | | | * eval.c (eval_init): Register neq, neql and nequal intrinsics. * lib.h (neq, neql, nequal): New inline functions. * txr.1: Documented neq, neql and nequal
* Relax restrictions on dwim places.Kaz Kylheku2016-10-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No longer require the leftmost expression in a dwim place to itself be a place, except when the expression evaluates to a list, and the list is subject to an element deletion or a range operation. * eval.c (eval_init): Register dwim-set and dwim-del with one additional argument that the C functions now take. * lib.c (dwim_set, dwim_del): Take a new place_p argument which informs these functions whether the object they are operating on came from a syntactic place. The forbidden situations are diagnosed based on this flag: modification of the subrange of a list, or deletion of a list ref. Some error messages reworded. * lib.h (dwim_set, dwim_del): Declarations updated. * share/txr/stdlib/place.tl (defplace dwim): Produce a different update, clobber and delete expansion when the obj-place form isn't a place. In the non-place case, do not assign the result of the sys:dwim-set or sys:dwim-del operation back obj-place. Furthermore, pass a Boolean flag to sys:dwim-set and sys:dwim-del indicating which situation is the case: did the object argument come from a place or non-place. * txr.1: Documentation updated.
* lambda-set method: treat [struct ...] as place.Kaz Kylheku2016-10-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Change registration of dwim-set to only one required argument, with the rest variadic. * lib.c (lambda_set_s): New symbol variable. (dwim_set): Change to variadic function that takes all arguments other than the object/sequence being operated on as struct args *. Rewrite to do a test on the object type first, handling hashes and structs specially. (obj_init): Initialize lambda_set_s. * share/txr/stdlib/place.tl (defplace dwim): Rewritten for more generic syntax. The only argument required is obj-place; the other arguments are treated as a variable argument list, all treated uniformly. This eliminates the special handling of the default value for hash lookups. * args.h (args_count): New inline function. * txr.1: Updated documentation for dwim operator, which neglects to mention use over objects thanks to the lambda function. Documented lambda-set.
* last, butlast: become accessors, get optional arg.Kaz Kylheku2016-10-261-2/+2
| | | | | | | | | | | | | | | | | | | | * eval.c (optimize_qquote_form): Pass nil to default new argument of butlast. (me_whilet, me_iflet_whenlet): Likewise for last. (eval_init): Add optional argument to registration of last and butlast intrinsics. * lib.c (last, butlast): Support optional numeric argument, like in Common Lisp. * lib.h (last, butlast): Declarations updated. * share/txr/stdlib/place.tl (last, butlast): New place macros. * txr.1: Updated documentation. The description of last is now moved into the sequence functions section.
* New accessors nthlast and butlastn.Kaz Kylheku2016-10-251-0/+2
| | | | | | | | | | | | | | * eval.c (eval_init): register nthlast and butlastn intrinsicis. * lib.c (nthlast, butlastn): New function. * lib.h (nthlast, butlastn): Declared. * share/txr/stdlib/place.tl (defplace nthlast, defplace butlastn): New places. * txr.1: Documented nthlast and butlastn.
* Changes to the printing framework.Kaz Kylheku2016-10-201-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The print function now takes an optional boolean for pretty printing. The print method is also called with a third argument; hence structures can customize both standard printing and pretty printing. * lib.c (obj_print): Take pretty argument, and pass it down to obj_print_impl. This makes obj_pprint redundant. (obj_pprint): Function removed: it was identical to obj_print except for passing t down to obj_print_impl for the pretty argument. These two wrappers had started small and got bigger with identical changes done in parallel. (pprint): New function. (tostring, dump): Pass nil for pretty argument of obj_print. (tostringp): Use pprint instead of obj_pprint. * lib.h (obj_print): Declaration updated. (obj_pprint): Declaration removed. (print, pprint): Declared. * eval.c (prinl): Pass nil for pretty_p argument of obj_print. Do the stream defaulting here; obj_print doesn't do it. (pprinl): Pass t for pretty_p argument of obj_print, and do stream argument defaulting. (eval_init): Register print to new print function rather than directly to obj_print. Register pprint to new pprint function rather than obj_pprint. * hash.c (hash_print_op): Call obj_print_impl to print the :equal-based keyword, rather than obj_print. Pass down the pretty flag. All the other keywords are treated this way; this fixes an inconsistency. * match.c (dump_var): Call pprint instead of obj_pprint. * stream.c (formatv): Call obj_print, with a calculated pretty argument instead of switching between obj_pprint and obj_print. * struct.c (struct_inst_print): Except when in backward compatibility mode, call the object's print method in both pretty and regular printing mode, passing the mode as a third argument. * tests/012/oop.tl (defstruct animal): Support third argument in print method. Make it optional because there are some explicit calls which don't pass the argument. * txr.1: Documentation updated for print method and the print function. Revised text for some of the related functions. Added compat notes.
* Add stream printing context.Kaz Kylheku2016-10-201-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is some infrastructure which will support *print-circle*. * lib.h (struct strm_ctx): Forward declared. (struct cobj_ops): Add context parameter to print function pointer. (cobj_print_op, obj_print_impl): Add context parameter to declarations. * hash.c (hash_print_op): Take context argument and pass it down in obj_print_impl calls. * lib.c (cobj_print_op, out_quasi_str): Likewise (obj_print_impl): Likewise, and also pass to COBJ print method. (obj_print, obj_pprint): Pass null pointer as context argument to obj_print_impl. * regex.c (regex_print): Take context parameter and ignore it. * socket.c (dgram_print): Likewise. * stream.h (struct strm_ctx): New struct type. (struct strm_base): New ctx member, pointer to struct strm_ctx. (stream_print_op): Add context parameter to declaration. (get_set_ctx, get_ctx): Declared. * stream.c (strm_base_init): Add null pointer to initializer. (strm_base_cleanup): Add assertion against context pointer being non-null: that indicates that some stream operation installed a context pointer and neglected to restore it to null before returning, which is bad because context will be stack allocated. (stream_print_op, stdio_stream_print, cat_stream_print): Take context parameter and ignore it. (get_set_ctx, get_ctx): New functions. * struct.c (struct_type_print): Take context parameter and ignore it. (struct_inst_print): Take context parameter and pass down to obj_print_impl.
* Provide functions to alter range objects.Kaz Kylheku2016-10-171-0/+2
| | | | | | | | | | Ranges continue to be immutable; but a backdoor is needed for upcoming support for circular notation. * lib.c (set_from, set_to): New functions. * lib.h (set_from, set_to): Declared.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-011-16/+17
| | | | | | | | | | | | | | | | | | | | * Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* split-str gains ability to keep separating pieces.Kaz Kylheku2016-09-161-0/+1
| | | | | | | | | | | | | | | * eval.c (eval_init): Register split-str to split_str_keep, with optional argument. * lib.c (split_str_keep): New function, formed from split_str, with third argument. (split_str): Reduced to wrapper around split_str_keep. Thus we don't have to update umpteen existing calls with an extra nil parameter. * lib.h (split_str_keep): Declared. * txr.1: Documented new optional argument of split-str.
* key function argument on remq, remql and remqual.Kaz Kylheku2016-09-151-3/+3
| | | | | | | | | | | | | | | | | * eval.c (weave_while): Pass third arg to remq as nil. (eval_init): Update registrations of remq, remql and remqual. * lib.c (remq, remql, remqual): Implement key function argument. * lib.h (remq, remql, remqual): Declarations updated. * sysif.c (at_exit_call): Pass third arg to remq as nil. * debug.c (debug): Pass third argument to remqual as nil. * txr.1: Documentation updated.
* New keepq, keepql and keepqual functions.Kaz Kylheku2016-09-151-0/+3
| | | | | | | | | * eval.c (eval_init): Register keepq, keepql and keepqual intrinsic functions. * lib.c (keepq, keepql, keepqual): New functions. * lib.h (keepq, keepql, keepqual): Declared.
* Adding time-parse function: wrapper for strptime.Kaz Kylheku2016-08-221-0/+3
| | | | | | | | | | | | * configure: Test for strptime. * eval.c (eval_init): register time-parse intrinsic. * lib.c (time_parse): New function. * lib.h (time_parse): Declared. * txr.1: Documented.
* Fixing semantics of makunbound.Kaz Kylheku2016-06-081-0/+2
| | | | | | | | | | | | | | | | | | * eval.c (unbound_s): New symbol variable. (lookup_var): If a dynamic binding has the special sys:unbound symbol as its value, then return nil, so the behavior is as if there is no binding. (makunbound): If the symbol exists in a dynamic environment, then replace its value with sys:unbound, making it look unbound. (eval_init): Initialize unbound_s. * lib.h (us_car, us_cdr): New inline functions. * txr.1: New dialect notes under boundp. Updated the makunbound documentation. Separated makunbound documentation from fmakunbound and mmakunbound. Added compatibility notes.
* New --free-all option for freeing memory on exit.Kaz Kylheku2016-06-071-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although we are garbage-collected, being able to clean up on shutdown is nevertheless useful for uncovering leaks. Leaks can occur, for instance, due to neglect to free out-of-heap satellite data from objects that are reclaimed by gc. This feature is long overdue. * arith.c, arith.h (arith_free_all): New function. * gc.c, gc.h (gc_free_all): New function. * lib.c (init): Remove program name parameter and redundant initialization of progname globl variable. * lib.h (progname): Superfluous declaration removed. This is already declared in txr.h. (init): Declaration updated. * regex.c (char_set_destroy): Do not check the static allocation flag here; just destroy the object. Do check for a null pointer, though. (char_set_cobj_destroy): This cobj destructor now checks the static flag of the char set object and avoids freeing it. Thus our char set singletons are left alone by gc, but our global freeing function takes care of them. (wide_cs): New static variable moved out of wide_display_char_p to static scope. (regex_free_all): New function. * regex.h (regex_free_all): Declared. * txr.c (progname): const qualifier and initializer removed. (main): Ensure progname is always dynamically allocated, even in the argv[0] == 0 case. Do not pass progname to init; it doesn't take that argument any more. (free_all): New static function. (txr_main): Implement --free-all option. * txr.h (progname): Declaration updated.
* Store hash values in hash entries.Kaz Kylheku2016-05-271-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Here, we augment the cons cells used for the hash chain assoc lists with one more field to store the hash value. This lets us grow hash tables without recalculating the hashes, and to perform hash searches with fewer equality comparisons. * hash.c (struct hash): assoc_fun and acons_new_c_fun function pointers get a new cnum hash argument. (hash_equal_op): Pass cell's hash value to assoc_fun. (hash_grow): No need to compute each hash entry's hash code; just pull it out from the cell, and mod it with the new modulus to get the chain index. (hash_assoc, hash_assql, hash_acons_new_c, hash_aconsql_new_c): New static functions. (make_hash): Store hash_assoc, hash_assql, hash_acons_new_c and hash_aconsql_new_c in place of assoc, assql, acons_new_c and aconsql_new_c. (gethash_c, gethash, gethash_f, gethash_n, remhash): Pass hash alue to assoc_fun or acons_new_c_fun. * lib.h (struct cons_hash_entry): New struct type. (union obj): New member ch.
* Reduce work done by hashing.Kaz Kylheku2016-05-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Curtail traversal of objects and strings. * hash.c (struct hash): hash_fun member takes int * parameter now. (HASH_STR_LIMIT, HASH_REC_LIMIT): New macros. (hash_c_str): Hash only HASH_STR_LIMIT characters. (equal_hash): Becomes extern function. Takes pointer-to-int count argument, which is decremented. Function stops recursing and returns zero when this hits zero. (eql_hash): Also takes int * param, for compatibility with function pointer in struct hash. This parameter is not used, though. (cobj_hash_op): Take pointer-to-count parameter, but ignore it. (hash_hash_op): Take pointer-to-count parameter, decrement and check that it has not hit zero, pass down to equal hash. (hash_grow, gethash_c, gethash, gethash_f, gethash_n, remhash): Initialize a counter to HASH_REC_LIMIT and pass down to hashing function. (hash_eql): Pass down a pointer to a dummy counter to eql_hash. (hash_equal): Initialize a counter to HASH_REC_LIMIT and pass down to hash_equal. * hash.h (equal_hash): Declared. * lib.h (cobj_ops): hash member takes int * parameter. (cobj_hash_op): Declaration updated with new param. * struct.c (struct_inst_hash): Takes new int * parameter for count. Calls equal_hash instead of hash_equal, eliminating c_num calls; pointer to count is passed to equal_hash.
* Avoid unnecessary evaluation in argument defaulting.Kaz Kylheku2016-05-071-4/+1
| | | | | | | | * lib.h (default_arg): Inline function becomes macro, so we can avoid evaluating the default value expression when it is not needed. * lib.c (default_arg): Declaration removed.
* Adding panic macro, which throws a panic exception.Kaz Kylheku2016-05-071-1/+1
| | | | | | | | | | | * lib.c (panic_s): New symbol variable. (obj_init): Initialize panic_s. * lib.h (panic_s): Declared. * unwind.c (uw_init): Register panic exception. * unwind.h (panic): New macro.
* Mechanism for recycling conses outside of GC.Kaz Kylheku2016-04-201-0/+4
| | | | | | | | | | | | * lib.c (recycled_conses): New static variable. (rcyc_pop, rcyc_cons, rcyc_list, rcyc_empty): New functions. (cons): Take a recycled cons, if available. * lib.h (rcyc_pop, rcyc_cons, rcyc_list, rcyc_empty): Declared. * gc.c (gc): Call rcyc_empty to make recycle_list unreachable.
* Fix proper-listp to proper-list-p.Kaz Kylheku2016-04-141-1/+1
| | | | | | | | | | | | | | | | | | | | This is really a gratuitous incompatibility with Common Lisp and other dialects. Let's fix it internally also, but keep the proper-listp function binding for backwards compatibility. * eval.c (dot_to_apply, me_op): Update proper_listp call to proper_list_p. (eval_init): Register proper-list-p to the same C function as proper-listp, and that C function is now called proper_list_p. * lib.c (proper_listp): Renamed to proper_list_p. * lib.h (proper_listp): Declaration updated. * parser.y (define_transform): Update proper_listp call. * txr.1: Replace all occurrences of proper-listp with proper-list-p. Add note explaining the rename situation.
* Adding rightmost item search functions.Kaz Kylheku2016-03-271-0/+13
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Registered intrinsics rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if and rsearch. * lib.c (rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if, rsearch): New functions. (rsearch_list): New static function. (search): Omit unreachable return statement. * lib.h (rmemq, rmemql, rmemqual, rmember, rmember-if, rposqual, rposql, rposq, rpos, rpos-if, rfind, rfind-if, rsearch): Declared. * txr.1: Documented.
* Implement socket timeouts.Kaz Kylheku2016-03-151-1/+1
| | | | | | | | | | | | | | | | | * lib.c (timeout_error_s): New symbol variable. (obj_init): Intern timeout-error, init new variable. * lib.h (timeout_error_s): Declared. * socket.c (sock_timeout, sock_send_timeout, sock_recv_timeout): New static functions. (sock_load_init): Register sock-send-timeout and sock-recv-timeout intrinsics. * stream.c (stdio_maybe_read_error, stdio_maybe_error): Convert EAGAIN into timeout_error_s. * txr.1: Documented.
* New function, split*.Kaz Kylheku2016-01-171-0/+1
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register split*. * lib.c (split_star_func): New static function. (partition_split_common): Take pointer-to-function argument instead of boolean. Hoist this C function into the lazy cons. (partition): Pass pointer to partition_func ito partition_split_common, intsead of a flag requesting the use of partition_func. (split): Pass apointer to split_func into partition_split_common. (split_star): New function. * lib.h (split_star): Declared. * txr.1: Documented split*.
* Fix omission: the / function becomes n-ary.Kaz Kylheku2016-01-131-0/+1
| | | | | | | | | | * eval.c (eval_init): Register / function to divv instead of divi. * lib.c (divv): New function. * lib.h (divv): Declared. * txr.1: Documented.
* Print control chars in regexes using \x.Kaz Kylheku2016-01-121-0/+1
| | | | | | | | | | | | | | | | | | | | * lib.c (out_str_char): Static function becomes extern. * lib.h (out_str_char): Declared. * regex.c (puts_clear_flag, putc_clear_flag): New static functions. (print_class_char): Take semicolon flag argument. Use out_str_char to render characters not escaped locally. Clear the semicolon flag. (paren_print_rec): Take semicolon flag argument, and pass it down. Clear it when printing parentheses. (print_rec): Take semicolon flag argument, and pass down to lower level functions. Use putc_clear_flag and puts_clear_flag instead of put_string and put_char. Use out_str_char for char object not esaped locally. (regex_print): define semi_flag and pass it down to print_rec.
* New internal function scat: variable arg cat_str.Kaz Kylheku2016-01-101-0/+1
| | | | | | | | | | | | | | Avoids consing up list of strings. * lib.c (vscat): New static function. (scat): New function. (lazy_str): Use scat instead of cat_str. * lib.h (scat): Declared. * eval.c (format_field): Use scat instead of cat_str. * parser.c (open_txr_file, read_eval_stream): Likewise.
* Use struct instead of cons for lazy string fields.Kaz Kylheku2016-01-091-1/+7
| | | | | | | | | | | | | | | | * gc.c (finalize): Must free the dynamic structure attached to the LSTR type now. (mark_obj): Must mark interior of LSTR type's props structure. * lib.c (lazy_sub_str, copy_lazy_str): Copy props structure. (lazy_str): Allocate and initialize props structure. (lazy_str_force, lazy_str_put, lazy_str_force_upto, lazy_str_get_trailing_list, out_lazy_str): Follow representation change. * lib.h (struct lazy_string_props): New struct type. (strut lazy_string): Member opts replaced with props pointer to struct lazy_string_props.
* New internal function for copying malloced object.Kaz Kylheku2016-01-091-0/+1
| | | | | | * lib.c (chk_copy_obj): New function. * lib.h (chk_copy_obj): Declared.
* Revert chr-isdigit/isxdigit, provide new functions.Kaz Kylheku2016-01-041-0/+2
| | | | | | | | | | | | | | | | | | | It was a mistake to change the semantics of the return value of chr-isdigit and chr-isdigit. It breaks code like [partition-by chr-isdigit ...]. The behavior of chr-isdigit and chr-isxdigit is restored to returning t and nil. New chr-digit and chr-xdigit functions are introduced for returning the digit value or nil. * eval.c (eval_init): Register chr-digit and chr-xdigit intrinsics. * lib.c (chr_isdigit, chr_isxdigit): Restore old behavior. (chr_digit, chr_xdigit): New functions. * lib.h (chr_digit, chr_xdigit): Declared. * txr.1: Everything documented.
* Copyright year bump.Kaz Kylheku2015-12-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * LICENSE, METALICENSE, Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/cadr.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Add 2016 copyright. * linenoise/LICENSE, linenoise/linenoise.c, linenoise/linenoise.h: Bump one principal author's copyright from 2014 to 2015. The code is based on a snapshot of 2015 upstream work.
* C++ breakage: multiple definition of name_s.Kaz Kylheku2015-12-301-1/+1
| | | | | | | | | | | | | * lib.c (name_s): Defined here now. (obj_init): name_s initialized here. * lib.h (name_s): Declared. * match.c (name_s): Definition removed. (syms_init): Initialization of name_s removed. * sysif.c (name_s): Definition removed. (sysif_init): Initialization of name_s removed.
* Overhaul printing of lazy strings.Kaz Kylheku2015-12-281-0/+1
| | | | | | | | | | | | | | | | | | The #<lazy-string ...> print syntax is gone. Lazy strings are now printed by traversing their structure, without forcing them to the flat representation. * lib.c (lazy_str_put): New function. (out_str_char, out_str_pretty, out_lazy_str): New static functions. (obj_print_impl): Use out_str_pretty for standard-printing regular strings. Use lazy_put_str for pretty-printing lazy strings, and out_lazy_str for standard-printing them. * lib.h (lazy_str_put): Declared. * stream.c (put_string): Check for a lazy string and route to lazy_str_put, so the string doesn't get forced (though of course the underlying list does, if it is lazy).
* Support eight-argument intrinsic functions.Kaz Kylheku2015-12-161-1/+7
| | | | | | | | | | * lib.h (enum functype): New member, N8. (struct func): New members n8 and n8v in embedded f struct. (func_n8, func_n8v, func_n70, func_n8o): Declared. * lib.c (equal): Handle N8 in switch. (func_n8, func_n8v, func_n70, func_n8o): New functions. (generic_funcall): Handle N8 in two switches.
* New functions window-map and window-mappend.Kaz Kylheku2015-11-251-0/+2
| | | | | | | | | | | | | | | | | * args.h (args_set_fill): New inline function. * eval.c (eval_init): Register window-map and window-mappend intrinics. * lib.c (wrap_k, reflect_k): New keyword variables. (calc_win_size): New static function. (window_map_list, window_map_vec): New static functions. (window_map, window_mappend): New functions. (obj_init): Initialize wrap_k and reflect_k. * lib.h (window_map, window_mappend): Declared. * txr.1: Documented window-map and window-mappend
* New equality substitution.Kaz Kylheku2015-11-201-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the equal method is defined for structs, its return value is used in their place for hashing and comparison. * eval.h (eq_s, eql_s, equal_s): Declared. * hash.c (equal_hash): If a COBJ defines an equalsub function, we call it. If it returns non-nil, we take the object in its place and recurse. * lib.c (equal): Refactored to support equality substitution. (less): Support equality substitution. * lib.h (cobj_ops): New function pointer member, equalsub. Only struct instances define this, currently. (cobj_ops_init): Add null entry to initializer for equalsub. (cobj_ops_init_ex): New initialiation macro for situations when the equalsub member must be provided. * struct.c (struct struct_type): new member eqmslot. (make_struct_type): Initialize emslot to zero. (static_slot_set, static_slot_ensure): If eqmslot is -1, indicating positive knowledge that there is no equal method static slot, we must invalidate that with a zero: it is no longer known whether there is or isn't such a slot. (get_equal_method, struct_inst_equalsub): New static functions. (struct_inst_ops): Initialize the equalsub member using new cobj_ops_init_ex macro. * txr.1: Document equality substitution.
* Provide butlast function.Kaz Kylheku2015-11-201-0/+1
| | | | | | | | | | * eval.c (eval_init): Registered butlast intrinsic. * lib.c (butlast): New function. * lib.h (butlast): Declared. * txr.1: Documented butlast.
* Consistent parameter name in list_collect_* decls.Kaz Kylheku2015-11-111-5/+5
| | | | | | | * lib.h (list_collect, list_collect_nconc, list_collect_append, list_collect_nreconc, list_collect_revappend): Rename pptail parameter to ptail, like in the lib.c definitions of these.
* Adding revappend and nreconc.Kaz Kylheku2015-11-111-0/+4
| | | | | | | | | | | | | | | * eval.c (eval_init): Register revappend and nreconc intrinsics. * lib.c (list_collect_nreconc): New function. (revlist): New static function. (list_collect_revappend): New function. (revappend, nreconc): New functions. * lib.h (revappend, nreconc): Declared. (list_collect_nreconc, list_collect_revappend): Declared. * txr.1: Documented revappend and nreconc.
* Add func_n6o.Kaz Kylheku2015-11-101-0/+1
| | | | | | * lib.c (func_n6o): New function. * lib.h (func_n6o): Declared.
* New range type, distinct from cons cell.Kaz Kylheku2015-11-011-4/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register intrinsic functions rcons, rangep from and to. (eval_init): Register rangep intrinsic. * gc.c (mark_obj): Traverse RNG objects. (finalize): Handle RNG in switch. * hash.c (equal_hash, eql_hash): Hashing for for RNG objects. * lib.c (range_s, rcons_s): New symbol variables. (code2type): Handle RNG type. (eql, equal): Equality for ranges. (less_tab_init): Table extended to cover RNG. (less): Semantics defined for ranges. (rcons, rangep, from, to): New functions. (obj_init): range_s and rcons_s variables initialized. (obj_print_impl): Produce #R notation for ranges. (generic_funcall, dwim_set): Recognize range objects for indexing * lib.h (enum type): New enum member, RNG. MAXTYPE redefined to RNG value. (TYPE_SHIFT): Increased to 5 since there are now 16 type codes. (struct range): New struct type. (union obj): New member rn, of type struct range. (range_s, rcons_s, rcons, rangep, from, to): Declared. (range_bind): New macro. * parser.l (grammar): New rule for recognizing the #R sequence as HASH_R token. * parser.y (HASH_R): New terminal symbol. (range): New nonterminal symbol. (n_expr): Derives the new range symbol. The n_expr DOTDOT n_expr rule produces rcons expression rather than const. * match.c (format_field): Recognize rcons syntax in fields which is now what ranges translate to. Also recognize range object. * tests/013/maze.tl (neigh): Fix code which destructures range as a cons. That can't be done any more. * txr.1: Document ranges.
* Move noreturn macro.Kaz Kylheku2015-10-281-0/+6
| | | | | | * lib.h (noreturn): Defined here. * unwind.h (noreturn): Removed from here.