summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
...
* doc: update car, cdr, rplaca, rplacd.Kaz Kylheku2018-01-081-26/+114
| | | | | | | | | | | * txr.1: Update the documentation to reflect the current handling of objects, eliminating some contradictions in the process, like text which says that rplacd is erroneous on anything but conses and lazy conses, followed by text which states other kinds of objects are allowed. The semantics of car and cdr forms as places is described strictly in terms of rplaca and rplacd, so the mechanism is then described in one place.
* tail: reduce calls to cdr.Kaz Kylheku2018-01-071-2/+3
| | | | | | * lib.c (tail): Don't call cdr on the same cell twice in the loop body. tail is used in list_collect and friends, which are used all over the place.
* term: move near site of use.Kaz Kylheku2018-01-073-8/+7
| | | | | | | | | * eval.c (term): Function here from lib.c, and changed to static. It is used only by iapply. * lib.c (term): Function moved to eval.c. * lib.h (term): Declaration removed.
* listref_l: remove.Kaz Kylheku2018-01-062-18/+0
| | | | | | * lib.c (listref_l): Unused function removed. * lib.h (listref_l): Declaration removed.
* refset: implement objects that support car method.Kaz Kylheku2018-01-061-12/+46
| | | | | | | | | | | | | | refset and range assignment is implemented for objects that have no lambda-set but do have a car method. * lib.c (refset): Implementation for lists rewritten to avoid listref_l, and use nthcdr instead. For structs, if there is no lambda-set method, but a car method exists, jump to the list case: the idea is that we can cdr down and then use rplaca. (dwim_set): Error handling streamlined. In this function too, we check whether there is a car method and branch to the list case.
* nthcdr: terminate loop if end of list hit.Kaz Kylheku2018-01-051-1/+1
| | | | | * lib.c (nthcdr): Terminate loop when nil is hit rather than continuing to count down to zero.
* car, cdr: self-identify in error message.Kaz Kylheku2018-01-051-2/+2
| | | | | * lib.c (car, cdr): Type mismatch messages now identify functions.
* car, cdr: fall back on lambda method.Kaz Kylheku2018-01-031-4/+24
| | | | | | * lib.c (car, cdr): Don't fail if the struct object has no car or cdr method. Use it if it is available, otherwise try to fall back on the lambda method if that is available.
* ltail: unused function.Kaz Kylheku2018-01-022-8/+0
| | | | | | | | * lib.c (ltail): Function removed. This was introduced at the same time as lazy_appendv and used only by it. That function was rewritten a few months ago and doesn't use lail. * lib.h (ltail): Declaration removed.
* seq_info: bugfix: wrong object tested obj_struct_p.Kaz Kylheku2018-01-021-1/+1
| | | | | | * lib.c (seq_info): The obj_struct_p test must be applied to obj, not to cls, which is a symbol. Due to this bug, seq_info would always report struct-based sequences as SEQ_NOTSEQ.
* seq_info: whitespace.Kaz Kylheku2018-01-021-1/+1
| | | | | * lib.c (seq_info): Incorrect indentation of else statement fixed.
* last: rewrite using seq_info.Kaz Kylheku2018-01-021-10/+17
| | | | | * lib.c (last): Use seq_info classification rather than relying on listp.
* eliminate cdr_l use from implementation of last.Kaz Kylheku2018-01-022-12/+8
| | | | | | * lib.c (lastcons): Return value is just the last cons rather than a loc. The only caller of this function is last. (last): Adapt to the new lastcons.
* Use rplaca and rplacd instead of set over car_l/cdr_l.Kaz Kylheku2018-01-017-28/+28
| | | | | | | | | | | | | | | | | | | | | | | This reduces the proliferation of car_l and cdr_l. With this change, nreverse should work on chains of objects that implement rplacd. * combi.c (comb_gen_fun_common, rcomb_gen_fun_common): Use rplaca. * eval.c (mappendv, mapdov): Likewise * hash.c (hash_equal_op): Likewise. * lib.c (nreverse, acons_new, aconsql_new, sort_list): Use rplaca and rplacd. * match.c (dest_set, v_gather, v_collect, v_flatten, v_cat, v_output, v_filter): Likewise * parser.c (ensure_parser): Use sys_rplacd. * unwind.c (uw_register_subtype): Use rplacd.
* sub and replace redirect to structure methods.Kaz Kylheku2018-01-013-6/+121
| | | | | | | | | | | | | * lib.c (replace_obj): New static function. (sub): Handle struct case via lambda method. (replace): Handle struct case via replace_obj. * txr.1: Documented. * tests/012/aseq.tl (add): The lambda method now has to handle a range argument. One test case uses the last function, which for non-lists relies on sub, which now calls the lambda method if the object has one.
* New inlined test for struct object.Kaz Kylheku2017-12-313-19/+20
| | | | | | | | | | | * lib.c (seq_info, car, cdr, make_like, nullify, generic_funcall, copy, length, empty, ref, refset, dwim_set, dwim_del, populate_obj_hash): Use new obj_struct_p test when we know that the object is a COBJ. * struct.c (struct_inst_ops): Change from static to extern. * struct.h (ob_struct_p): New inline function.
* New methods rplaca and rplacd.Kaz Kylheku2017-12-304-2/+101
| | | | | | | | | | | | | | | * eval.c (eval_init): Register rplaca and rplacd using new rplaca_s and rplacd_s symbol variables. * lib.c (rplaca_s, rplacd_s): New symbol variables. (rplaca): Handle struct object via rplaca method, if it has one, otherwise lambda-set, if it has that, or else error out. (rplacd): Handle struct object via rplacd method. * lib.h (rplaca_s, rplacd_s): Declared. * txr.1: Documented rplaca and rplacd methods.
* refset: better diagnostics.Kaz Kylheku2017-12-291-1/+3
| | | | | | * lib.c (refset): If structure has no lambda-set method, diagnose it like that, rather than "not a sequence". Also, diagnostics should use refset:, not ref:.
* doc: invoke-catch: no such function as get-framesKaz Kylheku2017-12-291-2/+3
| | | | | * txr.1: Fix wording under invoke-catch which refers to a nonexistent function called get-frames.
* read, iread: source location recording now conditional.Kaz Kylheku2017-12-295-64/+130
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Recording of source location info incurs a time and space penalty. We don't want to impose this on programs which are just reading large amounts of Lisp data that isn't code. * eval.c (eval_init): Register lisp-parse and read functions to the newly introduced nread function rather than lisp_parse. lisp_parse continues to record source location info unconditionally. * parser.c (rec_source_loc_s): New symbol variable. (parser_common_init): Set the new member of the parser structure, rec_source_loc, according to the current value of the special var *rec-source-loc*. (lisp_parse_impl): New second argument, rlcp_p. If true, it overrides the rec_source_loc member of the parser structure to true. (lisp_parse): Pass true argument to rlcp_p parameter of lisp_parse_impl, so parsing via lisp_parse always records source loc info. (nread): New function. (iread): Pass true argument to rlcp_p parameter of lisp_parse_impl, so *rec-source-loc* controls whether source location info is recorded. (parse_init): Initilize rec_source_loc_s symbol variable, and register the *rec-source-loc* special var. * parser.h (struct parser): New member, rec_source_loc. (rec_source_loc_s, nread): Declared. * parser.y (rlcp_parser): New static function. Like rlcp but does nothing if parser->rec_source_loc is false. (rlc): New macro. (grammar): Replace rlcp uses with rlc, which expands to a call to rlcp_parser. (rlrec): Do nothing if source loc recording is not enabled in the parser. (make_expr, uref_helper): Replace rlcp with rlc. This is possible because these functions have a parser local variable that the macro expansion can refer to. (parse_once): Override rec_source_loc in the parser to 1, so that source loc info is always recorded when parsing is invoked through this function. * txr.1: Documented *rec-source-loc* and added text under read and iread.
* hash: read/print consistency regression.Kaz Kylheku2017-12-283-57/+78
| | | | | | | | | | | | | | | | | | | | | | TXR 188 makes a slight mess of the #H notation. An :eql-based hash table prints as #H(() ...), but when that notation is read, it produces an :equal-based hash table. No aspect of this situation was intended; the intent was that the notation stays the same as before, and just the hash function changes to make :equal-based the default. Let's just go with this and have #H(() ...) denote :equal-based tables. * hash.c (hash_print_op): Print an :eql-based for eql-based hash tables, and nothing for equal-based ones. In compatibility mode with 188 and older, reproduce the old behavior, rendering equal-based tables with :equal-based and the absence of a symbol for eql-based. * txr.1: Updated places that touch on :equal-based and added compatibility notes. * tests/009/json.expected: updated, since equal-based hash tables now print without :equal-based keyword.
* doc: document listener :prompt properly.Kaz Kylheku2017-12-281-1/+1
| | | | | * txr.1: There is no :print command in the listener to print the current prompt; it is actually the :prompt command.
* Version 188.txr-188Kaz Kylheku2017-12-197-762/+815
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim, protsym.c: Regenerated.
* New functions: rlist and rlist*.Kaz Kylheku2017-12-182-0/+135
| | | | | | | | | | These easily express discontinuous ranges. * eval.c (rlist_fun, rlist_star_fun, rlist, rlist_star): New static functions. (eval_init): Register rlist and rlist* intrinsics. * txr.1: Documented.
* expander: do constant folding of a..b range exprs.Kaz Kylheku2017-12-181-0/+9
| | | | | | | | | * eval.c (do_expand): In the function call case, check for the operator being the rcons function. If it is called with exactly two arguments and they are constantp in the given environment, then evaluate them and replace with a range literal object. Rationale: ranges often appear in constant form like [array 1..:] and whatnot.
* doc: listener: clarify about deletion in selection mode.Kaz Kylheku2017-12-151-3/+11
| | | | | | * txr.1: Clarify that Ctrl-D is the only deletion command which copies into the clipboard, and only in visual selection mode.
* doc: ffi: clarify in and out nuances.Kaz Kylheku2017-12-151-6/+7
| | | | | | | | | | | * txr.1: Fix wrong wording about the by-value nuance of the in operation. What is specifically doesn't do, in contrast to the by-pointer nuance, is propagate the foreign representation back to Lisp. Not Lisp to foreign, which is opposite to the in operation. Also clarifying some wording in the description of the out operation: that the by-value nuance doesn't reconstruct from the updated Lisp structure, to help the reader keep in mind the data direction.
* awk: condense implementation of range-macros.Kaz Kylheku2017-12-151-36/+13
| | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-mac-let): Move repeated boiler-plate code from the various rng macrolets into an the implementation of the sys:rng macro they rely on. That implementation is split into two macros: sys:rng is now the name of a wrapper which adds the boiler-plate, and the bulky implementation macrolet is now called sys:rng-impl.
* doc: slots, not members.Kaz Kylheku2017-12-141-9/+9
| | | | | | * txr.1: Fixed a number of places where structure slots are called members. In the context of structures, we use the word member only for C structures; Lisp structures have slots.
* doc: wrong typesetting of suspend.Kaz Kylheku2017-12-141-1/+1
| | | | | | * txr.1: Example for sys:capture-cond uses wrong style for the reference to the suspend operator suspend, causing it not to be hyper-linked to the definition in the HTML version.
* doc: swapped words in continuations description.Kaz Kylheku2017-12-141-1/+1
| | | | | | * txr.1: Paragraph about sys:cont-poison must say "continuation's evaluation frames" not "evaluation's continuation frames"
* doc: attempt to clarify continuations.Kaz Kylheku2017-12-141-18/+85
| | | | | | | * txr.1: Under sys:capture cont, try to revise some potentially confusing text. Also adding more notes, clarifying the semantics of shared lexical environments, and behavior of special variable bindings with regard to continuations.
* doc: example formatting under tuples.Kaz Kylheku2017-12-141-1/+2
| | | | | | * txr.1: Fix example code that is too wide, causing a visual problem for standard 80 column man page formatting.
* doc: severe formatting problem under int-str.Kaz Kylheku2017-12-141-2/+2
| | | | | * txr.1: Fix lack of escaping of backslash in #\c causing the c to be interpreted as a troff code.
* doc: mapcar heading problem.Kaz Kylheku2017-12-141-1/+1
| | | | * txr.1: Add missing comma in mapcar section heading.
* Structure delegate streams documented.Kaz Kylheku2017-12-141-0/+446
| | | | | | | * txr.1: New major (SS*) section User-Defined Streams. Documented make-struct-delegate-stream function, the stream-wrap class and all the stream interface object methods.
* New feature: structure delegate streams.Kaz Kylheku2017-12-088-13/+434
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A new kind of stream object which redirects its operations to the methods of a structure. * Makefile (OBJS): New object file, strudel.o. * lib.c (init): Call new strudel_init function. * lisplib.c (stream_wrap_set_entries, stream_wrap_instantiate): New static functions. (lisplib_init): Arrange for autloading of new stream-wrap.tl. * share/txr/stdlib/stream-wrap.tl: New file. * stream.c (put_string_s, put_char_s, put_byte_s, get_line_s, get_char_s, get_byte_s, unget_char_s, unget_byte_s, put_buf_s, fill_buf_s, flush_s, seek_s, truncate_s, get_prop_s, set_prop_s, get_error_s, get_error_str_s, clear_error_s, get_fd_s): New symbol variables. (stream_init): New symbol variables initialized. Numerous functions registered via these variables now rather than intern(...) expressions. * stream.h (put_string_s, put_char_s, put_byte_s, get_line_s, get_char_s, get_byte_s, unget_char_s, unget_byte_s, put_buf_s, fill_buf_s, flush_s, seek_s, truncate_s, get_prop_s, set_prop_s, get_error_s, get_error_str_s, clear_error_s, get_fd_s): Declared. * strudel.c, strudel.h: New files.
* trace: bugfix: spurious "previously traced" warningKaz Kylheku2017-12-081-2/+2
| | | | | | | | | | | | | | When a method is traced with (trace (meth class slot)), a spurious warning occurs. This is because the function is recorded in the trace hash first and then the hook is installed, and the hook is installed using the static-slot-ensure function which performs the trace warning check. * share/txr/stdlib/trace.tl (sys:trace): Swap the order: install the hook first, and then put the the previous function into the trace hash. Doing this in parallel with pset would also work.
* hash tables: now default to :equal-based.Kaz Kylheku2017-12-063-39/+114
| | | | | | | | | | | | | | * hash.c (eql_based_k): New keyword variable. (equal_based_p): New static function. (hashv): Use eql_based_p to determine whether to make an equal-based hash table. Subject to opt_compat relative to version 187. (hash_init): Intern :eql-based keyword and store in new variable. * hash.h (eql_based_k, userdata_k): Declared. * txr.1: Documentation updated, with compat notes too.
* prof: deal with overflowing mem counters.Kaz Kylheku2017-12-042-2/+19
| | | | | | | | * eval.c (op_prof): Deal with the cases when alloc_bytes_t value cannot be converted to a val in a single call to unum. * lib.h (SIZEOF_ALLOC_BYTES_T): New macro.
* args: redesign args extractor to just use array.Kaz Kylheku2017-12-043-50/+27
| | | | | | | | | | | | | | | | | | | * args.c (struct args_bool_key): Structure moved to header file. (struct args_bool_ctx): One more piece of context information, the array size. (args_check_key_store): Work with array of args_bool_key structs rather than linked list. Remove useless local variable "store". (args_key_extract_vl): Function removed. (args_key_extract): Takes array instead of va_list. * args.h (struct args_bool_key): Structure declared here. Loses the next pointer since not used for a linked list. (args_key_extract_vl): Function removed. (args_key_extract): Redeclared. * hash.c (hashv): Adapt to new args_key_extract function.
* hash: use new args keyword extraction mechanism.Kaz Kylheku2017-12-011-6/+8
| | | | * hash.c (hashv): Switch over to args_keys_extract.
* args: keyword extraction mechanism.Kaz Kylheku2017-12-012-0/+94
| | | | | | | | | | | | | | | | Implement a mechanism for extracting keyword arguments out of "struct args *" argument lists which avoids consing up an argument list and scanning it multiple times for multiple keywords. * args.c (args_for_each): New function. (struct args_bool_key, struct args_bool_ctx): New struct types. (args_key_check_store): New static function. (args_keys_extract_vl, args_key_extract): New functions. * args.h (args_for_each, args_keys_extract_vl, args_key_extract): Declared.
* Rewrite internal mapping function.Kaz Kylheku2017-11-301-4/+21
| | | | | | * lib.c (mapcar_listout): Rework using seq_info for efficient processing of vector-like sequences and objects that implement sequences.
* bugfix: code-walk the result of a declined macro.Kaz Kylheku2017-11-291-2/+3
| | | | | | | | | | | | | | | | When a form is a macro, but the macro declines to expand the form, the form must still be code walked; we can't just return it and be done. For instance if it is a function call, its argument expressions have to be expanded. This also causes undefined function warning to be generated properly if a macro declines, and the resulting form is a function call to a not-yet-defined function. * eval.c (do_expand): If expand_macro yields the original form, branch backwards to re-execute the whole if statement again. Use the fact that the local variable macro is now non-nil to skip the macro expansion case.
* macros: expand declined form in outer env.Kaz Kylheku2017-11-244-1/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch implements a new requirement which clarifies what happens when a macro declines to expand a form. To decline expanding a form means to return the original form (same object) without returning it. The expander detects this situation with an eq comparison on the input and output. The current behavior is that no further attempts are made to expand the form. This is problematic for various reasons. In code which is expanded more than once, this can lead to the expansion being different between the expansion passes. In the first pass, a local macro M might decline to expand a form. In the second pass, the local macro definition no longer exists, and the form does get expanded by a global macro M. This kind of instability introduces a flaw into complex macros which expand their argument material more than once. The new requirement is that if a macro definition declines to expand a macro, then a search takes place through the outer lexical scopes, and global scope, for the innermost macro definition which will expand the form. The search tries every macro in turn, stopping if a macro is found which doesn't decline the expansion, or after passing the global scope. * eval.c (expand_macro): Implement new searching behavior. * txr.1: Documented the expansion declining mechanism under defmacro and macrolet. * tests/011/macros-3.tl: New file. * tests/011/macros-3.expected: New file.
* Fix quoted function name in unsupported object errors.Kaz Kylheku2017-11-231-11/+17
| | | | | | | | | * lib.c (unsup_obj): New static function. (grade, find, rfind, find_max, find_if, rfind_if, pos, rpos, pos_if, rpos_if, pos_max): Replace call to uw_throwf with call to unsup_obj. IN all these functions except grade, the ~s conversion specifier was wrongly used on the function name rather than ~a, resulting in unwanted quoting.
* New function: grade.Kaz Kylheku2017-11-234-0/+90
| | | | | | | | | | | | Inspired by APL. * eval.c (eval_init): Register grade intrinsic. * lib.c (grade): New function. * lib.h (grade): Declared. * txr.1: Documented.
* lastcons: streamline.Kaz Kylheku2017-11-221-1/+1
| | | | | * lib.c (lastcons): Don't wastefully call cdr on an object after called cdr_l; just dereference the cdr_l loc.
* bugfix: tail handles improper list.Kaz Kylheku2017-11-221-1/+1
| | | | | | | | | | | * lib.c (tail): This low-level function is used by the list accumulation routines. Because it doesn't handle improper lists, looking for a null terminator, certain things don't work, like the associativity of append. For instance (append '(1 2) #(3) 4) works but not (append (append '(1 2) #(3)) 4). Fixing tail so that it terminates on any atom, rather than failing trying to cdr through it.