summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* doc: fix bad deindent under copy-path-rec.Kaz Kylheku2021-05-281-0/+1
| | | | * txr.1: Add missing .IP after .RE to return the indentation.
* json: tojson function.Kaz Kylheku2021-05-281-0/+66
| | | | | | | | | | | | * eval.c (eval_init): tojson intrinsic registered. * lib.c (tojson): New function. * lib.h (tojson): Declared. * txr.1: Documented. * share/txr/stdlib/doc-syms.tl: Updated.
* json: printing support.Kaz Kylheku2021-05-281-0/+12
| | | | | | | | | | First cut, without line breaks or indentation. * lib.c (out_json_str, out_json_rec, out_json): New static functions. (obj_print_impl): Hook in json printing via out_json. * txr.1: Add notes about output to JSON extensions.
* json: support forgotten null object.Kaz Kylheku2021-05-281-2/+12
| | | | | | | | | | | | | The JSON null will map to the Lisp null symbol. I thought about using : but that could cause surprises; like when it's passed to functions as an optional argument, it will trigger the default value. * parser.l (JSON): Add rules for producing null keyword. * txr.1: Documented. * lex.yy.c.shipped: Updated.
* json: handling for bad UTF-8 bytes, NUL and \u0000.Kaz Kylheku2021-05-281-1/+15
| | | | | | | | | | | * parser.l <JLIT>: Convert \u+0000 sequence to U+DC00 code point, the pseudo-null. Also include JLIT in in the rule for catching bad bytes that are not matched by {UANYN}. * txr.1: Document this treatment as extensions to JSON. * lex.yy.c.shipped: Updated.
* json: hash issues with quasiquoting.Kaz Kylheku2021-05-281-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two problems. One is that in #J{~foo:"bar"} the foo expression is parsed while the scanner is in Lisp mode and the : token is grabbed by the parser as a lookahead token in the same mode. Thus it comes back as a SYMTOK (the colon symbol). We fix this by recognizing the colon symbol as synonym of the colon character. But only if it is spelled ":" in the syntax: we look at the lexeme. The second problem is that even if we fix the above, ~foo produces a sys:unquote form which is rejected because it is not a string. We fix this in the most straightforward way: by deleting the code which restricts keys to strings, an extension I already thought about making anyway. * parser.y (json_col): New non-terminal. This recognizes either a SYMTOK or a ':' token, with the semantic restriction that the SYMTOK's lexeme must be ":". (json_vals): Use yybadtok instead of generic error. (json_pairs): Do not require keys to be strings. Use json_col instead of ':', and also yybadtok instead of generic error. * y.tab.c.shipped: Updated.
* doc: document json syntax support.Kaz Kylheku2021-05-271-0/+155
| | | | | | * txr.1: Documented #J, #J^ and json macro. * share/txr/stdlib/doc-syms.tl: Updated.
* Version 260txr-260Kaz Kylheku2021-05-261-2/+2
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Bumped. * txr.vim, tl.vim: Regenerated.
* tests: fix vtest being hindrance to error finding.Kaz Kylheku2021-05-251-2/+2
| | | | | | | | | | | | | * tests/common.tl (vtest): Only if the expected expression is :error or (quote :error) do we wrap the expansion and evaluation of the test expression with exception handling, because only then do we expect an error. When the test expression is anything else, we don't intercept any errors, and so problems in test cases are easier to debug now. * tests/012/struct.tl: In one case we must initialize the *gensym-counter* to 4 to compensate for the change in vtest to get the same gensym numbers in the output.
* window-map: add tests, improve doc, add examples.Kaz Kylheku2021-05-251-23/+64
| | | | | | | * tests/012/seq.tl: New tests. * txr.1: Improve documentation of window-map's :wrap and :reflect. Add examples.