summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
* New hist-sort function.Kaz Kylheku2023-09-251-0/+44
| | | | | | | | | | | | | | | * eval.c (eval_init): Register hist-sort intrinsic. * lib.c (gt_f): New global variable. (hist_succ_f): New static variable. (hist_succ): New static function. (hist_sort): New function. * lib.h (gt_f, hist_sort): Declared. * tests/012/sort.tl: New tests. * txr.1: Documented.
* New T mode for open-file.Kaz Kylheku2023-09-231-1/+53
| | | | | | | | | | | | | | | The T mode uses O_TMPFILE to create an unlinkd temporary file. * stream.h (struct stdio_mode): New flag, tmpfile. (stdio_mode_init_blank, stdio_mode_init_r, stdio_mode_init_rpb): Updated to cover new bitfield member. * stream.c (w_open_mode): If tmpfile flag is on, add O_TMPFILE. (do_parse_mode): Recognize "T" mode selector and set all appropriate mode bits. If we are not on a platform that has O_TMPFILE, set the maformed flag. * txr.1: Documented.
* New function: rlink.Kaz Kylheku2023-09-231-2/+14
| | | | | | | | | | | | | | | This uses the linkat function to implement a variant of link which resolves the source object if it is a symlink. * configure: test for linkat. * sysif.c (link_wrap_common): New static function, used by both link_wrap and rlink_wrap. (link_wrap): Now a one-liner which calls link_wrap_common. (rlink_wrap): New static function. (sysif_init): Register rlink intrinsic. * txr.1: Documented.
* doc: awk: records and fieldsKaz Kylheku2023-09-221-1/+1
| | | | | * txr.1: the awk macro divides input into records and fields, not records or fields.
* doc: fix "uninterested symbols".Kaz Kylheku2023-09-221-1/+1
| | | | | * txr.1: in description of weak packages, fix "uninterested" symbols to "discarded".
* doc: fix wording problem in hash-map.Kaz Kylheku2023-09-221-5/+9
| | | | | * txr.1: Fix hash-map being described as constructing a function. It returns a hash table. Revise wording.
* doc: fix instances arguments-apply-to-function wording.Kaz Kylheku2023-09-221-21/+27
| | | | | | | | * txr.1: Revise all wording which says that arguments are applied to a function, or other object being used as a function. I seem to remember taking the same initiative some years ago, but wrong usages have snuck in. I even found some in the definition of the apply function.
* New functions: nested-vec-of and nested-vec.Kaz Kylheku2023-09-211-0/+81
| | | | | | | | | | | | | | | * eval.c (eval_init): Register nestd-vec-of and nested-vec intrinsics. * lib.[ch] (vec_allocate, vec_own, vec_init): New static functions. (vector, copy_vec): Expressed in terms of new functions. (nested_vec_of_v, nested_vec_v): New functions. * args.[ch] (args_cat_from): New function. * tests/010/vec.tl: New tests. * txr.1: Documented.
* doc: glob*: spellingKaz Kylheku2023-09-131-2/+2
| | | | * txr.1: Typos in recently added paragraphs.
* New place-mutating macro ensure.Kaz Kylheku2023-09-131-0/+48
| | | | | | | | | * autload.c (place_set_entries): Add ensure as an autoload trigger symbol for the place module. * stdlib/place.tl (ensure): New macro. * txr.1: Documented.
* chdir: support stream and fd argument via fchdir.Kaz Kylheku2023-09-121-4/+17
| | | | | | | | | | | * configure: new test for fchdir resulting in HAVE_FCHDIR. * sysif.c (get_fd): Define for HAVE_FCHDIR also. (chdir_wrap): If HAVE_FCHDIR, handle non-string arguments via fchdir, with help of get_fd. * txr.1: Documented.
* New glob* function.Kaz Kylheku2023-09-121-2/+220
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The glob* function supports brace expansion, the ** pattern for matching zero or more path components, as well as a sane sort for path names. glob* relies on brace expansion written in Lisp; the ** processing and sorting is done by a glob-compatible C function called super_glob that uses glob. * autoload.c (glob_set_entries, glob_instantiate): New static functions. (autoload_init): Register autoload of stdlib/glob module. * glob.c (GLOB_XNOBRACE, GLOB_XSTAR): New macros. (glob_wrap): Call super_glob instead of glob if GLOB_XSTAR is present in flags. Avoid passing extension flags to glob. (super_glob_find_inner, super_glob_rec, glob_path_cmp, glob_str_cmp, super_glob): New static functions. (glob_init): Register sys:glob-xstar, and glob-xnobrace. sys:glob-xstar is used by glob* to request support for the ** pattern from glob. * stdlib/glob.tl: New file. * tests/018/glob.tl: New file. * txr.1: Documented.
* json: allow integers and lists.Kaz Kylheku2023-09-031-2/+10
| | | | | | | | | | | | * lib.c (out_json_rec): Handle NUM and BGNUM cases same as FLNUM so integers get printed. The restriction against integers has been largely unhelpful and bothersome. Handle LCONS together with CONS. Lists that are not special notation fall through to the VEC case, which now uses seq_iter_t iteration to handle vectors and lists. * tests/010/json.tl: New tests. * txr.1: Documented support for printing integers and lists.
* crypt: detect error tokens more weakly; drop some tests.Kaz Kylheku2023-09-031-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | It has been reported by user cielesti that some of our crypt tests fail on the Musl library. Musl has some additional agorithms so it yields a meaningful hash for a "$0$" salt, as well as for "$9$". Musl uses "*" and "x" as error tokens rather than "*0" and "*1". We need to change how we detect error tokens. * sysif.c (crypt_wrap): Detect error tokens only by their length: if a string emerges from crypt or crypt_r, whose length is less than 13, it's an error token. * tests/018/crypt.tl: Drop the tests that require :error for salts "$0$" and "$9$", replacing them with a test for a salt that is almost certainly invalid in all C libraries on Linux. * txr.1: Document that crypt throws an error exception and under what circumstances (when the C library function does what).
* New functions for shell escaping.Kaz Kylheku2023-09-011-0/+90
| | | | | | | | | | | * stream.c (sh_esc, sh_esc_all, sh_esc_dq, sh_esc_sq): New static functions. (stream_init): sh-esc, sh-esc-all, sh-esc-dq, sh-esc-sq: Intrinsics registered. * tests/018/sh-esc.tl: New file. * txr.1: Documented.
* New function: str-esc.Kaz Kylheku2023-09-011-0/+37
| | | | | | | | | | * lib.[ch] (str_esc): New function. * eval.c (eval_init): str-esc intrinsic registered. * tests/015/esc.tl: New file. * txr.1: Documented.
* awk: prn returns nil.Kaz Kylheku2023-08-261-0/+5
| | | | | | | | | * stdlib/awk.tl (awk-state prn): Return nil in the no-argument case instead of returning whatever put-string returns. * tests/015/awk-misc.tl: New file. * txr.1: Documented.
* New macros opf and lopf.Kaz Kylheku2023-08-231-0/+78
| | | | | | | | | | | | | | These remove repetitive (op ...) syntax from the arguments of functional combinators. * stdlib/opt.tl (opf, lopf): New macros. * autoload.c (op_set_entries): Register opf and lopf as autoload triggers. * tests/012/op.tl: New tests. * txr.1: Documented.
* load-args-process: bugfix: :compile action must load.Kaz Kylheku2023-08-221-2/+11
| | | | | | | | | | * stdlib/load-args.tl (load-args-process): When compile-update-file doesn't do anything due to the compiled file being up-to-date, the file must be loaded, so that the effect is similar to compiling. Otherwise subsequent files may fail to compile due to missing definitions such as packages. * txr.1: Documented.
* New function: csort-group.Kaz Kylheku2023-08-171-1/+10
| | | | | | | | | | | | | * autoload.c (csort_set_entries): Register csort-group as autoload trigger for stdlib/csort.tl. * stdlib/csort.tl (csort-group): New function. * tests/012/sort.tl: Tests for sort-group and csort-group. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* doc: massive revision of capitalization in headings.Kaz Kylheku2023-08-161-81/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | In this patch we change the convention of uncapitalized words occurring in headings such as "Special variable *foo*". * checkman.txr (check-var, check-func): Consolidated into a single pattern function called check-coNP. This now enforces capitalization, and also has a giant fall-back clause which explicitly recognizes .coNP headings that are not specially checked by the previous rules, after which there is an error case, so that unclassified .coNP headings are diagnosed. A bug is fixed here in the handling of Special Variable and Variable headings. The pattern match was wrong, so these were not being properly recognized. Without the error case at the end, a number of errors occur in the document where the .desc is missing after a Variable or Special Variable. * txr.1: (.dir, .dirs): Fix capitalization of Directive and Directives in headings generated by this macro. Fix capitalization in numerous .coNP headings. * stdlib/doc-syms.tl: Updated. Unfortunately, many symbols change their hash value because it's based on the entire heading.
* doc: typo in *stdnull* example.Kaz Kylheku2023-08-161-1/+1
| | | | | * txr.1: Fix misspelled *stderr* in example demonstrating binding of *stderr* to *stdnull*.
* doc: capitalize User-defined in heading.Kaz Kylheku2023-08-161-1/+1
| | | | * txr.1: Fix "User-defined Patterns" heading to "User-Defined".
* math: tofloat and toint in user-defined arithmetic.Kaz Kylheku2023-08-141-0/+31
| | | | | | | | | | | | | | | | | | * arith.c (tofloat_s, toint_s): New symbol variables. (tofloat, toint): If the argument is a COBJ, handle it via do_unary_method. (arith_init): Initialize new symbol variables. The functions tofloat, toint, tofloatz and tointz. are now registered here, rather than eval_init. * eval.c (eval_init): Remove registrations of tofloat, toint, tofloatz and tointz. * tests/016/ud-arith.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* listener: auto compound expression mode.Kaz Kylheku2023-08-141-0/+29
| | | | | | | | | | | | | * parser.c (listener_auto_compound_s): New symbol variable. (repl): If *listener-auto-compound-p* is true, then evaluate multiple forms directly as a compound expression, without inserting progn at the head. (parse_init): Initialize symbol variable and register the *listener-auto-compound-p* special. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* unuse-sym: fix in face of use-sym-as.Kaz Kylheku2023-08-101-0/+42
| | | | | | | | | | | | | * lib.c (unuse_sym): A used symbol may now appear in a package under a different name. So if we don't find a symbol under the symbol's name, or find a different symbol, we must try a reverse hash search before giving up. * txr.1: Add notes to use-sym-as that unuse-sym must be used to undo its effect. Add notes to unuse-sym discussing similarities and differences versus unintern. * tests/012/use-as.tl: New test cases.
* New feature: local symbol renaming.Kaz Kylheku2023-08-101-27/+149
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The new function use-sym-as can bring a foreign symbol into a package under a different name, which is not that symbol's name. This is also featured in a new defpackage clause, :use-syms-as. With this simple relaxation in the package system, we don't require package local nicknames, which is more complicated to implement and less ergonomic, because it doesn't actually vanquish the use of ugly package prefixes on clashing symbols. * eval.c (eval_init): Register use-syms-as. * lib.c (use_sym_as): New function, made out of use_sym. (use_sym): Now a wrapper for use_sym_as. * lib.h (use_sym_as): Declared. * stdlib/package.tl (defpackage): Implement :use-syms-as clause. * tests/012/use-as.tl: New file. * txr.1: Documented, * stdlib/doc-syms.tl: Updated.
* new: left-inserting pipeline operators.Kaz Kylheku2023-08-081-7/+52
| | | | | | | | | | | | | | | | | | | * stdlib/op.tl (opip-expand): Take arguments which specify the op and do operators to be inserted. Pass these through the recursive calls. (opip, oand): Pass op and do for the new arguments. (lopip, loand): New macros like opip and oand, but passing lop and ldo to the expander. (lflow): New macro. * autoload.c (op_set_entries): Add autoload entries for lopip, loand and lflow. * tests/012/op.tl: A few new tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated.
* doc: bit ore advice on unused variable diagnotics.Kaz Kylheku2023-08-081-1/+12
| | | | | * txr.1: Mention that @nil can be used in pattern matching to suppress unused variable warnings.
* close-stream: new : protocol from close method.Kaz Kylheku2023-08-071-0/+36
| | | | | | | | | | | | | * stream.c (close_stream): If the underlying method returns the colon symbol :, then keep the cached close_result as nil, so that the method can be called again, but return t to the caller to indicate success. * tests/018/close-delegate.tl: Test case added. * tests/018/close-delegate.expected: Updated. * txr.1: Documented.
* streams: close-stream only caches non-nil result.Kaz Kylheku2023-08-071-0/+2
| | | | | | | | | | | | | | | | | | | | This is motivated by trying to implement a struct delegate stream which performs reference counting in close, in order to close the real stream when the count hits zero. The caching behavior of close-stream is a problem. * stream.c (strm_base_init): Initialize close_result to nil, rather than nao. (strm_base_mark): Don't check close_result for nao. (close_stream): Suppress the call to op->close if close_result has a non-nil value, rather than a value other than nao. * tests/018/close-delegate.tl, * tests/018/close-delegate.expected: New files. * txr.1: Document that only a non-nil return is cached by close-stream.
* Version 291.txr-291Kaz Kylheku2023-08-061-3/+3
| | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated.
* doc: new typo in compat notes.Kaz Kylheku2023-08-031-1/+1
| | | | * txr.1: Fix misspelled "elements" in 289 compatibility notes.
* opip: new special handling of (let ...).Kaz Kylheku2023-08-031-1/+126
| | | | | | | | | | | | | * stdlib/op.tl (sys:opip-single-let-p, sys:opip-let-p): New functions. (sys:opip-expand): Restructure from collect loop to car/cdr recursive form, because the new let operators in opip need access to the rest of the pipeline. Implement let operators. * tests/012/op.tl: New tests. * txr.1: Documented.
* Version 290.txr-290Kaz Kylheku2023-07-291-3/+3
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* match: bug: lexical symbol macros neglectedKaz Kylheku2023-07-271-5/+8
| | | | | | | | | | | | | | | | | | When a pattern variable match like @foo references a global symbol macro, that's treated as an existing expression to match, and not a new binding. However, local symbol macros are not treated this way; they are invisible to variable patterns. That is an unintended inconsistency. * stdlib/match.tl (var-list exists): Use lexical-binding-kind rather than lexical-var-p. This returns true for lexical symbol macros also. * tests/011/patmatch.tl: New test cases. * txr.1: Documentation revised to clarify that both global and local symbol macros are considered to be existing variable bindings by pattern matching.
* New functions and fixes in lexical introspection.Kaz Kylheku2023-07-271-14/+94
| | | | | | | | | | | | | | | | | | | | | | * evalc (macro_k): New keyword symbol variable. (lexical_binding_kind, lexical_fun_binding_kind) New functions. (lexical_var_p): Bugfix: if the symbol is a special variable, do not short-circuit to a nil answer. Special variables can be shadowed by symbol macros. The function is now defined in terms of lexical_binding_kind. (lexical_symacro_p, lexical_macro_p): New functions. (lexical_fun_p): Now defined using lexical_fun_binding_kind. (lexical_lisp1_binding): Bugfix: check for special variables; do not report special variables as :var. (eval_init): Initialize macro_k. Register new intrinsics: lexical-binding-kind, lexical-fun-binding-kind, lexical-symacro-p, lexical-macro-p. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* del/replace with index-list: fix semantics.Kaz Kylheku2023-07-181-9/+46
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit does two things. The replace function, implemented under the hood by four specializations: replace-list, replace-vec, replace-str and replace-buf, will handle the index-list case a little differently. This is needed to fix the ability of the del macro work on place designated by an index list, such as: (del [sequence '(1 3 5 6)] which now deletes elements 1, 3, 5 and 6 from the sequence, and returns a sequence of those items. The underlying implementation uses replace with an index-list, which is now capable of deleting items. Previously, replace would stop processing the index list when the replacement-sequence corresponding to the index list ran out of items. Now, when the replacement-sequence runs out of items, the remaining index-list sequence elements specify items to be deleted. For instance if str holds "abcdefg" then: (set [str '(1 3 5)] "xy") will change str to "axcyeg". Elements 1 and 3 are replaced by x and y, respectively. Element 5, the letter f, is deleted, because the replacement "xy" has no element corresponding to 5. * lib.c (replace_list, replace_str, replace_vec): Implement new deleteion semantics for the case when the replacement sequence runs out of items. * buf.c (replace_buf): Likewise. * tests/010/seq.txr: Some new test cases here for deletion. * tests/010/seq.expected: Updated. * txr.1: Documented new semantics of replace, including a new restriction that if elements are being deleted, the indices should be monotonically increasing regardless of the type of the sequence (not only list). A value of 289 for the -C option documented, which restores the previous behavior of replace (breaking deletion by index-list, unfortunately: you don't always get to simulate an old version of TXR while using new features.)
* doc: fix recent typos.Kaz Kylheku2023-07-181-2/+2
| | | | | | * txr.1: fix misspelling of Arithmetic and algorithm introduced by recent updates: new math functions, and documentation of CRC-32 parameters.
* Math library: add numerous C99 functions.Kaz Kylheku2023-07-151-0/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * configure: Detect all the new functions, with separate tests for the unary and binary ones. * arith.c (cbrt_s, erf_s, erfc_s, exp10_s, exp2_s, expm1_s, gamma_s, j0_s, j1_s, lgamma_s, log1p_s, logb_s, nearbyint_s, rint_s, significand_s, tgamma_s, y0_s, y1_s, copysign_s, drem_s, fdim_s, fmax_s, fmin_s, hypot_s, jn_s, ldexp_s, nextafter_s, remainder_s, scalb_s, scalbln_s, yn_s, r_copysign_s, r_drem_s, r_fdim_s, r_fmax_s, r_fmin_s, hypot_s, r_jn_s, r_ldexp_s, r_nextafter_s, r_remainder_s, r_scalb_s, scalbln_s, r_yn_s): New symbol variables. (not_available): New static function. (cbrt_wrap, erf_wrap, erfc_wrap, exp10_wrap, exp2_wrap, expm1_wrap, gamma_wrap, j0_wrap, j1_wrap, lgamma_wrap, log1p_wrap, logb_wrap, nearbyint_wrap, rint_wrap, significand_wrap, tgamma_wrap, y0_wrap, y1_wrap, copysign_wrap, drem_wrap, fdim_wrap, fmax_wrap, fmin_wrap, hypot_wrap, jn_wrap, ldexp_wrap, nextafter_wrap, remainder_wrap, scalb_wrap, scalbln_wrap, yn_wrap): New static functions. (arith_set_entries, arith_instantiate): New static functions. (arith_init): Initialize symbols and instantiate functions via autoload mechanism. In a program that doesn't use the functions, we suffer only the overhead of interning the symbols. * lib.h (UNUSED): New macro for GCC unused attribute. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* group-reduce: use sequence iteration.Kaz Kylheku2023-07-101-1/+1
| | | | | | | | * hash.c (group_reduce): Use seq_iter_t instead of obsolete vector and list iteration. * txr.1: Use 1..11 range in one group-reduce example instead of (range 1 10).
* group-by: use sequence iteration.Kaz Kylheku2023-07-101-5/+4
| | | | | | | | | | | * hash.c (group_by): Replace obsolete list/vector switching with seq_iter_t iteration. The group-by function is limited otherwise. * txr.1: Update group-by documentation not to assert that the sequence argument is required to be a list or vector. Examples for group-by and group-map now use a 0..11 range instead of (range 0 10).
* doc: document SHA-1 support.Kaz Kylheku2023-07-081-4/+68
| | | | | | * txr.1: SHA-1 functions documented. * stdlib/doc-syms.tl: Updated.
* doc: fix SHA256.Kaz Kylheku2023-07-081-3/+3
| | | | * txr.1: SHA256 should be SHA-256 in several places.
* doc: document crc32 parameters.Kaz Kylheku2023-07-081-0/+9
| | | | | * txr.1: Specify which crc32 is implemented: which polynomial, bit direction, and complementation of the output.
* Version 289.txr-289Kaz Kylheku2023-07-021-3/+3
| | | | | | | | | | | | | | * RELNOTES: Updated. * configure (txr_ver): Bumped version. * stdlib/ver.tl (lib-version): Bumped. * txr.1: Bumped version and date. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* Callable integers become assignable places.Kaz Kylheku2023-06-301-1/+27
| | | | | | | | | * lib.c (dwim_set): Handle seq argument being an integer or range. * tests/012/callable.tl: A few tests. * txr.1: Documented.
* New: callable integers and ranges.Kaz Kylheku2023-06-281-0/+35
| | | | | | | | | | | | | | | | | * lib.c (do_generic_funcall): Allow integers and ranges to be function callable. They take one argument and index into it or extract a slice. In the case of ranges, this is a breaking change. Ranges can already be used in the function position in some limited ways that are not worth preserving. * tests/012/callable.tl: New file. * tests/012/iter.tl: Here we fix two instances of breakage. Using txr -C 288 will restore the behaviors previously tested here. * txr.1: Documented.
* New cached sorting functions.Kaz Kylheku2023-06-281-0/+29
| | | | | | | | | | | | | | | | | | These functions are useful when sorting a sequence using an expensive keyfun. * autoload.c (csort_set_entries, csort_instantiate): New static functions. (autlod_init): Register autoloading of csort module via new functions. * stdlib/csort.tl: New file. * tests/012/sort.tl: csort functions included in tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: hash-map.Kaz Kylheku2023-06-281-0/+32
| | | | | | | | | | | | | | | | | | | | hash-map converts a function mapping over a sequence into a hash table. * hash.[ch] (hash_map): New function. * tests/010/hash.tl: Test case. * genman.txr: The hash-map identifier introduces a hash collision. We have to deal with that somehow now. (colli): We put the conflicting entries into a new hash called colli which maps them to an increment value. (hash-title): Increment the hash code h by the amount indicated in colli, if the title is found there. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.