summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
* New style iteration functions.Kaz Kylheku2020-06-021-5/+157
| | | | | | | | | | | | | | | | | | | | | | | | iter-begin provides a paradigm for iteration that is more compatible with lists. If the sequence is a list, then the list itself is returned as the iterator, and the other functions are basicaly wrappers for car/cdr and null testing. Yet the API is defined in such a way that other objects can be iterated with good efficiency, at the cost of allocating a new iterator object (which can be re-used). * eval.c (eval_init): Register iter-begin, iter-more, iter-item, iter-step and iter-reset. * lib.c (seq_iter_init_with_info): New static function. (seq_iter_init): Now a thin wrapper for seq_iter_init_with_info. (iter_begin, iter_more, iter_item, iter_step, iter_reset): New functions. * lib.h (iter_begin, iter_more, iter_item, iter_step, iter_reset): New functions. * txr.1: Documented.
* Version 239.txr-239Kaz Kylheku2020-06-021-2/+2
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* doc: constantp syntax formatting.Kaz Kylheku2020-05-311-1/+1
| | | | * txr.1: Fix extra whitespace around env parameter.
* search, rsearch: rewrite using seq_info and bugfix.Kaz Kylheku2020-05-251-4/+16
| | | | | | | | | | | | | | | * lib.c (seq_getpos, seq_setpos): New functions. * lib.h (seq_getpos, seq_setpos): Declared. (search_list, rsearch_list): Static functions removed. (search_common): New static function. (search, contains, rsearch): These functions are now trivial wrappers around search_common. A requirement problem is fixed in rsearch: when the key is empty, the length of sequence is returned rather than zero, because zero is obviously not the right most place where an empty key matches. * txr.1: Documentation updated.
* Fix few typos reported from Fossies.Kaz Kylheku2020-05-231-2/+2
| | | | | | | | | | | | | Fossies administrator Jens alerted me to some typos. * txr.1: Fix two instances of alphanumeric being hyphenated, and one case of invocable being rendered as invokable. * linenoise/linenoise.c (struct lino_state): Misspelled "buffer" in a comment. One other comment typos in this file is from the original code, so it stays: who needs yet another merge conflict? Not touching the original typo in example.c, either.
* Version 238.txr-238Kaz Kylheku2020-05-181-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* New assert macro.Kaz Kylheku2020-05-181-0/+35
| | | | | | | | | | | | * eval.c (rt_assert_fail, me_assert): New static functions. (eval_init): assert macro and sys:rt-assert-fail function registered. * lib.c (func_n4ov): New function. * lib.h (func_n4ov): Declared. * txr.1: Documented.
* sort: prudently make it subject to compat valueKaz Kylheku2020-05-141-0/+20
| | | | | | | | | | | | * eval.c (eval_init): If opt_compat is 237 or less, make sort and shuffle destructive. * share/txr/stdlib/getopts.tl (opthelp): Revert previous change, restoring use of copy-list and use nsort instead of sort, so the function is not affected by the 237 compatibility being turned on. * txr.1: Add compatibility notes.
* lib: sort becomes non-destructive; nsort introduced.Kaz Kylheku2020-05-131-8/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I'm fixing a historic mistake copied from ANSI Lisp, which trips up language newcomers and sometimes even experienced users. The function innocently named sort will now return newly allocated structure. The function previously called sort will be available as nsort (non-consing/allocating sort). The shuffle function also becomes pure, and is accompanied by nshuffle. * eval (me_op): Continue to use destructive sort in this legacy code that is only triggered in very old compat mode. (eval_init): Registered nsort and nshuffle. * lib.c (nsort, nshuffle): New functions introduced, closely based on sort and shuffle. (sort, shuffle): Rewritten to avoid destructive behavior: work by copying the input and calling destructive counterparts. (sort_group): Continue to use destructive sort, which is safe; the structure is locally allocated. The sort_group function has pure semantics. (grade): Likewise. * lib.h (nsort, nshuffle): Declared. * share/txr/stdlib/getopts.tl (opthelp): Replace an instance of the (sort (copy-list ...)) pattern with just (sort ...). * tags.tl (toplevel): Continue to use destructive sort to sort tags before writing the tag file; the lifetime of the tags list ends when the file is written. * tests/010/seq.txr: Switch some sort calls to nsort to keep test case working. * txr.1: Documented.
* lib: use seq-info for sort and shuffle.Kaz Kylheku2020-05-131-0/+20
| | | | | | | | * lib.c (sort, shuffle): Switch to seq_info. For consistency with sort, shuffle now handles hashes in the same peculiar way. * txr.1: Document hash behavior for sort and shuffle.
* Expose isatty function.Kaz Kylheku2020-05-111-0/+33
| | | | | | | * sysif.c (isatty_wrap): New function. (sysif_init): Register isatty intrinsic. * txr.1: Documented.
* doc: quote, umethod, hash-invert: bad syntaxKaz Kylheku2020-05-091-3/+3
| | | | | * txr.1: Remove manually added angle brackets on <form>. Fix inappropriate use of << and >>.
* symbol-function: bugfix: expand lambda expression.Kaz Kylheku2020-05-031-1/+2
| | | | | | | * eval.c (lookup_fun): A lambda expression must be expanded before being turned into a function. * txr.1: Documented.
* compiler: honor load-time in parts of loop.Kaz Kylheku2020-05-031-0/+14
| | | | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-for): If a for loop occurs in the top level, or inside a load-time, then we don't want to suppress the semantics of load-time for any parts of the loop that are repeatedly evaluated. The programmer may be doing that specifically to hoist those calculations out of the loop. We thus bind *load-time* to nil after compiling the initializing and test expressions. * txr.1: New paragraph in Notes for load-time, mentioning compiler treatment of loops and lambda. The language is deliberately general rather than being specifically about the for loop, because several loop constructs compile to the for loop, and that is also subject to future changes.
* compiler: treat nested load-time forms.Kaz Kylheku2020-05-021-0/+46
| | | | | | | | | | | | | | | | | | | | | | | load-time forms nested in load-time forms have no special semantics; it's wasteful to separately hoist them into load time and store their value in their own D register. We must be careful: this is not true if a nested form occurs in a lambda. * share/txr/stdlib/compiler.tl (*load-time*): New special variable. (compiler comp-lambda): Bind *load-time* to nil around the compilation of the lambda, so load-time forms in the lambda are hoisted to load time, even if the lambda itself is wrapped in a load-time form. (compiler comp-load-time-lit): Bind *load-time* true around the compilation of the form. If *load-time* is already true, then skip the special load-time logic and just compile the enclosed form; the surrounding load-time compilation is taking care of the load-time hoisting. * txr.1: Document that load-time forms nested in load-time forms don't do anything, except in the lambda case.
* doc: new typos under User-Defined Streams.Kaz Kylheku2020-05-021-4/+4
| | | | | * txr.1: Fix typos and incorrect symbol under put-buf and fill-buf method.
* doc: mention zero-width bit-field at end of structure.Kaz Kylheku2020-04-271-1/+2
| | | | | * txr.1: A zero-width bit-field placed as the last member can have an effect on the structure; let's mention it.
* doc: fix wrong claim in Bitfield Allocation Rules.Kaz Kylheku2020-04-271-9/+6
| | | | | | | | * txr.1: Rewriting the last two sentences to fix the wrong claim of its last two sentences, which contradicts the correct statement in the the previous paragraph. The statements are only correct about big-endian, not about both types of machine.
* Version 237.txr-237Kaz Kylheku2020-04-261-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* streams: put_buf and fill_buf become lower-level.Kaz Kylheku2020-04-221-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this commit, the put_buf and fill_buf stream virtual functions are changed to operate directly on a low-level buffer, rather than a stream. This will allow these functions to be used for improving the performance of I/O operations that are not related to buffer objects. * stream.h (struct strm_ops): Change type signature of put_buf and fill_buf members. The lengths and iszes are ucnum. The return value is ucnum. The buffer is passed as a pointer and length, rather than a buffer object. * stream.c (unimpl_put_buf, unimpl_fill_buf, generic_put_buf, generic_fill_buf, stdio_put_buf, stdio_fill_buf, delegate_put_buf, delegate_fill_buf): Adjust to new interface. (put_buf, fill_buf, fill_buf_adjust): Pull the poitner and size from the buffer and pass those down to the virtual functions rather than the buffer itself. Convert ucnum return value to val. * strudel.c (strudel_put_buf, strudel_get_buf): The struct delegate interface doesn't change. The put-buf and fill-buf methods still operate on buffer objects. To glue that with the new low-level interface, we use the init_borrowed_buf trick that is was first used in ffi.c: temporary buf objects are efficiently allocated on the stack, pointing to the same memory that is coming down from the stream operation. * txr.1: Document the new restrictions on the buf argument of the put-buf and fill-buf stream delegate methods. Since the buf not a heap object, it cannot be used after the method returns.
* Extending =, <, >, <= and >= to work on sequences.Kaz Kylheku2020-04-211-7/+112
| | | | | | | | | | | | | * arith.c (seq_nueq, seq_lt, seq_le): New static functions. (gt, lt): Handle sequences via seq_lt. (ge, le): Handle sequences via seq_le. (numeq): Handle sequences via seq_eq. * txr.1: Documented, and also added missing documentation about comparison of ranges by these functions, fixed mistake in the syntax (> listed twice) and added some notes about symmetry of > >= and < <=.
* New function: get-line-as-bufKaz Kylheku2020-04-191-0/+23
| | | | | | | | | | | | | | * buf.c (buf_put_bytes, buf_get_bytes): static functions become external. * buf.h (buf_put_bytes, buf_get_bytes): Declared. * stream.c (get_line_as_buf): New fucntnion. (stream_init): Registered get-line-as-buf intrinsic. * stream.h (get_line_as_buf): Declared. * txr.1: Documented.
* Version 236.txr-236Kaz Kylheku2020-04-181-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* path-testing functions: accept file descriptor.Kaz Kylheku2020-04-181-1/+2
| | | | | | | * share/txr/stdlib/path-test.tl (do-path-test): Pass all argument types to statfun, except if they are of type stat. * txr.1: Documented.
* New function: touch.Kaz Kylheku2020-04-151-0/+31
| | | | | | | | | * lisplib.c (copy_file_set_entries): Register autoload for touch. * share/txr/stdlib/copy-file.tl (touch): New function. * txr.1: Documented.
* New "n" open file mode option: nonblocking.Kaz Kylheku2020-04-151-1/+3
| | | | | | | | | | | | | | | | | * stream.c (w_fopen_mode): Special handling via open and fdopen is now required if either the m.notrunc or m.nonblock is present. Since m.nonblock is just an option that can be used with any open mode, we must handle the mode flags more fully, to generate more possible combinations of open flags. (do_parse_mode): Check for 'n', and set nonblock flag. * stream.h (struct stdio_mode): New member, nonblock. (stdio_moe_init_blank, stdio_mode_init_r, stdio_mode_init_rpb): Update initalizers to set nonblock to zero. * txr.1: Documented, and also added missing i option to the mode string syntax grammar summary.
* sockets: missing shut-rd, shut-wr, shut-rdwr.Kaz Kylheku2020-04-131-1/+1
| | | | | | | | | | | | * socket.c (sock_load_init): Register documented but completely missing intrinsic variables shut-rd, shut-wr, shut-rdwr. * lisplib.c (sock_set_entries): Register autoload for shut-rd, shut-wr, shut-rdwr. * txr.1: In sock-shutdown description, fix shut-rw typo that should be shut-wr.
* Version 235.txr-235Kaz Kylheku2020-04-121-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* hash: bugfix: spurious retention in weak processing.Kaz Kylheku2020-04-111-6/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The algorithm for weak processing is not correct. In hash_mark, we must must simply not mark any of the entries, keys or values, of a weak table regardless of what type of weak table it is. If we do that, we cause spurious retention in situations that the keys and values have some kind of link together other than through the table. For instance, suppose keys are weak, but values happen to have references to keys. If we mark the values, we mark the keys and nothing will expire from the table. Such a situation happens in stream_parser_hash, which associates streams with parsers, and has weak keys. Parsers have references to streams. So entries in the hash never expire. Any stream that gets a parser is retained forever. The weak hashes used for binding in eval.c (top_vb, ...) are also affected, because the key is some symbol <sym> and the value is (<sym> . <val>). The key is weak, but the value references the sym. So these hashes also will not expire the keys: unreachable variable bindings will stick around. * hash.c (hash_mark): If a hash table has weak keys, values, or both, then only mark its vector if the count is zero. If it has one or more entries, we just add it to the reachable_weak_hashes list to be processed in do_weak_tables.
* gc: add argument to sys:gc.Kaz Kylheku2020-04-101-1/+11
| | | | | | | | * gc.c (gc_wrap): Takes argument for requesting full garbage collection. (gc_late_init): Update registration of gc intrinsic. * txr.1: Documented.
* doc: stat/fstat: bad syntax formatting.Kaz Kylheku2020-04-091-2/+2
| | | | * txr.1: > should be >>.
* path testing functions: accept stream argument.Kaz Kylheku2020-04-091-17/+28
| | | | | | | * share/txr/stdlib/path-test.tl (do-path-test): Check also for the argument being a stream, and pass to statfun. * txr.1: Documentation updated and improved.
* doc: read, iread: document lineno parameter.Kaz Kylheku2020-04-071-5/+14
| | | | | | | | * txr.1: The read and iread functions have an optional parameter for overriding the starting line number. It is now documented. read and lisp-parse got this parameter in 2015, in TXR 123. iread was introduced with this parameter in TXR 124.
* doc: bad grammer compilation section.Kaz Kylheku2020-04-071-1/+1
| | | | | * txr.1: Replace "apperas to compiles" typo with better wording.
* exceptions: improve non-error @(throw) and @(assert).Kaz Kylheku2020-04-071-0/+38
| | | | | | | | | | | | | | | When @(throw) generates a non-error exception that is unhandled, we just want it to continue. In the same situation, an @(assert) should behave as a failed match; that is, the failure of the query material that follows the assert, which activated it, should propagate through the assert. * match.c (v_throw): Return next_spec_k if uw_rthrow returns. (v_assert, h_assert): Return nil if uw_rthrow returns. * txr.1: Expanded @(throw) and @(assert) documentation with discussion of unhandled exceptions.
* exceptions: unhandled non-error exceptions now return.Kaz Kylheku2020-04-061-22/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch makes a fundamental change in exception behavior. Going forward, if an exception that is not derived from error is not handled (no catch intercepts it, and no handler accepts it) then the throw call simply returns nil to the caller instead of unwinding and terminating the process. For error exceptions, the behavior is the same: the *uhandled-hook* is called, if it exists, and if it doesn't exist or returns, unwinding and termination with diagnostics ensues. The rationale for not treating non-error exceptions fatally is that this simplifies the use of code that throws exceptions for non-error situations like progress updates. The code can be used without the caller having to establish a handler. * txr.1: Documentation updates and comaptibility notes. * unwind.c (uw_rthrow): New returning throw function based on the implementation of uw_throw. (uw_rthrowv, uw_rthrowvf): New functions. (uw_throw): Now a wrapper for uw_rthrow. Because uw_throw still does not return, it calls abort if uw_rthrow returns. uw_throw is used internally only for error exceptions. (uw_throwv, uw_throwfv): Functions removed. (uw_late_init): Register throw and throwf to the new functions uw_rthrowv an uw_rthrowfv. * unwind.h (uw_rthrow, uw_rthrowv, uw_rthrowfv): Declared. (uw_throwv, uw_throwfv): Declarations removed.
* New function: txr-parse.Kaz Kylheku2020-04-021-0/+50
| | | | | | | | | | | | txr-parse provides a way for Lisp code to programmatically parse the TXR language and obtain the Lisp represenation. This has hitherto not been available. * eval.c (eval_init): Register txr-parse intrinsic. * parser.c (txr_parse): New function. * parser.h (txr_parse): Declared.
* linenoise: command to force submission of unbalanced line.Kaz Kylheku2020-03-281-0/+10
| | | | | | | | | | * linenoise.c (edit): Handle Ctrl-F in extended mode so that Ctrl-X Ctrl-F forces the line to be submitted without a balance check. * txr.1: Document previously undocumented balance check, including the flashing exclamation mark. Document Ctrl-X Ctrl-F.
* doc: revise descriptions under Listener.Kaz Kylheku2020-03-251-27/+34
| | | | | | | | | | | | | | The recent commit 7c40d5d6ef6832baed4a5ccd0a5d4235ed4f5ee3 states that the documentation has been updated. However, it contains no changes to txr.1 at all. I swear I made the changes, but they somehow disappeared. They are not in my reflog or stash or any file in the filesystem. Gone! Here, I reproduce those changes, with some additional improvements and fixes. * txr.1: Rewrite the description of Ctrl-D. Document the new effect that major deletion operations all copy into the clipboard. Fix "It's" typo that should be "Its".
* Version 234.txr-234Kaz Kylheku2020-03-251-3/+3
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Regenerated.
* doc: typeof: missing BST types.Kaz Kylheku2020-03-241-0/+6
| | | | * txr.1: List tnode and tree types in typeof description.
* New contains function: near alias of search.Kaz Kylheku2020-03-231-1/+16
| | | | | | | | | | | | Harmonizes with starts-with and ends-with. * eval.c (eval_init): Register contains intrinsic. * lib.c (contains): New function. * lib.h (contains): Delared. * txr.1: Documented.
* apf and ipf: take arguments that are inserted.Kaz Kylheku2020-03-221-2/+14
| | | | | | | | | | | | | | The apf and ipf functions now take arguments in addition to the function that is being wrapped. If specified, these arguments are inserted to the left the applied arguments. * eval.c (do_args_apf, do_args_ipf): New static functions. (apf, ipf): Use do_args_apf and do_args_ipf, respectively, for handling the case when arguments are present. Passing the stored arguments is done with the help of the new DARG type, instead of consing up a list. * txr.1: Documented new arguments of apf and ipf.
* New type args with DARG type code.Kaz Kylheku2020-03-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | An object of args type captures into the heap the "struct args" argument list that normally appears only on the stack. Such an object also has space for a car and cdr field, which can come in handy. * args.c (dyn_args): New function: hoist a struct args * into an args heap object. * args.h (dyn_args): Declared. * gc.c (finalize, mark_obj): Handle DARGS type code. * hash.c (equal_hash): Handle DARG via eq equivalence. * lib.c (args_s): New symbol variable. (code2type): Map DARG to args symbol. (equal): Handle DARG type, using eq equivalence for now. (obj_init): Initialize args_s with interned symbol. * lib.h (enum type, type_t): New type code, DARG. (struct dyn_args): New struct. (union obj): New member, a of type struct dyn_args. * txr.1: Documented args type under typeof.
* hash-uni: two new arguments for projecting values.Kaz Kylheku2020-03-191-1/+14
| | | | | | | | | | | * hash.c (hash_uni): New functional argument map1fun and map2fun. If present, values from hash1 and hash2, respectively, are projected through these functions. (hash_init): hash-uni registration updated. * hash.h (hash_uni): Declaration updated. * txr.1: Documented new arguments.
* Support base64url encoding.Kaz Kyheku2020-03-171-2/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | * filter.c (tobase64url_k, frombase64url_k): New keyword symbols variables. (base64_stream_enc_impl): New static function, derived from base64_stream_enc. (base64_stream_enc): Now a wrapper for base64_stream_enc_impl. (base64url_stream_enc, base64url_encode): New functions. (base64_stream_dec_impl): New static function, derived from base64_stream_dec. (base64-stream_dec): Now a wrapper for base64_stream_dec_impl. (get_base64_url_char, b64url_code): New static functions. (base64url_stream_dec, base64_url_decode, base64url_decode_buf): New functions. (filter_init): Intern new keyword symbols, initializing the corresponding variables, register new :frombase64url and :tobase64url filters and intrinsic functions base64url-stream-enc, base64url-stream-dec, base64url-encode, base64url-decode and base64url-decode-buf. * filter.h (base64url_stream_enc, base64url_stream_dec, base64url_encode, base64url_decode, base64url_decode_buf): Declared. * txr.1: Documented.
* compile-file: propagate permissions for hash bang programs.Kaz Kyheku2020-03-101-3/+19
| | | | | | | | | | * share/txr/stdlib/compiler.tl (propagate-perms): New function. (compile-file-conditionally): If the source file is a hash bang script, then call propagate-perms just before closing the streams. * txr.1: Documented the permission propagation.
* Version 233.txr-233Kaz Kylheku2020-03-081-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* strings: bugfix: broken inequality comparisons.Kaz Kylheku2020-03-071-4/+10
| | | | | | | | | | | | | | | | | | | | | Inequality comparisons of strings and symbols are broken due to assuming that cmp_str returns -1 or 1. cmp_str uses the C library function wscsmp, and is exposed as the Lisp function cmp-str. That is correctly documented as returning a negative or positive value. But a few function in lib.c assume otherwise. On newer glibc's, at least on x86, it seems that wcscmp does return 1, 0 or -1 consistently; perhaps the newer optimized assembly routines are ensuring this. It shows up on older glibc installations where the C version just returns the difference between the mismatching characters. * lib.c (cmp_str): Now returns -1, 0 or 1. * txr.1: Specify the stronger requirements on the cmp-str return value, adding a note that older versions conform to a weaker requirement.
* getopts: new feature: cumulative options.Kaz Kyheku2020-03-061-1/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | An option declared as (cumul <type>) indicates that it is of type <type>, and that multiple occurrences of the option produce values that are accumulated into a list. The accumulation is in reverse order: the rightmost occurrence ends up the first in the list. * lisplib.c (getopts_set_entries): Add cumul to list of interned symbols, so that the getopts.tl code isn't mistakenly working with sys:cumul. * share/txr/stdlib/getopts.tl (opt-parsed): New slot, cumul. (opt-desc basic-type p, opt-desc list-type-p, opt-desc cumul-type-p): New methods. (opt-desc check): Rework type validity check using the new methods. (opt-parsed convert-type): Support 'cumul type by instantiating an opt-parsed object for the wrapped type, and stealing its converted argument into the current object, and setting the cumul flag. (opts add-opt, option-base add-opt): Support options that have the cumul flag set by accumulating list values. The code is different due to different amounts of encapsulation. The opts structure stores the raw opt-parsed objects, whereas option-base just takes the decoded values. (opthelp): Parse through the (cumul ...) type syntax, so cumulative options are printed in the help text the same way as if they were non-cumulative. * txr.1: Documented.