summaryrefslogtreecommitdiffstats
path: root/stdlib/doc-syms.tl
Commit message (Collapse)AuthorAgeFilesLines
* doc: new hashing scheme for navigation, doc lookup.Kaz Kylheku2023-08-221-2318/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is not an easy change to make because it breaks the validity of existing URLs in the wild which point to specific sections of the TXR manual. Some of my recent changes to capitalization of numerous headings have already broken many URLs, so we might as well bite the bullet and do this now. The problem with the current scheme is that entire section titles are hashed: all the words of a title, not just the names of functions. Whenever we add a new function, macro or variable which is documented together with related functions in the same paragraph under the same heading, the heading changes, and the hash changes. For instance, the hash for the hash-map identifier is actually the hash of the string "Function <tt>hash-map</tt>". Under the new scheme, section titles are hashed in a more complicated way that is robust against most edits. If a title contains any symbols marked up with <tt>, then the leftmost such symbol is taken as the title. Otherwise, the whole title is mapped to lower case. There is no longer a stdlib/doc-syms.tl file, and the special disambiguated "D-<HEX>" codes are also gone. Symbols are no longer associated with section hashes or disambiguation section codes. The hash of a symbol is a 32 bit CRC-32 checksum, expressed as S-<HEX> where <HEX> is 8 hex digits. A section which defines symbols has not only a <a name="..."> for its own hash but also additional <a name="...>" elements for each of the symbols that it defines. If a section defines an ambiguous symbol (one that is also defined with a different meaning in a different section), then that symbol is not linked to either section; it is mapped to the generated disambiguating section. * genman.txr (dupes): Renamed to dupe-hashes for clarity. (tagnum): Hash removed. (direct): New hash. Tracks the assocation between sections hashes and hashes of symbols that are defined only in those symbols (no ambiguity) and thus the symbol hashes can navigate directly to the sections. Serves as a complement to the disamb hash. (colli): There are no collisions now, so initialize this to empty. (hash-str): Function removed. (hash-title): This function becomes more complicated. If a title has at least one <tt>..</tt> item, then that is taken in its place. Either way, the title is transformed and enumerated against duplication and hashed with crc32 instead of the original custom hashing function. (enumerate): Function removed: enumeration of titles is done inside hash-title. All manipulations of symhash using material from HTML now use html-decode, so that we hash the original symbol name like "str<" and not "str&lt;". When filtering the BODY, we have a new case: whenever we see a <a name="...">, we now check the new direct hash to see if there is a list of symbol hashes for the given section. If so, we generate additional <a name="..."> definitions for all the symbol hashes. At the end of the file, the "missing from image" processing is condensed, and the generation of the stdlib/doc-syms.tl file is removed. * stdlib/doc-syms.tl: Removed. * stdlib/doc-lookup.tl: Don't load doc-syms. Use crc32 plus formatting to conver a symbol to the hash that is used in the document and try the lookup with that.
* New function: csort-group.Kaz Kylheku2023-08-171-1/+2
| | | | | | | | | | | | | * 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-89/+89
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* math: tofloat and toint in user-defined arithmetic.Kaz Kylheku2023-08-141-119/+119
| | | | | | | | | | | | | | | | | | * 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/+1
| | | | | | | | | | | | | * 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.
* New feature: local symbol renaming.Kaz Kylheku2023-08-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-3/+6
| | | | | | | | | | | | | | | | | | | * 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.
* New functions and fixes in lexical introspection.Kaz Kylheku2023-07-271-2/+6
| | | | | | | | | | | | | | | | | | | | | | * 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.
* Math library: add numerous C99 functions.Kaz Kylheku2023-07-151-115/+159
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* doc: document SHA-1 support.Kaz Kylheku2023-07-081-4/+9
| | | | | | * txr.1: SHA-1 functions documented. * stdlib/doc-syms.tl: Updated.
* New cached sorting functions.Kaz Kylheku2023-06-281-0/+4
| | | | | | | | | | | | | | | | | | 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/+1
| | | | | | | | | | | | | | | | | | | | 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.
* eval: take macro environment.Kaz Kylheku2023-06-271-131/+131
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change we fix the bug that the debugger commands yield their Lisp forms rather than evaluating them. * eval.c (eval_intrinsic): Takes one more argument, the macro environment. This is passed into env_to_menv as the root macro environment. (eval_init): Update registration of eval intrinsic to have two optional arguments. * eval.h (eval_intrinsic): Declaration updated. * parser.c (read_file_common, read_eval_ret_last): Pass nil argument to new parameter of eval_intrinsic. (repl): Pass the env parameter as the new menv parameter of eval_intrinsic, rather than the existing env parameter. This fixes the command dispatch in the debugger, since the command table is consists of symbol macros, and not variables. For instance the backtrace command bt is a binding of the bt symbol to the form (sys:print-backtrace), which has to be substituted for it and executed. When that envrionment is used as the ordinary environment, bt looks like a variable whose value is the list (sys:backtrace). * parser.y (elem, check_parse_time_action): Fix eval_intrinsic calls. * txr.c (txr_main): Likewise. * txr.1: Documented. * y.tab.c.shipped: Updated. * stdlib/doc-syms.tl: Updated.
* New macro: match-cond.Kaz Kylheku2023-06-121-0/+1
| | | | | | | | | | | | | * stdlib/match.tl (match-cond): New macro. * autoload.c (match_set_entries): match-cond triggers autoload of match module. * tests/011/patmatch.tl: Tests. * txr.1: Documented. * stdlib/doc.tl: Updated.
* New @(push) directive.Kaz Kylheku2023-06-121-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | @(push) is like @(output), but feeds back into input. Use carefully. * parser.y (PUSH): New token. (output_push): New nonterminal symbol. (output_clause): Handle OUTPUT or PUSH via output_push. Some logic moved to output_helper. (output_helper): New function. Transforms both @(output) and @(push) directives. Checks both for valid keywords; push has only :filter. * parser.l (grammar): Recognize @(push similarly to other directives. * lib.[ch] (push_s): New symbol variable. * match.c (v_output_keys): Internal linkage changes to external. (v_push): New function. (v_parallel): We must fix the max_line algorithm not to use an initial value of zero, because lines can go negative thanks to @(push). We end up rejecting the pushed data. (v_collect): We can no longer assert that the data line number doesn't retreat. (dir_tables_init): Register push directive in table of vertical directives. * match.h (append_k, continue_k, finish_k): Existing symbol variables declared. (v_output_keys): Declared. * y.tab.c.shipped, * y.tab.h.shipped, * lex.yy.c.shipped: Updated. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New functions keep-keys-if, separate-keys.Kaz Kylheku2023-06-071-0/+2
| | | | | | | | | | | * lib.[ch] (keep_keys_if, separate_keys): New functions. * eval.c (eval_init): keep-keys-if, separate-keys intrinsics registered. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New functions load-args-recurse and load-args-processKaz Kylheku2023-06-051-0/+2
| | | | | | | | | | | | * autoload.c (load_args_set_entries, load_args_instantiate): New static functions. (autoload_init): Register new auto-loaded module "load-args". * stdlib/load-args.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* compiler: new function, clean-file.Kaz Kylheku2023-06-041-0/+1
| | | | | | | | | | | | | | | | This function simplifies cleaning, by allowing a file to be cleaned to be identified in much the same way as an input file to load or compile-file. * autoload.c (compiler_set_entries): The clean-file symbol is interned and becomes an autoload trigger for the compiler module. * stdlib/compiler.tl (clean-file): New function. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New macro: expander-let.Kaz Kylheku2023-05-281-0/+1
| | | | | | | | | | | | | * stdlib/expander-let.tl: New file. * autoload.c (expander_let_set_entries, expander_let_instantiate); New static functions. (autoload_init): Register autoloading of above new file via above new functions. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New special operator: compiler-letKaz Kylheku2023-05-161-0/+1
| | | | | | | | | | | | | | | | | | | | | | * eval.c (compiler_let_s): New symbol variable. (op_let): Recognize compiler-let for sequential binding. (do_expand): Traverse and diagnose compiler-let form. (eval_init): Initialize compiler_let_s and register the interpreted version of the operator. * stdlib/compiler.tl (compiler compile): Handle compiler-let form. (compiler comp-compiler-let): New method. (no-dvbind-eval): New function. * autoload.c (compiler-set-entries): Intern the compiler-let symbol in the user package. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New special operator: progvKaz Kylheku2023-05-151-0/+1
| | | | | | | | | | | | | | | | | | | | | | Adding a progv operator, similar to the Common Lisp one. * eval.c (progv_s): New symbol variable. (op_progv): New static function. (do_expand): Recognize and traverse the progv form. (rt_progv): New static function: run-time support for compiled progv. (eval_init): Initialize progv_s, and register the the op_progv operator interpreting function. * stdlib/compilert (compiler compile): Handle progv operator ... (compiler comp-progv): ... via this new method. * tests/019/progv.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* sort: support stable sorting via ssort and snsort.Kaz Kylheku2023-05-021-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For array-like objecgts, these objects use an array-based merge sort, using an auxiliary array equal in size to the original array. To provide the auxiliary array, a new kind of very simple vector-like object is introduced into the gc module: protected array. This looks like a raw dynamic C array of val type, returned as a val *. Under the hood, there is a heap object there, which makes the array traversable by the garbage collector. The whole point of this exercise is to make the new mergesort function safe even if the caller-supplied functions misbehave in such a way that the auxiliary array holds the only references to heap objects. * gc.c (struct prot_array): New struct, (prot_array_cls): New static variable. (gc_late_init): Register COBJ class, retaining in prot_array_cls. (prot_array_mark, prot_array_free): New static functions. (prot_array_ops): New static structure. (prot_array_alloc, prot_array_free): New functions. * gc.h (prot_array_alloc, prot_array_free): Declared. * lib.c (mergesort, ssort_vec): New static function. (snsort, ssort): New functions. * lib.h (snsort, ssort): Declared. * tests/010/sort.tl: Cover ssort. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* hash: new function, hash-props.Kaz Kylheku2023-05-011-0/+1
| | | | | | | | | | | | | | | | We don't have a function in the hash table module which can create a populated hash table in one step without requiring the caller to create auxiliary lists. This new function fills that gap, albeit with some limitations. * hash.c (hash_props): New function. (hash_init): Register hash-props intrinsic. * tests/010/hash.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* time: improved convenience in time functions.Kaz Kylheku2023-04-301-0/+2
| | | | | | | | | | | | | | | | * time.c (time_str_local, time_str_utc): New static functions. (time_fields_local, time_fields_utc, time_struct_local, time_struct_utc): Time argument becomes optional, defaulted to current time. (time_init): Use time_s symbol instead of interning twice. Register new time-str-local and time-str-utc intrinsics. Fix registration of functions that take optional args. * txr.1: New functions documented; optional arguments documented; existing documentation revised. * stdlib/doc-syms.tl: Updated.
* compiler: optimization improvementsKaz Kylheku2023-04-071-62/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * stdlib/optimize.tl (basic-blocks peephole-block): Drop the code argument, and operate on bl.insns, which is stored back. Perform the renames in the rename list after the peephole pass. (basic-blocks rename): New method. (basic-blocks do-peephole-block): Implementation of peephole-block, under a new name. The local function called rename is removed; calls to it go to the new rename method. (basic-blocks peephole): Simplify code around calls to peephole-block; we no longer have to pass bl.insns to it, capture the return value and store it back into bl.insns. * stdlib/compiler.tl (*opt-level*): Initial value changes from 6 to 7. (compiler optimize): At optimization level 6, we now do another jump threading pass, and peephole, like at levels 4 and 5. The peephole optimizations at level 5 make it possible to coalesce some basic blocks in some cases, and that opens up the possibility for more reductions. The previously level 6 optimizations are moved to level 7. * txr.1: Updated documentation of optimization levels, and default value of *opt-level*. * stdlib/doc-syms.tl: Updated.
* doc: compiler-opts typo.Kaz Kylheku2023-03-271-1/+1
| | | | | | | * txr.1: Fix compiler-opts, *compiler-opts* and with-compiler-opts to the correct "compile". * stdlib/doc-syms.tl: Updated.
* New function: arithp.Kaz Kylheku2023-03-261-0/+1
| | | | | | | | | | | | | | | | | | | * lib.h (arithp): Declared. (plus_s): Existing symbol declared. * arith.c (arithp): New function. * struct.h (special_slot): New enum member plus_m. * struct.c (special_sym): Register plus_s together as the [plus_m] entry of the array. * tests/016/arith.tl * tests/016/ud-arith.tl: Tests for arithp. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* compiler/doc: document compiler-opts and enable unused warningKaz Kylheku2023-03-231-0/+3
| | | | | | | | | | * stdlib/compiler.tl (sys:env shadow-fun): Also diagnose if a global macro is shadowed. * txr.1: Documented compiler-opts structure, *compiler-opts* variable and with-compiler-opts macro. * stdlib/doc-syms.tl: Updated.
* New function: ignore, synonym of nilf.Kaz Kylheku2023-03-211-2/+3
| | | | | | | | | | | | | | | This will be an official mechanism for indicating deliberately unused variables. * eval.c (eval_init): Register ignore intrinsic, binding to the same function object as nilf. * stdlib/compiler.tl (%const-foldable-funs%): Mention ignore function, next to its nilf synonym. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* doc: * function not mentioned in heading.Kaz Kylheku2023-01-021-74/+74
| | | | | | | | | | | | * txr.1: The functions -, + and * are documented together, but the section heading only mentions + and -. This was introduced when these functions were documented for the first time in March 2012, in commit 6363875356bc050ef81d40553e573fc47aca2e28, and then went unnoticed for almost eleven years in spite of the heading undergoing relocation and reformatting. * stdlib/doc-syms.tl: Updated.
* awk: new feature, res variable.Kaz Kylheku2022-12-301-0/+1
| | | | | | | | | | | | | | | | The res variable captures the specific value of the condition expression, making it available to the action. * autoload.c (awk_set_entries): Intern the res symbol * stdlib/awk.tl (awk): Instead of generating the condition-action into a simple when, we use whenlet to also bind the res variable. * tests/015/awk-res.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* doc: fix nonexistent macro name.Kaz Kylheku2022-12-301-1/+1
| | | | | | | * txr.1: *define-struct-prelude* should of course be define-struct-prelude. * stdlib/doc-syms.tl: Updated.
* New feature: struct preludes.Kaz Kylheku2022-11-031-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | A struct prelude definition associates one or more future defstruct (by struct name) with clauses which are implicitly inserted into the defstruct. It is purely a macro-time construct, customizing the expansion behavior of defstruct. * stdlib/struct.tl (*struct-prelude, *struct-prelude-alists*): New special variables holding hash tables. (defstruct): Before processing slot-specs, augment it with the contents of the prelude definitions associated with this struct name. (define-struct-prelude): New macro. * autoload.c (struct_set_entries): define-struct-prelude is interned and triggers autoload of struct module. * tests/012/oop-prelude.tl: New file. * tests/012/oop-prelude.expected: Likewise. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: macroexpand-struct-clause.Kaz Kylheku2022-10-131-0/+1
| | | | | | | | | | | * stdlib/struct.tl (macroexpand-struct-clause): New function. * autoload.c (struct_set_entries): Autoload struct module on macroexpand-struct-clause. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: macroexpand-match.Kaz Kylheku2022-10-131-0/+1
| | | | | | | | | | | * stdlib/match.tl (macroexpand-match): New function. * autoload.c (match_set_entries): Autoload match module on macroexpand-match. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: macroexpand-place.Kaz Kylheku2022-10-131-0/+2
| | | | | | | | | | | | | | | * stdlib/place.tl (sys:pl-expand): Function renamed to macroexpand-place; env parameter becomes optional. (macroexpand-1-place): New function. (place-form-p, call-update-expander, call-clobber-expander, call-delete-expander): Follow rename. * autoload.c (place_set_entries): Register symbols macroexpand-place and macroexpand-1-place for autoload. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: macroexpand-params.Kaz Kylheku2022-10-131-0/+1
| | | | | | | | | | | | | | | * stdlib/pmac.tl (macroexpand-params): New function, implemented using newly exposed sys:expand-param-macro. * autoload.c (pmac_set_entries): Trigger pmac.tl autload on macroexpand-params symbol. * eval.c (eval_init): Register existing expand_param_macro function as sys:expand-param-macro. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* json: support standard-style formatting.Kaz Kylheku2022-10-111-0/+1
| | | | | | | | | | | | | | | | | | | | * stream.c (standard_k, print_json_format_s): New symbol variables. (stream_init): New variables initialized. * stream.h (enum json_fmt): New enum. (standard_k, print_json_format_s): Declared. * lib.c (out_json_rec): Take enum json_fmt param, and pass it recursively. Printing for vector and dictionaries reacts to argument value. (out_json, put_json): Examine value of special var *print-json-format* and calculate enum json_fmt value from this. Pass to out_json_rec. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* streams: new function inc-indent-abs.Kaz Kylheku2022-10-111-3/+4
| | | | | | | | | | | * stream.c (inc_indent_abs): New function. (stream_init): inc-init-abs intrinsic registered. * stream.h (inc_indent_abs): Declared. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New: %fun% mechanism for current function name.Kaz Kylheku2022-10-031-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (pct_fun_s): New symbol variable, holding the usr:%fun% symbol. (fun_macro_env): New static function. (do_expand): For defun and defmacro, use fun_macro_env to establish an environment binding the %fun% symbol macro, and expand everything in that environment. (eval_init): Intern the %fun% symbol, initializing pct_fun_s, and also register a global symbol macro in that name so that we can freely use %fun% everywhere without worrying that the code will blow up. E.g. a logging macro can use it to get the function name, but still be useful in a top-level form outside of a named function. * stdlib/struct.tl (sys:meth-lambda): New macro. (defstruct, defmeth): Use sys:meth-lambda as a replacement for lambda to set up the %fun% symbol macro. In the :init case which doesn't use a lambda, an open-coded symacrolet does the job. * tests/019/pct-fun.tl: New file. * tests/019/pct-fun.expected: Likewise. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New method: str-addr.Kaz Kylheku2022-10-031-0/+1
| | | | | | | | | | | | | | | | | | | | | * socket.c (sock_set_entries): Intern str-addr symbol. There is no autoload on this because the struct types of which this is a method don't exist if the socket module has not been loaded. * stdlib/socket.tl ((sockaddr-in str-addr), (sockaddr-in6 str-addr), (sockaddr-un str-addr)): New methods. * tests/014/str-addr.tl: New file. This provides coverage not just for the str-addr method, but the hitherto untested address to text functions. This is why the bug was found, that was addressed in the previous commit. The test case which produces "8000::1" was actually producing "800:1". * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New sockaddr-str function.Kaz Kylheku2022-10-021-0/+1
| | | | | | | | | | | | | | | | This function "intelligently" constructs an address object of the right type from a string. * socket.c (sock_set_entries): Autoload socket.tl on sockaddr-str function being accessed. * stdlib/socket.tl (sockaddr-str): New function. * tests/014/sockaddr-str.tl: New file. * txr.1: Documented. * stdlib.doc-syms.tl: Updated.
* New macro: close-lazy-streams.Kaz Kylheku2022-08-281-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | * lib.c (lazy_stream_s): New symbol variable. (lazy_streams_binding): New static variable. (lazy_stream_register): New static function (lazy_stream_cons): If the stream is associated with a lazy cons, register it with lazy_stream_register. (obj_init): gc-protect lazy_streams_binding variable. Intern the sys:*lazy-streams* symbol. * lib.h (lazy_streams_s): Declared. * eval.c (eval_init): Register sys:*lazy-streams* special variable. * stdlib/getput.tl (close-lazy-streams): New macro. * autoload.c (getput_set_entries): Trigger autload on close-lazy-streams symbol. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: search-allKaz Kylheku2022-08-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): search-all intrinsic registered. * lib.c (search_common): New Boolean argument all, indicating whether all positions are to be returned. We must handle this in the two places where empty key and sequence are handled, and also in the main loop. A trick is used: the found variable is now bound by list_collect_decl, but not used for collecting unless all is true. (search, rsearch, contains): Pass 0 for all argument of search_common. (search_all): New function. * lib.h (search_all): Declared. * tests/012/seq.tl: New tests. * txr.1: Documented. * stdlib/doc-syms.tl: Regenerated.
* New function: path-components-safe.Kaz Kylheku2022-07-251-0/+1
| | | | | | | | | | | | | | | | * autoload.c (path_test_set_entries): Autoload on path-components-safe symbol. * stdlib/path-test.tl (if-windows, if-native-windows): New system macros. (path-safe-sticky-dir): New system function. (path-components-safe): New function. * tests/018/path-safe.tl: New file.' * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New function: count.Kaz Kylheku2022-07-181-1/+2
| | | | | | | | | | | | | | | | The general count function, with keyfun and testfun, is noticeably absent. Let's implement it. * lib.[ch] (count): New function. * eval.c (eval_init): Register count intrinsic. * tests/012/seq.tl: Some tests for count. * txr.1: Add count to count-if section. Revise documentation based on pos/pos-if. * stdlib/doc-syms.tl: Updated.
* for/for*: stricter syntax check.Kaz Kylheku2022-06-131-2/+2
| | | | | | | | | | | | | | | | | * eval.c (me_for): Require at least one argument. However, we let the init-forms continue to be optional and document it. * txr.1: Refer to for and for* as macros, since they have been since 2016. The omission of the inc-form list is shown as a second variant of the syntax. This is to avoid misleading the reader into thinking that the the inc-form list can be omitted while body forms are present. A spurious paragraph reiterating that the macros establish an anonymous block is removed. That extra text was present in the first draft written in 2011, and maintained since. * stdlib/doc-syms.tl: Updated.
* New function: strKaz Kylheku2022-06-121-38/+38
| | | | | | | | | | | | | | | The str function is like mkstring but allows a fill pattern to be specified. * eval.c (eval_init): str intrinsic registered. * lib.[ch[ (str): New function. * tests/015/str.tl: New file. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* New: spln and tokn functions.Kaz Kylheku2022-05-301-1/+2
| | | | | | | | | | | | | | | Instead of trying to work the new count parameter into the spl and tok functions, it's better to make new ones. * eval.c (eval_init): spln and tokn intrinsics registered. * lib.[ch] (spln, tokn): New functions. * tests/015/split.tl: New test cases. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.
* buf: compression and decompression functions.Kaz Kylheku2022-05-281-0/+2
| | | | | | | | | * buf.c (buf_compress, buf_decompress): New static functions. (buf_init): buf-compress and buf-decompress intrinsics registered. * txr.1: Documented. * stdlib/doc-syms.tl: Updated.