summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
...
* Version 263txr-263Kaz Kylheku2021-06-171-3/+3
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* doc: bad grammar under FFI ptr typeKaz Kylheku2021-06-171-1/+1
| | | | * txr.1: "update *the* datum".
* doc: formatting of meta-symbols under op.Kaz Kylheku2021-06-171-16/+26
| | | | | | * txr.1: Fix the typesetting of @rest, @rec, @num, @n and @n-1 in the op macro section. Missing word inserted: "recursive call *to* the function".
* New macro: flow.Kaz Kylheku2021-06-161-0/+40
| | | | | | | | | | | | | | | There has been interest in the community in a threading macro; a triviality which which applies the opip syntax to a value. Eschewing unusual glyph combinations like ->> and whatnot, I've chosen the English word flow for this. * share/txr/stdlib/op.tl (flow): New macro. * lisplib.c (op_set_entries): Set up autoload for flow. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* listener: new --noprofile option.Kaz Kylheku2021-06-161-1/+9
| | | | | | | | | | | | | * parser.c (repl): Set the rcfile variable to nil if opt_noprofile is true, to suppress reading it. * txr.c (op_noprofile): New global variable. (help): Add help text. (txr_main): Recognize noprofile option and set variable. * txr.h (opt_noprofile): Declared. * txr.1: Documented.
* txr-case: upkeep.Kaz Kylheku2021-06-161-5/+33
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/txr-case.tl (txr-case-impl): If the input is a stream, then convert it to a lazy list of lines, so that running multiple functions against it produces sane, backtracking behavior, like a @(cases) construct. * tests/011/txr-case.expected: Updated. * tests/011/txr-case.txr: Now actually contains a test case for txr-case. * txr.1: Address an issue reported by Paul A. Patience: the input to match-fun, txr-if and txr-when may be a stream. That has always been the case in the implementation. Also document that when the input is a single string, it is treated as a list. Document the new requirement in txr-case that a stream is converted into lazy list of lines.
* math: forbid dubious inequality comparisons.Kaz Kylheku2021-06-151-1/+1
| | | | | | | | | | | | | | | | | | | The issue, reported by Paul A. Patience, is that code like (< 1 "abc") is successfully producing a result. The root cause is that 1 is an iterable object, and so is treated as a sequence opposite to the "abc" operand. We should allow only true sequences in this situation. * arith.c (seq_lt_compat_check): New static function. Checks that neither of two sequences is SEQ_NOTSEQ or SEQ_HASHLIKE. (seq_lt, seq_le): Use seq_lt_compat_check to reject dubious inputs. * txr.1: Minor wording change in the related documentation, removing a gratuitous adjective. * tests/016/arith.tl: Inequality tests.
* defsymacro: regression: don't expand replacement.Kaz Kylheku2021-06-151-14/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | This is a regression that was introduced in 191. The change in 191 was trying to prevent defsymacro from being expanded immediately by the expander except in 190 compatibility. Unfortunately, this caused the whole defsymacro block not to be entered unless in 190 compatibility, otherwise taking the common exit which returns form_ex, containing the expanded replacement form. * eval.c (do_expand): Split up implementation of defvarl and defsymacro. In the defsymacro block, do not do any expanding on entry. Absent of compatibility mode, we just do some sanity checks and pass the entire form through. In 262 compatibility, we do the expansion to obtain form_ex. Then all the previous compat logic is wrapped in that block. * tests/011/macros-3.tl: Add a test case which confirms that symbol macros are lazily expanded. Weakness in the test suite is how these regressions creep in. * txr.1: Improve defsymacro documentation, spelling out clearly that the unexpanded replacement form is associated with the symbol. Eliminate obsolescent text suggesting that defsymacro is evaluated at macro time.
* txr.1: Correction to compat note for 190.Kaz Kylheku2021-06-151-1/+14
| | | | | | | | * txr.1: When writing up the compatibility notes for version 190, I missed the change that defmacro and defsymacro were switched away from instant evaluation by the macroexpander. That change introduced a regression which I just noticed, and this is noted also.
* doc: problems in mkstempKaz Kylheku2021-06-151-3/+3
| | | | | * txr.1: mkstemp: fix formatting problem in heading, and incorrect reference to mkdtemp with bad grammar.
* streams: *stdnull* lazily opens /dev/nullKaz Kylheku2021-06-141-3/+30
| | | | | | | | | | | | | | | | | | | | | The *stdnull* stream has been purely a stream-level abstraction. To make it useful for redirecting real file descriptors around the execution of external programs, we endow it with the ability to open /dev/null when it is asked to provide its file descriptor. * stream.c (struct dev_null): New structure. (dev_null_close, dev_null_get_fd, dev_null_get_prop): New static functions. (null_ops): Wire in the above functions instead of null_close, null_get_fd and null_get_prop. We need new functions because null_close and others do not belong to just the null stream; they are base operations used by other streams as default implementations for some kinds of unimplemented functions. (make_null_stream): Alocate a struct dev_null instead of a struct strm_base. Set the fd to -1. * txr.1: Documented.
* format: revise numeric handling.Kaz Kylheku2021-06-141-72/+112
| | | | | | | | | | | | | | | | | | | | | | | There are a number of issues, such as left adjustment not working and such. This needs a better treatment from the requirements level, through to a set of test cases. * stream.c (max, min): Macros macros added, in their usual form. (vformat_num): Implement new rules which suppress the zero and space characters used in place of a sign if they overflow the field width. (formatv): Clamp integer precision field to width - 1 for integers, for consistency with floating-point handling. For floating-point values under ~a and ~s, do not force the second stage precision to width - 1; only clamp it if it is greater. * format.tl: Numerous new tests. * txr.1: Significant redocumenting of this area. The handling of numbers is described as a two stage process, clarifying the changing role of "precision" in the two stages.
* format: new precision - character for zero.Kaz Kylheku2021-06-141-0/+12
| | | | | | | | | | | * stream.c (formatv): The - precision option character produces a "sign" that is a zero. If this is used with leading zeros, it will avoid generating a space. The requirements can use improvement here, but one step at a time. * tests/018/format.tl: Some tests. * txr.1: Documented.
* doc: remove hyphenation.Kaz Kylheku2021-06-141-4/+4
| | | | * txr.1: non-negative changed to nonnegative.
* Version 262txr-262Kaz Kylheku2021-06-111-3/+3
| | | | | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise. * y.tab.c.shipped: Regenerated. Good catch! forgot to do this for most recent change to parser.y.
* doc: add pic examples.Kaz Kylheku2021-06-111-0/+37
| | | | * txr.1: Examples added.
* pic: support quasiliteral as format string.Kaz Kylheku2021-06-111-6/+45
| | | | | | | | | | | | * share/txr/stdlib/pic.tl (pic): Refactor string compilation code into local function which has access to the overall argument list. Recognize the quasiliteral case and translate by compiling all the string parts, then forming a recombined quasiliteral where the compiled parts are substituted. * tests/018/format.tl: test case for this. * txr.1: Documented.
* doc: codify optional alternatives notation.Kaz Kylheku2021-06-111-1/+7
| | | | | | | * txr.1: The notation [ a | b | c | .. ] is used throughout the document, but the Conventions paragraph describes only square brackets around a single optional element. The notation is now officially codified.
* pic: allow trailing exclamation.Kaz Kylheku2021-06-111-14/+23
| | | | | | | | | | * share/txr/stdlib/pic.tl (expand-pic-num, expand-pic, pic): Allow ### to be followed by a single !. This is not counted toward the field width. * tests/018/format.tl: Cover with some tests. * txr.1: Doc updated.
* pic: clarification and tests.Kaz Kylheku2021-06-111-3/+7
| | | | | | | | * tests/018/format.tl: Add tests which combine overflow flagging with +/-. The space generated by - contributes to overflow. * txr.1: Clarify overflow issue in documentation.
* doc: document pic macro.Kaz Kylheku2021-06-101-0/+193
| | | | | | * txr.1: pic macro documented. * share/txr/stdlib/doc-syms.tl: Updated.
* format: fix precision field leading zero problems.Kaz Kylheku2021-06-101-6/+18
| | | | | | | | | | | | | | | | | * stream.c (formatv): Do not recognize multiple leading zeros as a single one; once the zero flag is set, if another zero is seen, it must be treated as one of the digits specifying the precision value. New requirement: before processing a format specifier, check for the situation that the leading zero has been specified, but no precision. Convert this situation to that of a precision of zero being given, with no leading zero. * txr.1: Document the ambiguity around the leading zero and how it is being handled when only the leading zero flag is given, and no actual precision. Add a note about what happens when zero precision is specified in ~a in conjunction with a floating-point value. Misspelled "pas" word fixed.
* arith: switch sum and prod to seq_iter.Kaz Kylheku2021-06-091-1/+3
| | | | | | | | | | | | | | * arith.c (nary_op_keyfun): Static function removed. (nary_op_seq, nary_op_seq_keyfun): New static functions. (sumv, prodv): Static functions removed. (sum, prod): Reimplement using nary_op_seq and nary_op_seq_keyfun. Conversion of sequence to list smuggled via args is gone. * tests/016/arith.tl: new sum and prod tests. * txr.1: Note about sum and prod taking an iterable sequence added.
* reduce-left: rewrite using seq_iter.Kaz Kylheku2021-06-091-0/+12
| | | | | | | * lib.c (reduce_left): Use sequence iteration instead of list operations. * txr.1: Add a note to the documentation.
* ffi: bug: always using ffi_prep_cif_var.Kaz Kylheku2021-06-091-3/+6
| | | | | | | | | | | | | | | * share/txr/stdlib/ffi.c (deffi): Fix misnamed variable. The second value coming from sys:analyze-argtypes is the number of fixed arguments, not the number of variadic arguments. Furthermore, if this number is equal to nargs, we were supposed to have been passing nil instead to ffi-make-call-desc, which indicates the ordinary non-variadic function. We were always always passing a non-nil value, so always requesting variadic. That is fixed now thanks to the change to ffi_make_call_desc. * ffi.c (ffi_make_call_desc): Register the function as variadic if either nfixed is specified as nil, or if it is equal to ntotal. * txr.1: Document the convention change for ffi-make-call-desc.
* parser: new *read-unknown-structs* variable.Kaz Kylheku2021-06-081-0/+19
| | | | | | | | | | | | | | | | | | | | | * parser.c (read_unknown_structs_s): New symbol variable. (parser_common_init): Initialize read_unknown_structs flag member of the parser structure from the new special variable. (parse_init): Initialize read_unknown_struct_s variable. Register the *read-unknown-structs* dynamic variable. * parser.h (struct parser): New member, read_unknown_structs. (read_unknown_structs_s): Declared. * parser.y (struct): Generate the struct literal syntax not only for quasiquoted structures, but for structures with an unknown type name, if the read_unkonwn_structs flag is set. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Regenerated. * y.tab.c.shipped: Regenerated.
* lib: new function, fill-vec.Kaz Kylheku2021-06-081-0/+88
| | | | | | | | | | | | | | * eval.c (eval_init): Register fill-vec intrinsic. * lib.c (fill_vec): New function. * lib.h (fill_vec): Declared. * tests/010/vec.tl: New file. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* ffi: new macros deffi-struct and deffi-union.Kaz Kylheku2021-06-081-0/+30
| | | | | | | | | | | | * lisplib.c (ffi_set_entries): Autoload for deffi-struct and deffi-union symbols. * share/txr/stdlib/ffi.tl (deffi-struct, deffi-union): New macros. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* expander: expand must only ignores unbound warnings.Kaz Kylheku2021-06-071-1/+14
| | | | | | | | | | | | | | | | | | | The expand function must not muffle all deferred warnings. That causes the problem that a form like (inc var a.bar) fails to produce a warning due to bar not being the slot of any structure. The expand function must only muffle warnings about undefined functions and variables. * eval.c (muffle_unbound_warning): New static function. (no_warn_expand): Use muffle_unbound_warning as handler, rather than uw_muffle_warning. * tests/012/struct.tl: Fix two test cases here which test the expand function using a form that references a nonexistent slot. These now generate a warning, so we use the slot name b rather than d, which is defined. * txr.1: Documented change to expand.
* ffi: allow conversion of carray objects under cptr.Kaz Kylheku2021-06-061-2/+32
| | | | | | | | | | | | | | * ffi.c (ffi_cptr_put): If the object is not a cptr, try it as a carray. This requires the tft to have an eltype, requiring a change in ffi_type_compile. (ffi_type_compile): When compiling a parametrized cptr object, we now look up the type symbol as a FFI type, and store the result as the tft->eltype. If the symbol is not an FFI type, then this lookup returns nil. If the eltype is non-nil, then there is the possibility it can match the element type of a carray. * txr.1: Documented.
* ffi: allow nil object to convert under closure type.Kaz Kylheku2021-06-061-3/+30
| | | | | | | | * ffi.c (ffi_closure_put): Only diagnose a bad object if it's not nil, otherwise let the null value of p through. This is useful because there are sometimes C interfaces which take an optional function pointer, whereby a null value indicates that the pointer is not specified.
* matcher: doc fix, quasiquote examples, new test.Kaz Kylheku2021-06-041-1/+41
| | | | | | | * tests/011/patmatch.tl: New test case. * txr.1: Heading fix: Quasiquote matching notation, not quasiliteral. Examples of quasiquote notation added.
* FFI: big improvement in bad call diagnosis.Kaz Kylheku2021-06-041-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | FFI has the problem that when things go wrong in calls, or in specifications of functions, the diagnostics refer to an internal function like ffi-call or ffi-make-call-desc, which is not helpful in identifying the error. We want the diagnostics to refer to the foreign function, or foreignb callback wrapper, to which the problem pertains. The approach taken is to stick the name symbol into the ffi-call-desc object. Functions which work with a ffi-call-desc can pull out the name and use it for reporting. * ffi.c (struct txr_ffi_call_desc): Add name member. (ffi_call_desc_print_op): Include name in printed representation. (ffi_desc_mark_op): Mark the name. (ffi_make_call_desc): Take new argument to specify the name, storing it into the structure. If it is specified,then use that name for reporting errors, otherwise stick with ffi-make-call-desc. (ffi_call_wrap, ffi_closure_dispatch, ffi_closure_dispatch_safe, ffi_make_closure): Use the name from the call descriptor, or else the function's own name if that is nil. (ffi_init): Update registration of ffi-make-call-desc intrinsic to five arguments with four required. * ffi.h (ffi_make_call_desc): Declaration updated. * share/txr/stdlib/ffi.tl (deffi, deffi-cb-expander): Pass the name symbol down to ffi-make-call-desc. * txr.1: Documented.
* json: improve escaping for script tags.Kaz Kylheku2021-06-031-11/+34
| | | | | | | | | | | * lib.c (out_json_str): Strengthen the test for escaping the forward slash. It has to occur in the sequence </script rather than just </. Recognize <!-- and --> in the string, and encode them. * tests/010/json.tl: Cover this area with some tests. * txr.1: Documented.
* matcher: better error handling for backquotes.Kaz Kylheku2021-06-021-1/+8
| | | | | | | * share/txr/stdlib/match.tl (transform-qquote): Handle hash error case with separate pattern. Use compile-error and *match form instead of error. Diagnose splicing unquote and nested quasiquote.
* matcher: quasiquote matching.Kaz Kylheku2021-06-021-10/+125
| | | | | | | | | | | | | | | | | | | | | | | This allows (when-match ^(,a ,b) '(1 2) (list a b)) -> (1 2) which is a nice alternative that is supported by some Lisp pattern matchers. We don't need it since we have (@a @b). The motivation is JSON matching. (when-match ^#J{"foo" : {"x" : ~val}} #J{"foo" : {"x" : "y"}} val) -> "y" * share/txr/stdlib/match.tl (compile-match): Recognize qquote case and handle via transform-qquote function. (non-triv-pat-p): Let's declare quasiquotes to be nontrivial. (transform-qquote): New function: transform quasi-quoted syntax into regular pattern matching syntax. * txr.1: Documented.
* Version 261txr-261Kaz Kylheku2021-06-011-5/+14
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* doc: rearrangement in Data Interchange SupportKaz Kylheku2021-06-011-34/+34
| | | | | * txr.1: Move the json macro description to the beginning of the section.
* doc: put-json: numbering, include U+007F.Kaz Kylheku2021-06-011-4/+4
| | | | | * txr.1: Fix duplicate 4. bullet; mention the that control character U+007F is rendered as an escape also.
* chr-iscntrl: recognize Unicode C0 and C1.Kaz Kylheku2021-06-011-3/+6
| | | | | | | | * lib.c (chr_iscntrl): Don't use iswcntrl; it fails to report 0x80-0x9F as control characters. A bit of hand-crafted logic does the job. * txr.1: Redocumented.
* json: wrap up: test cases, fixes, tweaks.Kaz Kylheku2021-05-311-7/+15
| | | | | | | | | | | | | | | | | | | | | * /share/txr/stdlib/getput.tl (get-jsons): If the s parameter is a string, convert it to a byte input stream so that. (put-jsons): Add missing t return value. (file-put-json, file-append-json, file-put-jsons, file-append-jsons, command-put-jsons, command-put-jsons): Add missing object argument to all these functions, and a missing "w" open-file mode to several of them. * stream.c (mkstemp_wrap): Calculate length of suff the defaulted argument, not the raw suffix argument. * test/010/json.tl: New file, providing tests that touch every area of the new JSON functionality. * tests/common.tl (mstest, with-temp-file): New macros. * txr.1: Document that get-jsons takes a source which could be a string.
* New: mkdtemp and mkstemp functions.Kaz Kylheku2021-05-311-0/+85
| | | | | | | | | | | | | | | | * configure: check for mkstemp and mkdtemp. * stream.c (stdio_set_prop): Implement setting the :name property. We need this in mkstemp_wrap in order to punch in the temporary name, so that the application can retrieve it. (mkdtemp_wrap, mkstemp_wrap): New functions. (stream_init): Register mkdtemp and mkstemp intrinsics. * stream.h (mkdtemp_wrap, mkstemp_wrap): Declared. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* New function: tmpfile.Kaz Kylheku2021-05-311-0/+26
| | | | | | | | | | | * stream.c (tmpfile_wrap): New static function. (stream_init): Register tmpfile intrinsic. * stream.h (tmpfile_wrap): Declared. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* doc: document all json I/O convenience routines.Kaz Kylheku2021-05-301-0/+243
| | | | | | | | | * txr.1: Documented file-get-json, file-put-json, file-append-json, file-get-jsons, file-put-jsons, file-append-jsons, command-get-json, command-put-json, command-get-jsons, command-put-jsons. * share/txr/stdlib/doc-syms.tl: Updated.
* doc: put-json and put-jsonl return the object.Kaz Kylheku2021-05-301-0/+7
| | | | * txr.1: Document return value of put-json and put-jsonl.
* json: functions put-json and put-jsonl.Kaz Kylheku2021-05-291-24/+90
| | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Register put-json and put-jsonl intrinsics. * lib.c (out_json_str): Do not output the U+DC01 to U+DCFF code points by masking them and using put_byte. This is unnecessary; if we just send them as-is to the text stream, the UTF-8 encoder does that for us. (put_json, put_jsonl): New functions. * lib.h (put_json, put_jsonl): Declared. * txr.1: Documented. The bulk of tojson is moved under the descriptions of these new functions, and elsewhere where the document pointed to tojson for more information, it now points to put-json. More detailed description of character treatment is given. * share/txr/stdlib/doc-syms.tl: Updated.
* json: tojson must not add #J prefix.Kaz Kylheku2021-05-291-18/+6
| | | | | | | | | | | * lib.c (out_json_rec): In the CONS case, if ctx is null bail and report and invalid object. This lets us call the function with a null context. (tojson): Do not support (json ...) syntax. Instead of obj_print, pass the object directly to out_json_rec. * txr.1: Do not mention handling json macro syntax. Common leading text factored out of bulleted paragraphs section.
* json: escape slash in </ sequenceKaz Kylheku2021-05-291-13/+31
| | | | | | | | | * lib.c (out_json_str): When the < character is seen, if the lookahead character is /, output the < and a backslash to escape the /. * txr.1: Moved description of special JSON output handling under tojson, and described the above escaping there also.
* parser: provide parse-errors function.Kaz Kylheku2021-05-281-0/+42
| | | | | | | | | | * parser.c (parse_errors): New function. * parser.h (parse_errors): Declared. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* json: get-json function.Kaz Kylheku2021-05-281-0/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): get-json intrinsic registered. * parser.c (prime_parser): Handle prime_json. (lisp_parse_impl): Take enum prime_parser argument directly instead of the interactive flag. (lisp_parse, nread, iread): Pass appropriate prime_parser value instead of the original flag. (get_json): New function. Like nread, but passes prime_json. * parser.h (enum prime_parser): New constant, prime_json. (get_json): Declared. * parser.l (prime_scanner): Handle prime_json. * parser.y (SECRET_ESCAPE_J): New terminal symbol. (spec): New productions around SECRET_ESCAPE_J for parsing JSON. * lex.yy.c.shipped, y.tab.c.shipped, y.tab.h.shipped: Updated. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.