summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* awk: add CSV support.Kaz Kylheku2025-01-301-0/+18
| | | | | | | | | | | * stdlib/awk (awk-state upd-rec-to-f): Handle a new case of fs being the keyword symbol :csv, producing a field-splitting lambda that calls get-csv. * tests/015/awk-basic.tl: Several new test cases for this CSV feature. * txr.1: Documented.
* awk: use prepared lambdas for field separation.Kaz Kylheku2025-01-282-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle field separations with lambdas, similarly to record separation. The idea is that we replace the rec-to-f method, which contains a cond statement checking the variables for which field separation discipline applies, with a lambda which is updated whenever any of those ariables change. * awk.tl (awk-state): New instance slot, rec-to-f. (awk-state :postinit): Call new upd-rec-to-f method so that rec-to-f is populated with the default field separating lambda. (awk-state rec-to-f): Method removed. (awk-state upd-rec-to-f): New method, based on rec-to-f. This doesn't perform the field separation, but returns a lambda which will perform it. (awk-state loop): We must call upd-rec-to-f whenever we change par-mode, because it influences field separation. (awk-mac-let): Replace the symbol macros fs, ft, fw and kfs with new implementations that use the reactive slot mechanism provided by rslot. Whenever the awk macro assigns any of these, the upd-rec-to-f method will be called. * tests/015/awk-basic.tl: New file. These basic tests of field separation pass before and after this change. * tests/common.tl (otest, motest): New macros.
* get-csv: bugfix: return nil on EOF.Kaz Kylheku2025-01-241-1/+23
| | | | | | | | | | | | | | | | | * stream.c (get_csv): Let's add a new state init. If get_char returns nil and we are in the init state, let's bail to a nil return. While we are at it, let's not allocate the record or string until we read at least one character. If we read a character in the init state, let's allocate those two objects, and then change to the rfield state and fall through to it to handle the character. * tests/010/csv.tl: Fix one incorrect test: (tocsv "") now returns nil, as it should. Add tests for multiple record extraction, also covering missing line termination on the last record as well as CR-LF termination. * txr.1: Documented nil return conditions.
* New functions for producing CSV.Kaz Kylheku2025-01-241-0/+19
| | | | | | | | | | | | * stream.c (put_csv, tocsv): New functions. (stream_init): put-csv and tocsv intrinsics registered. * stream.h (put_csv, tocsv): Declared. * tests/010/csv.tl (mtest-pcsv): New macro. New test cases. * txr.1: Documented.
* New function: get-csv.Kaz Kylheku2025-01-211-0/+166
| | | | | | | | | | | | | * autloload.c (csv_set_entries, csv_instantiate): New static funtions. (autoload_init): Register autoload of stdlib/csv module via new functions. * stdlib/csv.tl: New file. * tests/010/csv.tl: Likewise. * txr.1: Documented.
* New macros for enumerated constants.Kaz Kylheku2025-01-201-0/+23
| | | | | | | | | | | | | * autoload.c (enum_set_entries, enum_instantiate): New static functions. (autoload_init): Register autoload of stdlib/enum module via new functions. * stdlib/enum.tl: New file. * tests/016/enum.tl: Likewise. * txr.1: Documented.
* New macro: lop1.Kaz Kylheku2025-01-171-0/+13
| | | | | | | | | | | | | * autoload.c (op_set_entries): Autoload on lop1 symbol. * stldlib/op.tl (sys:op-expand): Add lop1 case. (sys:opip-expand): Add lop1 to the list of operators that are recgonized and specially treated. (lop1): New macro. * tests/012/op.tl: New tests. * txr.1: Documented.
* json: flat must override all effects of :standardKaz Kylheku2025-01-161-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | * stream.h (struct json_opts): Member flat removed. I noticed that !jo.flat was always being tested together with jo.fmt == json_fmt_standard. Except for a few places where the code only tested for json_fmt_standard, resulting in flat output, but some extra spaces. What distiguishes flat mode now is simply that we disable stream indentation. * lib.c (out_json_rec): Remove tests for !jo.flat. (out_json): Remove initialization of jo.flat member. In this function we set up indentation on the stream resulting in multi-line mode (existing behavior). (put_json): Remove initialization of jo.flat member. If flat mode is requested, then it overrides the format to json_fmt_default. I.e. json_fmt_standard coresponding to :standard is only in effect if flat is not requested. In this function we set up indentation on the stream if flat mode isn't requested, otherwise we disable indentation (existing behavior, enough to make flat work). * tests/010/json.tl: Tests for flat mode, :standard formatting, and combinaton of both.
* lop: don't insert args when metas present.Kaz Kylheku2025-01-081-0/+44
| | | | | | | | | | | | | | | | | | | | | The lop macro is inconsistent from op in that it inserts the trailing function arguments on the left even if arguments are explicitly given in the form via @1, @2, ... or @rest. This change makes lop is equivalent to op in all situations when these metas are given. * stdlib/op.tl (compat-225, compat-298): New top-level variables. (op-expand): local variable compat replaced by references to compat-225. If compat-298 is *not* in effect, then metas are checked for first in the cond, preventing the lop transformation from taking place. * tests/012/op.tl: Test cases for lop, combinations of do with lop and a few for op also. * txr.1: Redocumented, added compat notes.
* match-case: bugfix in conversion to casequal.Kaz Kylheku2024-12-201-0/+3
| | | | | | | | | | | | | * stdlib/match.tl (match-case-to-casequal): the (do inc dfl-cnt) action has a problem: it inserts an implicit extra parameter to the invocation of inc, which crashes the + addition due to that parameter being the matching @nil object. We don't need this entire case because it handles @nil, which also matches the following case for (sys:var ...), since @nil is (sys:var nil). That case ahs the same action of incrementing dfl-cnt. * tests/011/patmatch.tl: Test case added.
* string ranges: bug: ranges of length 1.Kaz Kylheku2024-12-152-1/+13
| | | | | | | | | * lib.c (seq_iter_init_with_info): String ranges are inclusive. We must not assume at a range whose endpoints are the same is empty; we must check that case for the endpoints being strings. * tests/012/seq.tl: New tests.
* tests for string range length.Kaz Kylheku2024-12-151-0/+12
| | | | * tests/012/seq.tl: New tests.
* copy: now handles range objects.Kaz Kylheku2024-10-012-0/+6
| | | | | | | | | | | | | | | | Ranges are iterable, denoting abstract sequences. The copy function now copies a range by constructing the array. This is useful when copy is used for the purpose of obtaining a mutable copy. For example, (shuffle 0..100) will now work, returning a shuffled vector of the integers from 0 to 99. * lib.c (copy): Handle RNG case via vec_seq. * tests/012/seq.tl, * tests/012/sort.tl: New test cases. * txr.1: Documented. Documentation for the copy function improved.
* read-until-match: fix regression.Kaz Kylheku2024-09-141-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | Commit 9aa751c8a4f845ef2d2bba091c81ffeded941afd broke things. This fix affects the function read-until-match, scan-until-match and count-until-match which share implementation. * regex.c (scan_until_common): In the REGM_MATCH_DONE and REGM_MATCH cases, we must push the character onto the local stack, before doing the match = stack assignment. Otherwise, it's possible that the stack is empty and so no match is recorded. The REGM_FAIL case will then behave as if no match was found, consuming a character and continuing. * txr.1: Codify an existing behavior: only non-empty matches for the regex are considered by read-until-match. * tests/015/regex.tl: New file. I am amazed to discover that we don't seem to have a test suite for regexes at all. Putting the tests here which confirm this fix and provide coverage for some edge cases in read-until-match.
* keep-if, remove-if, keep-keys-if: mapfun argument.Kaz Kylheku2024-07-301-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We introduce a mapfun argument to these functions so that they can additionally transform the accumulated values. The keep-keys-if function is now implemented through the same helper function as keep-if but with the mapfun argument defaulting to a copy of the keyfun argument. * eval.c (eval_init): Update registrations of remove-if, keep-if and keep-keys-if to new arities of C functions. * lib.c (rem_if_impl): Implement new optional mapfun parameter. (remove_if, keep_if): Add mapfun parameter. (keep_keys_if): Implement via rem_if_impl, and add mapfun argument. We do the defaulting of keyfun here, so that we can then use that argument's value to default mapfun. * lib.h (remove_if, keep_if, keep_keys_if): Declarations updated. * tests/012/seq.tl: Couple of test cases exercising mapfun argument of keep-if and remove-if. * txr.1: Documented.
* zip: more permissive implementation.Kaz Kylheku2024-07-241-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | zip and transpose should allow non-character data when the leftmost column is a string, falling back on making lists, like seq_build. We can't use seq_build as-is because of the special semantics of transpose/zip with regard to strings. We introduce a "strcat" variant of seq_build for this purpose. * lib.c (seq_build_strcat_add): New static function. (sb_strcat_ops): New static structure like sb_str_ops, but with seq_build_strcat_add as the add operation, which allows string arguments to be appended to the string rather than switching to a list. (seq_build_strcat_init): New function. * lib.h (seq_build_strcat_init): Declared. * eval.c (zip_strcat): New static function; uses seq_build_strcat_init. (zipv): Only recognize strings specially; all else goes through the existing default case. Strings use zip_strcat. * tests/012/seq.tl: New test case. * txr.1: Describe special semantics of zip/tranpose; previously only documented in one example. Clarify that the rows are only sequences of the same kind as the leftmost column if possible, otherwise lists. Remove text which says that it's an error for the other columns to contain non-string, non-character objects if the leftmost column is a string.
* make-like: use seq_build.Kaz Kylheku2024-07-231-3/+5
| | | | | | | | | | | * lib.c (make_like): Simplify implementation using seq_build, which also lets it handle more cases. * tests/012/seq.tl: New tests. Some existing test fixed, including one for tuples*. * txr.1: Documentation updated: mainly that make-like doesn't strictly require a list argument.
* New function: seq-like.Kaz Kylheku2024-07-231-0/+14
| | | | | | | | | | | | * eval.c (zip_fun): Renamed to seq_like. (zipv): Follow rename of zip_fun. (eval_init): Register seq-like intrinsic. * tests/seq.tl: Some tests for make-like and seq-like, revealing a difference: make-like needs to be rewritten to use seq_build. * txr.1: Documented.
* json: new *read-json-int* variable.Kaz Kylheku2024-07-221-0/+15
| | | | | | | | | | | | | | | | | | | | | * parser.h (struct parser): New member, read_json_int. * parser.c (read_json_int_s): New symbol variable for *read-json-int* symbol. (parser_common_init): Look up value of *read-json-int* and store in read_json_int struct member. (parse_init): Initialize read_json_int_s with interned symbol and also register the dynamic variable. * parser.l (grammar): Extend the {JNUM} rule to check the read_json_int flag and produce an integer value if the lexeme does not contain a decimal point, e or E. * tests/010/json.tl: New tests. * txr.1: Documented. * lex.yy.c.shipped: Regenerated.
* oop: special methods to handle missing slots.Kaz Kylheku2024-07-191-0/+36
| | | | | | | | | | | | | | | | | | | | | * struct.h (slotset_s, static_slot_s, static_slot_set_s): New symbol variables declared. (enum special_slot): New enum symbols: slot_m, slotset_m, static_slot_m, static_slot_set_m. * struct.c (slotset_s, static_slot_s, static_slot_set_s): New symbol variables. (special_sym): Associate new symbols with new enums. (struct_init): Intern slotset, static-slot and static-slot-set symbols, initializing the variables. Change the registrations of the same-named functions to use the variables. (slot, maybe_slot, slotset, static_slot, static_slot_set): In the no-such-slot case, check for the special method and call it. * tests/012/oop.tl: New tests. * txr.1: Documented.
* New functions: find-maxes and find-mins.Kaz Kylheku2024-07-161-0/+22
| | | | | | | | | | | * eval.c (eval_init): New intrinsic functions find-maxes and find-mins. * lib.[ch] (find_maxes, find_mins): New function. * tests/012/seq.tl: New tests. * txr.1: Documented.
* New funtion related to where function.Kaz Kylheku2024-07-111-0/+39
| | | | | | | | | | | | | | * eval.c (eval_init): register intrinsics wheref, whereq, whereql and wherequal. * lib.c (wheref_fun): New static function. (wheref, whereq, whereql, wherequal): New functions. * lib.h (wheref, whereq, whereql, wherequal): Declared. * tests/012/seq.tl: New tests. * txr.1: Documented.
* partition, split, split*: bug handling negative indices.Kaz Kylheku2024-07-101-19/+31
| | | | | | | | | | | | | | | | * lib.c (partition_func, split_func, split_star_func): When negative indices occur after the sequence has already been shortened, the conversion to positivce must take into account the base. This must be added so that the positive index produced is relative to the original length of the input sequence. When index_rebased is calculated, the base is subtracted out again. If we based the positive index off the shortened length, it's as if we are subtracting base twice. * tests/012/seq.tl: Dubious test cases for split* are replaced with the new results that make sense. Additional test cases are added which cover this issue, for not only split* but split and partition.
* split, split*: fix poor behavior for beyond-length indices.Kaz Kylheku2024-07-101-24/+24
| | | | | | | | | | * lib.c (split_func, split_Star_func): Ignore indices greater than the length of the sequence, the same as negative indices are ignored which don't become nonnegative after adding the length. * tests/012/seq.tl: Fix questionable test cases, which now confirm the right behavior.
* partition: add negative index tests.Kaz Kylheku2024-07-101-0/+36
| | | | * tests/012/seq.tl: New tests.
* split**: split for far negative indices.Kaz Kylheku2024-07-101-0/+32
| | | | | | | | | * lib.c (split_star_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in split_func and partition_func in recent commits. * tests/012/seq.tl: Test cases added.
* split*: add missing tests.Kaz Kylheku2024-07-101-0/+125
| | | | | | * tests/012/seq.tl: Add tests for split* that were lost in some editing. Corresponding tests exist for split already and for partition.
* split: fix for far negative indices.Kaz Kylheku2024-07-101-0/+28
| | | | | | | | | * lib.c (split_func): In empty index case, convert sequence via sub(seq, zero, t), so that ranges are properly expanded. This was done in partition_func in the previous commit. * tests/012/seq.tl: Test cases added.
* split, split*, partition: tests, fixes.Kaz Kylheku2024-07-101-0/+410
| | | | | | | | | | | | | | * lib.c (partition_func): In empty index list case, run the sequence through sub(seq, zero, t) so that ranges are expanded: e.g. 1..3 becomes (1 2). The corresponding code in split_func and split_star_func also needs this fix, but the current test cases don't reproduce a problem. (partition_split_common): Likewise here. * tests/012/seq.tl: Tests for split, split* and partition. Some tests have questionable results. We accept these as they are for now; will address these.
* match: new @(scan-all) operator.Kaz Kylheku2024-06-281-0/+8
| | | | | | | | | | | | | | | | This is like @(scan) but collects all matches over the suffixes of the list. * autoload.c (match_set_entries): Intern scan-all symbol. * stdlib/match.tl (compile-scan-all-match): New function. (compile-match): Dispatch compile-scan-all-match on scan-all symbol. * tests/011/patmatch.tl: Tests for scanall and also missing tests for scan. * txr.1: Documented.
* iter-begin: handle FLNUM.Kaz Kylheku2024-06-261-0/+13
| | | | | | | | | | * lib.c (iter_begin, iter_more, iter_item, iter_step, iter_reset, copy_iter): Handle FLNUM like NUM, so that we don't wastefully return a dynamic iterator object. * tests/012/iter.tl: Test cases for numeric and character iteration. Test cases for iter-begin on some basic types. copy-iter test for floats.
* copy-iter: test for common types.Kaz Kylheku2024-06-261-0/+18
| | | | | * tests/012/iter.tl: Test copy-iter for lists, vectors, integers, characters, strings, string ranges, numeric ranges.
* copy-iter: test that the combi iterators copy.Kaz Kylheku2024-06-261-0/+12
| | | | * tests/015/comb.tl: New tests.
* copy-iter: some tests.Kaz Kylheku2024-06-261-2/+15
| | | | | | | * test/012/oop-seq.tl: Add tests that verify that an OOP iter without a copy method cannot be copied with copy-iter, and that one which has the method can be copied, in accordance with the requirements.
* combi: fix permi and rpermi; impl combi, rcombi; test.Kaz Kylheku2024-06-241-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | * combi.c (permi_get, permi_peek): Fix algorithm. (permi_mark): New static function. (permi_ops): Reference permi_mark for mark operation. (permi): Initialize it->ul.next to nao as required by new get/peek algorithm. (rpermi_get, rpermi_peek): Fix algorithm. (rpermi_mark): New static function. (rpermi_ops): Reference permi_mark for mark operation. (rpermi): Initialize it->ul.next to nao as required by new get/peek algorithm. (combi_get, combi_peek, combi_mark, combi_clone): New static functions. (combi_ops): New static structure. (combi): New function. (rcombi_get, rcombi_peek, rcombi_mark, rcombi_clone): New static functions. (rcombi_ops): New static structure. (rcombi): New function. * combi.h (combi, rcombi): Declared. * tests/015/comb.tl: New tests.
* string ranges: individual positions are ascending/descending.Kaz Kylheku2024-06-201-0/+4
| | | | | | | | | | | | | | | | | | | | In this patch we get rid of the wrongheaded notion that a string range, as such, is ascending or descending. In fact, the corresponding character positions are individually ascending or descending. * lib.c (seq_iter_get_range_str): Either increment or decrement the character in the step string depending on whether that position is in order or reversed. (seq_iter_get_rev_range_str): Static function removed. (si_rev_range_str_ops): Static structure removed. (seq_iter_init_with_info): For string ranges, use si_range_str_ops regardless of the strings being lexicographically reversed. * test/012/iter.tl: New test case. * txr.1: Redocumented string ranges.
* combi: fix broken k 0 edge cases for sequences.Kaz Kylheku2024-06-201-0/+10
| | | | | | | | | * combi.c (rperm, comb, rcomb): In the default case for generic sequences, check k, like in the other cases and return the special case result. * tests/015/comb.tl: New tests.
* New function: copy-hash-iter.Kaz Kylheku2024-06-181-0/+11
| | | | | | | | | | | | * hash.c (hash_iter_ops): Use copy_hash_iter as the clone operation. (copy_hash_iter): New function. * hash.h (copy_hash_iter): Declared. * tests/010/hash.tl: New tests. * txr.1: Documented.
* cobj: clone method streamlines copy; structs get copy method.Kaz Kylheku2024-06-171-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * lib.h (struct cobj_ops): New function pointer, clone. (cobj_ops_init, cobj_ops_init_ex): Add clone argument to macros. * lib.c (seq_iter_cobj_ops): Use copy_iter as the clone operation. (cptr_ops): Use copy_cptr as clone operation. (copy): Replace if statements by check whether COBJ has a clone operation. If so, we use it to copy the object. * struct.h (enum special_slot): New member, copy_m. * struct.c (copy_s): New symbol variable. (special_sym): Associate copy_m enum value with copy symbol. (struct_init): Initialize copy_s with interned symbol. (struct_inst_clone): New static function. (struct_type_ops): Specify no clone operation via null pointer. (struct_inst_ops): Specify struct_inst_clone as clone operation. * arith.c (psq_ops): Indicate no clone operation via null pointer. * buf.c (buf_strm_ops): Likewise. * chksum.c (sha1_ops, sha256_ops, md5_ops): Likewise. * ffi.c (ffi_type_builtin_ops, ffi_type_struct_ops, ffi_type_ptr_ops, ffi_type_enum_ops, ffi_closure_ops, union_ops): Likewise. (carray_borrowed_ops, carry_owned_ops, carray_mmap_ops): Specify copy_carray as clone operation. * gc.c (prot_array_ops): Indicate no clone operation via null pointer. * gzip.c (gzio_ops_rd, gzip_ops_wr): Likewise. * hash.c (hash_iter_ops): Likewise. (hash_ops): Specify copy_hash as clone operation. * parser.c (parser_ops): Indicate no clone operation via null pointer. * rand.c (random_state_clone): New static function. (random_state_ops): Use random_state_clone as clone function. * regex.c (char_set_obj_ops, regex_obj_ops): Indicate no clone operation via null pointer. * socket.c (dgram_strm_ops): Likewise. * stream.c (null-ops, stdio_ops, tail_ops, pipe_ops, dir_ops, string_in_ops, byte_in_ops, strlist_in_ops, string_out_ops, strlist_out_ops, cat_stream_ops, record_adapter_ops): Likewise. * strudel.c (strudel_ops): Likewise. * sysif.c (cptr_dl_ops, opendir_ops): Likewise. * syslog.c (syslog_strm_ops): Likewise. * unwind.c (cont_ops): Likewise. * vm.c (vm_desc_ops, vm_closure_ops): Likewise. * tree.c (tree_ops): Use copy_search_tree for clone operation. (tree_iter_ops): Use copy_tree_iter for clone operation. * genchksum.txr: Changes in chksum.c specified in one place here. * tests/012/oop.tl: Couple of new tests. * txr.1: Documented.
* quasiliterals: buffers in hex, separation for strings and buffers.Kaz Kylheku2024-05-271-2/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | In this commit, output variables in the TXR Pattern language and in TXR Lisp quasiliterals now support separator strings for values that are strings and buffers. Values which are buffers appear differently: they are rendered as a sequence of lower case hex digit pairs. When a string-valued variable specifies a separator, the separator appears between characters of the string value. Previously, the separator was ignored. When a buffer-valued variable specifies a separator. the separator appears between pairs of digits, not between digits. For instance if ethaddr is a variable holding #b'08:00:27:79:c7:f5', then the quasiliteral `@ethaddr` produces "08002779c7f" whereas `@{ethaddr ":"}` produces "08:00:27:79:c7:f5". * buf.[ch] (buf_str_sep): New function. * lib.[ch] (fmt_str_sep): New function. * eval.c (fmt_cat): If the argument is a string, and a separator is present, replace the value with the result of calling fmt_str_sep. If the argument is a buffer, and a separator is present, use buf_str_sep to convert to a string, otherwise use tostringp. * txr.1: Section on Output Variables updated. * tests/012/readprint.tl: New tests.
* interpose: use seq_iter and seq_build.Kaz Kylheku2024-05-261-0/+11
| | | | | | | * lib.c (interpose): non-list cases consolidated into one, which uses generic iteration and building. * tests/012/seq.tl: New tests
* buf: pprint produces hex, not raw bytes.Kaz Kylheku2024-05-031-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The pprint semantics of buffers is that the raw bytes are dumped into the stream. This is poor. It was hastily designed based on analogy with strings, which pprint by just sending their contents to the stream; but for strings this is justified because they represent text. We also fix the semantics of buffer values being rendered by quasiliteral notation. Currently, the are treated as sequences, and so they explode into individual decimal integers. * buf.c (buf_pprint): Print the bytes as pairs of lower-case hex digits, with no line breaks. In 294 compatibility or lower, put out bytes as before. * eval.c (fmt_cat): When not in 294 compatibility mode, treat a buffer object via tostringp, which will render it to hexadecimal via buf_pprintf. In compatibility mode, treat it as before, which is as a sequence: the individual values of the buffer are converted to text, thus decimal values in the range 0 to 255, catenated using the given separator. * tests/012/readprint.tl: New tests. * txr.1: Documented. Also expanding on what pretty printing means in TXR.
* New function: iter-cat.Kaz Kylheku2024-04-161-0/+5
| | | | | | | | | | | | | | | | * eval.c (eval_init): Register iter-cat intrinsic. * lib.h (struct seq_iter): New union member dargs. (iter_catv): Declared. * lib.c (seq_iter_get_cat, seq_iter_peek_cat): New static functions. (si_cat_ops): New static structure. (iter_catv): New function. * tests/012/iter.tl: New tests. * txr.1: Documented.
* New functions for filtering through external processes.Kaz Kylheku2024-04-041-0/+8
| | | | | | | | | | | | | | * stdlib/getput.tl (sys:maproc-common): new function. (map-command-lines, map-command-str, map-command-buf, map-process-lines, map-process-str, map-process-buf): New functions. * autoload.c (getput_set_entries): Trigger autoload of getput module on new function symbols. * tests/018/getput.tl: New tests. * txr.1: Documented.
* tests: stability of fini test case.Kaz Kylheku2024-03-171-1/+1
| | | | | | | | * test/012/fini.tl: Pass t to sys:gc to request full garbage collection. Otherwise the output may be reordered, due to some of the objects made earlier in the test case being promoted to the mature generation and thus not finalized by the (sys:gc) call.
* tests: suppress warnings in seq.tl.Kaz Kylheku2024-03-081-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When tests/012/compile.tl compiles tests/012/seq.tl, there are now some compiler warnings due to constant expressions that throw. We introduce a new compiler option to suppress them, and then use it. * stdlib/comp-opts.tl: New file. The definitions related to compiler options are moved here out of compile.tl, so that optimize.tl can use them. * stdlib/compiler.tl (compile-opts, %warning-syms%, when-opt, *compile-opts*, opt-controlled-diag): Moved to comp-opts.tl. New constant-throws option added to compile-opts and %warning-syms%. (safe-constantp): Make the constant expression throws diagnostic conditional on the new option. * stdlib/optimize.tl: Load comp-opts file. (basic-blocks do-peephole-block): Make diagnostic about throwing situation subject to constant-throws option. * tests/012/seq.tl: Turn off constant-throws warning option before the ref tests that work with ranges. Fix: one of the expressions calls refs with the wrong number of arguments, which was unintentional. * txr.1: Document new diagnostic option.
* New function: rangeref.Kaz Kylheku2024-03-071-0/+56
| | | | | | | | | | | | | | | | | | | | | Because ranges can be iterated like sequences, and are identified as vector-like, they have to support indexing. However, ranges already have semantics as a function: with a sequence argument, they slice it. Let's put the semantics into a function called rangeref, so it can be coherently documented. * eval.c (eval_init): Register rangeref intrinsic. * lib.c (generic_funcall): Range as a function works in terms of rangeref. (ref): Handle RNG case via rangeref. (rangeref): New function. * lib.h (rangeref): Declared. * tests/012/seq.tl: New tests.
* mapcar: avoid alloca proportional to number of args.Kaz Kylheku2024-03-011-0/+3
| | | | | | | | | | | | | | | * eval.c (MAP_ALLOCA_LIMIT): New preprocessor symbol. (map_common): If the number of args is greater than MAP_ALLOCA_LIMIT, then allocate the array of seq_iter_t structures from chk_malloc rather than alloca. In case an exception might be thrown during the execution of this function, we bind that memory to a buf object. If we return normally, we call the new function buf_free to release it. Otherwise we rely on the garbage collector. * buf.[ch] (buf_free): New function. * tests/012/seq.tl: Test case which hits this behavior.
* zip: make more generic.Kaz Kylheku2024-03-011-0/+66
| | | | | | | | | | | | | | | | * lib.c (do_pa_12_1_v, pa_12_1_v): Static functions removed. (transposev, transpose): Functions removed. * lib.c (transposev, transpose): Declarations removed. * eval.c (join_f): New global variable. (zip_fun, zipv, transpose): New static functions. (eval_init): gc-protect join_f, and initialize it. Registration of zip intrinsic goes to zipv rather than transposev. sys:fmt-join and join registered with help of global join_f rather than local. * tests/012/seq.tl: New zip test cases.
* tuples: convert tuple generation to seq_build.Kaz Kylheku2024-02-271-1/+1
| | | | | | | | | | * lib.c (tuples_func): Replace list accumulation with make_like with seq_build. * tests/012/seq.tl: Fix one test case here which no longer errors out. It produces a tuple which is not a string, due to the inclusion of a non-character object.