summaryrefslogtreecommitdiffstats
path: root/lib.c
Commit message (Collapse)AuthorAgeFilesLines
* Pass pretty flag to cobj print operation.Kaz Kylheku2015-08-011-4/+4
| | | | | | | | | | | | | | | | | | | | | * hash.c (hash_print_op): Take third argument, and call cobj_print_impl rather than cobj_print. * lib.c (cobj_print_op): Take third argument. The object class is * printed with obj_print_impl. (obj_print_impl): Static function becomes extern. Passes its pretty flag argument to cobj print virtual function. * lib.h (cobj_ops): print takes third argument. (cobj_print_op): Declaration updated. (obj_print_impl): Declared. * regex.c (regex_print): Takes third argument, and ignores it. * stream.c (stream_print_op, stdio_stream_print, cat_stream_print): Take third argument, and ignore it. * stream.h (stream_print_op): Declaration updated.
* Multi-line, indented printing of structure.Kaz Kylheku2015-07-311-166/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (op_error): New static function. (macro_form_p, fboundp): Static to external. (special_operator_p): New function. (eval_init): Register macrolet and symacrolet to op_error. These are recognized and processed by expand, but we want them in the op table so they are reported by special_operator_p. * eval.h (fboundp, macro_form_p, special_operator_p): Declared. * hash.c (print_key_val): Break long lines on spaces between pairs with stream_width_check. (hash_print_op): Implement split and indented printing. * lib.c (obj_print_impl): New static function, resulting from a merge of obj_print and obj_pprint. Fixes some wrong-way recursion bugs: obj_pprint recursed into obj_print in some places. Adds support for multi-line printing of vectors and lists, with indentation using the new interfaces in streams. * stream.c (strm_base_init): Update initializer. (put_indent, indent_mode_put_string): New static functions. (put_string): Use indent_mode_put_string in either of the two indent modes. (put_char): Implement indent mode. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): New functions. * stream.h (enum indent_mode): New. (struct strm_base): indent_on member becomes indent_mode. New members data_width and code_width. (get_indent_mode, test_set_indent_mode, set_indent_mode, get_indent, set_indent, inc_indent, width_check): Declared. * tests/009/json.expected: Updated. * tests/010/seq.expected: Likewise. * tests/011/macros-2.expected: Likewise.
* Adding nthcdr as accessor.Kaz Kylheku2015-07-221-0/+13
| | | | | | | | | | | | * eval.c (eval_init): Register nthcdr function. * lib.c (nthcdr): New function. * lib.h (nthcdr): Declared. * share/txr/stdlib/place.tl (nthcdr): New defplace. * txr.1: Documented.
* Implementing second through tenth as places.Kaz Kylheku2015-07-221-10/+30
| | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register second through tenth as intrinsic. * gencadr.txr: New cadr.c changes encoded. * lib.c (second, third, fourth, fifth, sixth): Functions reimplemented using ref, so they are much more efficient for vectors and strings. (seventh, eighth, ninth, tenth): New functions. * lib.h (seventh, eighth, ninth, tenth): Declared. * share/txr/stdlib/place.tl: place macros defined for second through tenth. * txr.1: Documented.
* * lib.c (obj_print, obj_pprint): Bugfix: incorrectKaz Kylheku2015-07-221-2/+4
| | | | | value returned when printing dwim forms, due to mutating the obj variable.
* Implementing caar, cadr, cdar and friends.Kaz Kylheku2015-07-211-0/+2
| | | | | | | | | | | | | | | | | | | | * lib.c (init): Call cadr_init. * lisplib.c (dl_table, set_dlt_entries, dlt_register): Externalize. * lisplib.h (dl_table, set_dlt_entries, dlt_register): Declared. * Makefile (OBJS): Add cadr.o. * cadr.c: New file. * cadr.h: New file. * gencadr.txr: New file. * share/txr/stdlib/cadr.tl: New file. * txr.1: Document cadr accessors.
* * eval.c (eval_init): Register new split function.Kaz Kylheku2015-07-211-2/+48
| | | | | | | | | | | | * lib.c (split_func): New static function. (partition_split_common): New static function, based on on contents of partition function. (partition): Now a wrapper around partition_split_common. (split): New function. * lib.h (split): Documented. * txr.1: Documented split.
* Refactoring n-ary functions to use a single helper.Kaz Kylheku2015-07-241-20/+13
| | | | | | | * lib.c (nary_op): New function. (plusv, mulv, logandv, logiorv): Use nary_op. * lib.h (nary_op): Declared.
* * lib.c (mkstring): Fix neglect to null terminate.Kaz Kylheku2015-06-181-3/+4
|
* * lib.c (cat_str): Detect overflow in the total lengthKaz Kylheku2015-06-181-4/+21
| | | | calculation.
* * lib.c (replace_list, replace_str, replace_vec): HandleKaz Kylheku2015-05-141-0/+61
| | | | | | | | the case when from is a vector, for consistency with the sel function and the dwim operator. * txr.1: Document that the third argument of select and replace may be a vector.
* Recursive lcons force bug (keep-if*, remove-if*).Kaz Kylheku2015-05-131-1/+3
| | | | | * lib.c (rem_lazy_func): Do not access the cdr field of the lcons that we are in the middle of forcing!
* Handle vectors and strings in rplaca and rplacd.Kaz Kylheku2015-05-111-2/+12
| | | | | | * lib.c (rplaca, rplacd): Use refset and replace respectively to handle vectors and strings. Adjust type mismatch error message.
* * lib.c (chr_str_set): Check for literal strings.Kaz Kylheku2015-05-111-0/+5
|
* Crack down on redefinitions of built-ins.Kaz Kylheku2015-05-081-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (builtin, eval_initing): New global variable. (op_defun, op_defmacro): During initialization, record functions and macros in builtin hash. (builtin_reject_test): New static function. (expand_macrolet): Perform builtin reject test for fbind, lbind, and macrolet. (regfun, reg_mac): Add symbol to builtin hash. (eval_init): GC-protect new hash table variable and initialize it. Set eval_initing to true over eval initialization. The flip function is renamed fo flipargs. (eval_compat_fixup): New function, for dealing with the operator/function conflict over flip. * eval.h (eval_compat_fixup): Declared. * lib.c (compat_fixup): Call eval_compat_fixup. * tests/011/macros-2.txr: This test was defining a macro called while which is now illegal. Renamed to whilst. * tests/011/macros-2.expected: Regenerated. * txr.1: Function flip renamed to flipargs and documented in Compatibility section.
* New macro-based framework for assignment places.Kaz Kylheku2015-05-061-1/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The operators set, inc, dec, pop and others are now macros which generate code, rather than built-in special forms that use "C magic". Moreover, new such macros are easy to write, and several new ones are already available. Moreover, new kinds of assignable places are easy to create. * place.tl: New file. * lisplib.c, lisplib.h: New files. * Makefile (OBJS): New target, lisplib.o. (GEN_HDRS): New variable. (LISP_TO_C_STRING): New recipe macro, with rule. (clean): Remove generated headers named in $(GEN_HDRS). * eval.c (dec_s, push_s, pop_s, flip_s, del_s): Variables removed. (setq_s): New variable. (lookup_var, lokup_sym_lisp_1, lookup_var_l, lookup_fun, lookup_mac, lookup_symac, lookup_symac_lisp1): Trigger the delayed loading of libraries for undefined global symbols, and re-try the lookup. (op_modplace, dwim_loc, force_l): Static functions removed. (op_setq): New static function. (eval_init): Initialize setq_s; remove initializations of removed variables; remove registrations for op_modplace; add registration for sys:setq, sys:rplaca, sys:rplacd, sys:dwim-set and sys:dwim-del intrinsics. Call lisplib_init to initialize the dynamic library loading module. * lib.c (sys_rplaca, sys_rplacd): New functions, differing in return value from rplaca and rplacd. (ref, refset): Handle hash table. (dwim_set, dwim_del): New functions. * lib.h (sys_rplaca, sys_rplacd, dwim_set, dwim_del): Declared. * genvim.txr: Include place.tl in scan. * tests/010/seq.txr: The del operator test case no longer throws at run-time but at macro-expansion time, so the test case is simply removed. * tests/010/seq.expected: Updated output. * tests/011/macros-2.txr: Reset *gensym-counter* to zero, because the textual output of the test case includes gensyms, whose numberings fluctuate with the content of the new Lisp library material. * tests/011/macros-2.expected: Updated output.
* Deal with bad quote syntax.Kaz Kylheku2015-05-031-2/+2
| | | | | | | * eval.c (op_quote): Throw error on bad syntax. * lib.c (obj_print, obj_pprint): Do not hide bad quote syntax using ' notation; print it using ordinary notation.
* Move initialization calls to more suitable place.Kaz Kylheku2015-05-011-0/+10
| | | | | | | | * lib.c (init): Initialize parser, syslog and glob modules here. * txr.c (main): Remove initialization of parser, syslog and glob modules from here.
* Bugfix: cannot print (lambda . 42) structure.Kaz Kylheku2015-04-291-2/+2
| | | | | * lib.c (obj_print, obj_pprint): Fix mistake in the test for properly formed lambda syntax whcih is printed specially.
* * lib.c (symbol_package): If the argument is nil, returnKaz Kylheku2015-04-251-1/+1
| | | | | the user package directly, not the value of the *user-package* variable.
* Remove silly package lookup from keywordp.Kaz Kylheku2015-04-251-1/+1
| | | | | | | | | | This tiny change yields a 165% (2.65X) speedup in the tst/tests/011/mandel.txr test case. * lib.c (keywordp): Use keyword_package_var instead of the keyword_package macro which looks up the global environment. * parser.y (sym_helper): Likewise.
* Adding getenv, setenv and unsetenv.Kaz Kylheku2015-04-181-6/+7
| | | | | | | | | | | | | | * lib.c (setenv, unsetenv): Changed static functions to external. Moved them out of the #if !HAVE_TIMEGM block. * lib.h (setenv, unsetenv): Declared. * sysif.c (getenv_wrap, setenv_wrap, unsetenv_wrap): New functions. (sysif_init): Registered getenv, setenv and unsetenv. * txr.1: Documented getenv, setenv and unsetenv. * tl.vim, txr.vim: Regenerated.
* Deal with spurious retention in function application.Kaz Kylheku2015-03-311-76/+78
| | | | | | | | | | | | * gc.h (zap): New inline function. (z): New macro. * lib.c (generic_funcall, funcall1, funcall2, funcall4, do_not, do_dup, do_iff): Use z macro to burn funargs with no next use. * eval.c (apply, apply_frob_args, iapply, call, do_eval, op_dwim, mapcarv, mappendv, lazy_mapcarv_func, mapdov, do_apf, do_ipf, callf): Use z macro to burn funargs with no next use.
* * eval.c (eval_init): register get-lines as having one optionalKaz Kylheku2015-03-281-0/+2
| | | | | | | | argument. * lib.c (lazy_stream_cons): Default the argument to std_input. * txr.1: Document that the stream is optional in get-lines.
* * lib.c (int_str): Workaround for wcstol recognizing the 0x prefix whenKaz Kylheku2015-03-201-1/+27
| | | | | | | radix is 16. Also, thrown an error if radix is not in the range 0 to 36. * txr.1: Document int-str's radix range restriction.
* Introducing persistent error state on streams.Kaz Kylheku2015-02-251-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.c (cobj_ops): New function. * lib.h (cobj_ops): Declared. * stream.c (null_ops): Initializer updated. (struct stdio_handle): New member, err. (stdio_stream_mark): Mark the err member. (errno_to_string): New static function. (stdio_maybe_read_error, stdio_maybe_error): Set persistent error state. Use errno_to_string_function. (stdio_put_string, stdio_put_char, stdio_put_byte, stdio_seek, stdio_get_line): Set errno to zero, so that if the underlying operations do not set errno on err, we don't misinterpret some pervious errno value as pertaining to the failed stream operation. (stdio_get_error, stdio_get_error_str, stdio_clear_error): New static functions. (stdio_ops, tail_ops, pipe_ops): Update initializer with new functions. (string_in_get_error, string_in_get_error_str): New static functions. (string_in_ops): Update initializer with new functions. (byte_in_get_error, byte_in_get_error_str): New static functions. (byte_in_ops): Update initializer with new functions. (string_out_ops, strlist_out_ops): Update initializer with null pointers for new functions. (struct dir_handle): New struct type. (dir_destroy, dir_mark): New functions. (dir_get_line): Refactor for struct dir_handle context rather than DIR. Persist error state. (dir_close): Refactor for struct dir_handle. (dir_get_error, dir_get_error_str, dir_clear_error): New static functions. (dir_ops): Update initializer with new functions. (make_stdio_stream_common): Initialize new err member. (make_dir_stream): Refactor for struct dir_handle. (get_error, get_error_str, clear_error): New functions. (cat_get_error, cat_get_error_str, cat_clear_error): New static functions. (cat_stream_ops): Update initializer with new functions. (stream_init): Register get-error, get-error-str, clear-error intrinsics. * stream.h (struct strm_ops): New function pointer members, get_error, get_error_str and clear_error. (strm_ops_init): Macro extended with new arguments for new function pointers. (get_error, get_error_str, clear_error): Declared. * syslog.c (syslog_strm_ops): Update initializer with null pointers for new functions. * txr.1: Documented get-error, get-error-str and clear-error.
* * lib.c (list_collect, list_collect_append): In errorKaz Kylheku2015-02-121-2/+2
| | | | | | messages about bad appends, do not show the list being appended because it may be an infinite lazy list. For instance (append* 3 lazy-list).
* * lib.c (lazy_appendv_func, lazy_appendv): Bugfix: append*Kaz Kylheku2015-02-121-2/+10
| | | | | | | | | was silently ignoring lists after the first atom, instead of throwing an error. Also, it was not detecting the case that the last argument is a list which should just be returned, and instead trying to find its tail in preparation for the next call to lazy_appendv_func, the consequences being runaway iteration over an infinite list.
* * unwind.c (unhandled_hook_s): New static variable.Kaz Kylheku2015-02-061-0/+1
| | | | | | | | | | | | | | | | | | | (uw_throw): In the unhandled case, check if *unhandled-hook* variable has a function, and use it instead of the default logic. If it's not a function, abort with an error message. Clear it so that if the hook function re-enters this code, it will not be used. Always exit now on unhandled exceptions; do not abort. (uw_late_init): New function. * unwind.h (uw_late_init): Declared. * lib.c (init): Call uw_late_init. * txr.1: Documented *unhandled-hook*. * genvim.txr: Scan the unwind.c file, since it has a reg_var now. * tl.vim, txr.vim: Updated.
* Update copyright notices from 2014 to 2015.Kaz Kylheku2015-02-011-1/+1
| | | | | | | | | | | * arith.c, arith.h, combi.c, combi.h, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, gc.c, gc.h, hash.c, hash.h, lib.c, lib.h, match.c, match.h, parser.h, rand.c, rand.h, regex.c, regex.h, signal.c, signal.h, stream.c, stream.h, sysif.c, sysif.h, syslog.c, syslog.h, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Update. * LICENSE, METALICENSE: Likewise.
* * lib.c (make_like): Fix regression introduced in 102.Kaz Kylheku2015-01-271-1/+1
| | | | | A one element list being converted to a string treated as an empty list, leading to empty string.
* * eval.c (eval_init): Register dupl and swap_12_21 asKaz Kylheku2015-01-251-0/+10
| | | | | | | | | | | the dup and flip intrinsics. * lib.c (do_dup): New static function. (dupl): New function. * lib.h (dupl): Declared. * txr.1: Documented dup and flip.
* * lib.c (make_like): Bugfix. (make-like nil "abc")Kaz Kylheku2015-01-111-0/+4
| | | | | | | | | | must return the empty string, not nil. Only lists of non-characters fail to convert to a string. Since programs may depend on the hitherto wrong, undocumented behavior, this is made subject to compatibility. * txr.1: Added compatibility note.
* * lib.c (replace_str, replace_vec): Bugfix. The replacement itemKaz Kylheku2014-12-311-87/+91
| | | | | | sequence may be an infinite list in the case that the from argument specifies a list of indices. We must avoid trying to calculate its length before we have detected this case.
* * lib.c (simple_lazy_stream_func): Bugfix: close the streamKaz Kylheku2014-12-251-2/+4
| | | | | | | | | | if get_line returns nil. * stream.c (cat_get_line, cat_get_char, cat_get_byte): The catenated stream read operations close an exhausted stream before popping to the next one. * txr.1: Document closing behavior of catenated streams.
* * eval.c (eval_init): Registered intrinsic function unique.Kaz Kylheku2014-12-231-4/+11
| | | | | | | | | | | * lib.c (unique): New function. (uniq): Becomes wrapper around unique. * lib.h (unique): Declared. * txr.1: Documented unique, and equivalence between uniq and unique. * tl.vim, txr.vim: Regenerated.
* * lib.c (func_n1ov, func_n2ov, func_n3ov): New functions.Kaz Kylheku2014-12-231-0/+21
| | | | * lib.h (func_n1ov, func_n2ov, func_n3ov): Declared.
* * lib.c (func_n0o): Useless, unused function removed.Kaz Kylheku2014-12-231-7/+0
| | | | * lib.h (func_n0o): Declaration removed.
* * lib.c (copy): Support copying random state objectsKaz Kylheku2014-12-181-1/+4
| | | | | | vi make_random_state. * txr.1: Updated.
* * eval.c (eval_init): Register in function as intrinsic.Kaz Kylheku2014-12-051-0/+70
| | | | | | | | | | * lib.c (in): New function. * lib.h (in): Declared. * txr.1: Documented in. * txr.vim, tl.vim: Regenerated.
* * lib.c (set_diff): Bugfix: use member rather than find,Kaz Kylheku2014-12-051-1/+1
| | | | so that a nil set element is handled properly.
* * eval.c (eval_init): Register lequal and gequal.Kaz Kylheku2014-11-271-0/+41
| | | | | | | | | | * lib.c (lequal, gequal, lequalv, gequalv): New functions. * lib.h (lequal, gequal, lequalv, gequalv): Declared. * txr.1: Documented lequal and gequal. * txr.vim, tl.vim: Regenerated.
* * eval.c (eval_init): Register less and greater toKaz Kylheku2014-11-271-0/+28
| | | | | | | | | | the lessv and greaterv functions instead of less and greater. * lib.c (lessv, greaterv): New functions. * lib.h (lessv, greaterv): Declared. * txr.1: Document variadic nature of less and greater.
* * eval.c (eval_init): Register sort-group.Kaz Kylheku2014-11-211-1/+9
| | | | | | | | * lib.c (sort_group): New function. * lib.h (sort_group): Declared. * txr.1: Documented.
* * lib.c (partition_star_func): Bugfix: doing rplaca(env, seq)Kaz Kylheku2014-11-211-8/+7
| | | | | | too early, before the loop which adjusts its value. Restructuring this slightly to avoid duplicated code, by moving the !first check later.
* * lib.c (partition_by_func): Rename one local variable for clarity.Kaz Kylheku2014-11-211-9/+8
| | | | | Remove unessential variable last, and move the next variable into loop scope.
* * lib.c (where): Argument order reversed, with compat support.Kaz Kylheku2014-11-201-1/+7
| | | | | | * lib.h (where): Declaration updated. * txr.1: Documented.
* * lib.c (sel): Accept a function in place of the index list.Kaz Kylheku2014-11-201-1/+3
| | | | * txr.1: Documented.
* * lib.c (split_str): If the separator string is empty,Kaz Kylheku2014-11-171-1/+24
| | | | | | | | | | then unless opt_compat is 100 or less, provide a more consistent behavior, rather than splitting the string into characters. This latter behavior was never documented. * txr.1: Documented. * dep.mk: Updated.
* * lib.c (max2, min2): Use the less comparison functionKaz Kylheku2014-11-151-4/+4
| | | | | | | | | for generic semantics. * lib.h (max2, min2): Parameter names changed to avoid suggesting that the operands are numbers. * txr.1: Documentation for min and max updated.