summaryrefslogtreecommitdiffstats
Commit message (Collapse)AuthorAgeFilesLines
* doc: clarifications under lambda.Kaz Kylheku2019-03-221-1/+21
| | | | | | | | | * txr.1: Make it clearer that the default expression of an optional parameter is only evaluated when required. Document that t, nil and keyword symbols can't be used as parameters, and that duplicates symbols are unspecified, the situation being diagnosed by the compiler but ignored by the interpreter.
* doc: update let/let* doc.Kaz Kylheku2019-03-221-14/+117
| | | | | | * txr.1: specification of let and let* is substantially revised for clarity, and behavior of duplicate symbols, and special variables.
* take-until: rewrite with seq_info; elide cons.Kaz Kylheku2019-03-201-16/+13
| | | | | | | | | | * lib.c (take_until_list_fun): Renamed to lazy_take_until_list_fun. (lazy_take_until_list_fun, take_until): take_until upgraded to use seq_info to classify sequence. In the lazy list case, the state cons is elided; the predicate function is passed as the function environment, and the key function and list being traversed are propagated via the lazy cons car and cdr.
* take: rewrite with seq_info; elide cons.Kaz Kylheku2019-03-202-32/+32
| | | | | | | | | | | | | * lib.c (take_list_fun, take_while_list_fun): Renamed to lazy_take_list_fun and lazy_take_while_list_fun respectively. (lazy_take_list_fun, take): take upgraded to use seq_info to classify sequence. In the lazy list case, the state cons is elided; the list is passed as the function environment, and the remaining count is propagated in the lazy cons's car field. (lazy_take_while_list_fun, take_while): Similar changes. * txr.1: Fixed accidental reference to drop function in the documentation for the take function.
* interpose: eliminate state cons.Kaz Kylheku2019-03-181-9/+5
| | | | | * lib.c (lazy_interpose_func, lazy_interpose): Pass list in car of lcons, and separator as function env.
* partition*: optimization.Kaz Kylheku2019-03-181-14/+8
| | | | | | * lib.c (partition_star_func, partition_star): Eliminate state cons. Eliminate wasteful cons updating and destructuring in loop.
* doc: clarify split/partition difference.Kaz Kylheku2019-03-181-0/+8
| | | | | * txr.1: Under in split doc, add a sentence highlighting the difference between split and partition.
* partition, split, split*: eliminate state conses.Kaz Kylheku2019-03-181-30/+31
| | | | | | * lib.c (partition_func, split_func, split_star_func, partition_split_common): Store three context elements in function's env, and lcons car/cdr.
* partition-by: eliminate state conses.Kaz Kylheku2019-03-171-12/+7
| | | | | | * lib.c (partition_by_func, partition_by): Store the three context items in the function's env, and the lcons car and cdr, instead of allocating a two-cons list stored in the env.
* tuples: eliminate state conses.Kaz Kylheku2019-03-151-8/+6
| | | | | | * lib.c (tuples_func, tuples): Store the three context items in the function's env, and the lcons car and cdr, instead of allocating a two-cons list stored in the env.
* flatcar*: eliminate state cons.Kaz Kylheku2019-03-151-5/+5
| | | | | | | * lib.c (lazy_flatcar_func, lazy_flatcar): Here, the state information consists of just one value. We just make that value itself the function's env, and mutate that env as needed.
* flatten*: use lcons for threading state.Kaz Kylheku2019-03-151-5/+6
| | | | | | | * lib.c (lazy_flatten_func, lazy_flatten): Do not allocate a cons to hold the traversal state. In fact, the environment of the function is not used at all; the lcons car and cdr are used to propagate the state.
* append*: save a bit of memory.Kaz Kylheku2019-03-141-9/+8
| | | | | | | | * lib.c (lazy_appendv_func, lazy_appendv): Do not allocate a cons cell for maintaining the state. Use the function environment for one of the two state values, and thread the other state value through the initial car contents of each lazy cons cell.
* New unchecked setter for function environment.Kaz Kylheku2019-03-142-0/+7
| | | | | | | * lib.c (us_func_set_env): New function: func_set_env without the type check. * lib.h (us_func_set_env): Declared.
* doc: clarifications regarding struct-typeKaz Kylheku2019-03-131-0/+12
| | | | | * txr.1: Clarifying text added under find-struct-type and struct-type-p to better explain struct-type.
* oop: make struct symbol supertype of all structs.Kaz Kylheku2019-03-132-2/+14
| | | | | | | | * lib.c (subtypep): If the supertype is struct, then return t if the subtype is the name of a struct type. * txr.1: Update the type graph to show the struct root, adding a note about it.
* lazy conses: support state in car and cdr.Kaz Kylheku2019-03-134-6/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Here we allow application code to take advantage of a trick already used internally. When a lazy cons cell is created, we can temporarily put state information into its car and cdr fields. When these fields are accessed normally, by the car and cdr function, the lazy cons' update function will be invoked, which will populate these fields. If we have a way for that function to retrieve the existing values of those fields, then the function can treat those fields as state information: it can retrieve the values into temporary local variables, overwrite the original values, and then propagate the state information into the car and cdr into the next lazy cons cell being added. Thus lazy list generation that needs two cells of state or less does not require the allocation of a context object. * eval.c (eval_init): make-lazy-cons becomes a three-argument function with two optional parameters. New functions lcons-car and lcons-cdr are registered. * lib.c (make_lazy_cons_pub): New function, wrapping make_lazy_cons_car_cdr with argument defaulting. (lcons_car, lcons_cdr): New functions. * lib.h (make_lazy_cons_pu, lcons_car, lcons_cdr): Declared. * txr.1: Updated doc of make-lazy-cons regarding new arguments. Documented lcons-car and lcons-cdr.
* lib: use accessor for lcons function.Kaz Kylheku2019-03-122-6/+7
| | | | | | | | * hash.c (hash_keys_lazy, hash_values_lazy, hash_pairs_lazy, hash_alist_lazy): Use us_lcons_fun instead of direct lcons->lc.fun access. * lib.c (simple_lazy_stream_func, lazy_stream_func): Likewise.
* lib: introduce new make_lazy_cons variant.Kaz Kylheku2019-03-122-15/+16
| | | | | | | | | | * lib.c (make_lazy_cons_car_cdr): New function. (lazy_where_func, lazy_where_hash_func, where): Use make_lazy_cons_car and the new make_lazy_cons_car_cdr instead of two-step construction and initialization with us_rplaca and us_rplacd. * lib.h (make_lazy_cons_car_cdr): Declared.
* lib: rename make_half_lazy_cons.Kaz Kylheku2019-03-123-15/+15
| | | | | | | | | | | * lib.h (make_half_lazy_cons): Renamed to make make_lazy_cons_car. * lib.c (rem_lazy_rec, make_half_lazy_cons): Follow rename. * hash.c (hash_keys_lazy, hash_keys, hash_values_lazy, hash_values, hash_pairs_lazy, hash_pairs, hash_alist_lazy, hash_alist): Follow rename.
* lib: optimize lazy functions with unchecked accesses.Kaz Kylheku2019-03-123-150/+156
| | | | | | | | | | | | | | | | | | * lib.h (us_lcons_fun): New inline function. (us_cons_bind): New macro. * eval.c (lazy_mapcar_func, lazy_mapcarv_func, range_func, range_star_func, generate_func, giterate_func, ginterate_func, expand_right_fun, repeat_infinite_func, repeat_times_func, pad_func): Use us_cons_bind, us_car, us_cdr, us_rplaca, us_rplacd and us_lazy_cons_func, which skip the type check. * lib.c (lazy_conses_func, lazy_appendv_func, rem_lazy_func, lazy_flatten_func, lazy_flatcar_fund, tuples_func, partition_by_func, partition_func, split_func, split_star_func, partition_star_func, lazy_interpose_fun, take_list_fun, take_while_list_fun, take_until_list_fun, lazy_where_has_func): Likewise.
* doc: more accurate dialect note about package prefixes.Kaz Kylheku2019-03-121-1/+8
| | | | | * txr.1: Update the possibly misleading dialect note about treatment of foo:bar in ANSI CL.
* where: convert to lazy.Kaz Kylheku2019-03-122-46/+82
| | | | | | | | * lib.c (lazy_where_func, lazy_where_hash_func): New static functions. (where): Rewritten to generate lazy list. * txr.1: Doc updated.
* float: turn out-of-range calculations into exceptions.Kaz Kylheku2019-03-122-4/+51
| | | | | | | | | | | | | | | On platforms that have the C99 fpclassify, we can use it to banish infinity and NaN representations. If such a thing arises, we throw an exception rather than producing an object that prints as #<bad-float>. * configure: add detection for fpclassify. * lib.c (bad_float): New inline function and macro. (flo): If the argument is other than zero, a normal value or a subnormal, then throw an exception. We thereby refuse to admit such objects into our numeric object system.
* parser: catch out-of-range floats.Kaz Kylheku2019-03-122-3/+20
| | | | | | | | | | * parser.l (out_of_range_float): New static function. (grammar): Check for flo_str returning nil in several places; that value is returned for out of range floats. This is not documented! * txr.1: Document athat flo-str returns nil for out-of-range floats.
* New sequence iterator object and functions.Kaz Kylheku2019-03-114-2/+120
| | | | | | | | | | | | | | | | | * eval.c (eval_init): Register seq-begin, seq-next and seq-reset. * lib.c (seq_iter_s): New symbol variable. (seq_iter_mark): New static function. (seq_iter_ops): New static structure. (seq_begin, seq_next, seq_reset): New functions. (obj_init): Intern seq-iter symbol, used as class name for iterators. * lib.h (seq_iter_s, seq_begin, seq_next, seq_reset): Declared. * txr.1: Documented.
* doc: document division by zero.Kaz Kylheku2019-03-091-0/+17
| | | | | | * txr.1: Document that floor, mod, floor-rem and other functions in this family throw an exception if the divisor is zero.
* expt: handle negative integer exponents with integer bases.Kaz Kylheku2019-03-092-19/+66
| | | | | | | | | * arith.c (expt): The function overhauled. Raising integers to negative integers now works. Raising zero to a negative is diagnosed as a division by zero for operands of all kinds. * txr.1: Documentation updated for expt, and also division by zero error is documented for the / function.
* Version 213.txr-213Kaz Kylheku2019-03-087-759/+811
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* defset: eliminate the get-form argument.Kaz Kylheku2019-03-082-64/+79
| | | | | | | | | | | | | * share/txr/stdlib/defset.tl (defset-expander): Drop getform argument. Obtain the arguments of the place in a variable called args, which is then explicitly destructured with tree-case to match the params list. Having all of the original arguments in args, we can work backwards to replace some of them with gensyms. The resulting gensym-ized list is used to generate the access call to the operator named by name. * txr.1: Update doc to get rid of get-form. Updated and corrected the long form example.
* structs: fix missing lnew operator.Kaz Kylheku2019-03-081-2/+2
| | | | | | | | | * lisplib.c (struct_set_entries): Add missing entry for lnew in the name array. This is not just a missing auto-load issue. Because we don't intern the symbol, struct.tl ends up defining a sys:lnew macro, and not usr:lnew. The symbol usr:lnew doesn't exist and so when application code tries to use lnew, it's trying to invoke pub:lnew.
* defset: support improper list places.Kaz Kylheku2019-03-082-6/+22
| | | | | | | | | | | * share/txr/stdlib/defset.tl (defset-expander): Check for restpar being an atom and handle differently. We still don't handle the case where (b . c) is matched against a rest parameter; in this case the mapcar will process an improper list. I.e. the improper form must have an atom which matches the position of the rest parameter. * txr.1: Updated.
* defset: support parameter macros.Kaz Kylheku2019-03-082-15/+50
| | | | | | | | | | | * defset.tl (defset-expander): Add logic to expand parameter list to determine additional paramters that may come out of the expansion, as well as additional symbols that may be visible as a result as a result of processing in the expanded body. These symbols are included in the same way as original the original parameters. * txr.1: Documented defset's support for parameter list macros.
* expander: tree-bind: fix incorrect param env.Kaz Kylheku2019-03-081-2/+2
| | | | | | | | | | | | * eval.c (do_expand): A wrong thing is being done here: the macro is extended using the original parameter syntax, that has not been processed by expand_params. The body is then expanded using that environment. This subtly breaks support for parameter macros in tree-bind. They work, but there are spurious warnings about undefined variables during expansion, and the wrong scope handling can introduce bugs. The right thing is to derive new_menv by pulling the parameter symbols from params_ex.
* New macro: defset.Kaz Kylheku2019-03-064-2/+380
| | | | | | | | | | | | | | * lisplib.c (defset_instantiate, defset_set_entries): New static functions. (lisplib_init): Register auto-load of defset.tl, keyed on defset symbol. * share/txr/stdlib/defset.tl: New file. * share/txr/stdlib/paramt.tl (param-parser-base opt-syms): New method. * txr.1: Documented.
* doc: justify lack of seed keyword in hash construction.Kaz Kylheku2019-03-051-0/+8
| | | | | | * txr.1: The hash function doesn't support a keyword like :seed <n> to specify the hash seed. Adding an explanation of why. Spoiler: security reason.
* doc: fix too-wide make-hash syntaxKaz Kylheku2019-03-051-1/+2
| | | | | * txr.1: Fold make-hash over two lines to avoid 80 col overflow under man.
* lambda expressions aren't fboundp.Kaz Kylheku2019-03-031-5/+11
| | | | | | | | | | | | | | | | | | We don't want (fboundp '(lambda ...)) to be true, or (symbol-function '(lambda ...)) to yield a function. This also fixes funny print formatting of lambda expressions. * eval.c (lookup_fun): Do not recognize lambda expressions. Also, return nil for unknown syntax; don't bother looking it up in the hashes. (do_eval): We now have to check for a lambda expression in the car position to evaluate it; lookup_fun will no longer do that. (op_fun): The interpreted fun oprator must also check for lambda itself. (do_expand): A small code change is required here to avoid spuriously warning about a lambda in the car position.
* Fix use of comma operator as statement terminator.Kaz Kylheku2019-03-031-2/+2
| | | | | | * eval.c (fmakunbound, mmakunbound): Replace comma operator with statement terminator, an unintentional stylistic oddness. No behavior change.
* compiler: use new load-for.Kaz Kylheku2019-03-021-2/+1
| | | | | * share/txr/stdlib/compiler.tl: use load-for macro to load the param module.
* New macro: load-for.Kaz Kylheku2019-03-022-0/+184
| | | | | | | | | * eval.c (me_load_for): New function. (rt_load_for): New static function. (eval_init): Register load-for macro and sys:rt-load-for intrinsic function. * txr.1: Documented.
* eval: introduce variable for usr:var symbol.Kaz Kylheku2019-03-021-1/+2
| | | | | | * eval.c (usr_var_c): New symbol variable. The existing var_s hold sys:var, not usr:var. (eval_init): var symbol interned in usr package.
* ffi, eval: move struct_s.Kaz Kylheku2019-03-023-4/+4
| | | | | | | | | | * eval.c (struct_s): Now defined here. (eval_init): struct now interned here. * eval.h (struct_s): Declared. * ffi.c (struct_s): Definition removed. (ffi_init) struct no longer interned here.
* listener: return value regression.Kaz Kylheku2019-03-011-2/+2
| | | | | * parser.c (lino_getl, lino_gets): Return null pointer on EOF, restoring original behavior that was broken by recent patches.
* listener: fix buffer overflow loading overlong history line.Kaz Kylheku2019-03-011-6/+1
| | | | | * parser.c (lino_getl): Same fixes that were applied two weeks ago to lino_gets in commit b76c5760. Always check for copy and paste!
* compiler: fix (fun (lambda ...)).Kaz Kylheku2019-02-281-4/+8
| | | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-fun): Recognize a lambda expression argument. The neglect to do this is causing a miscompilation of (fun (lambda ...)) to a single getf instruction that processes raw syntax at run time and yields an interpreted lambda.
* compiler: fix broken inline lambda.Kaz Kylheku2019-02-281-6/+9
| | | | | | | | | | | | | | * share/txr/stdlib/compiler.tl (lambda-apply-transform): Fix failure to bind the additional expresions to the rest variable, causing a too many arguments error to be reported. That is ((lambda (. x)) 1) would fail to compile. When binding the trailing fixed arguments to rest, we also pull in the apply list; this matches interpreted behavior, for instance ((lambda (a . b) (list a b)) 1 2 . 3) must return (1 (2 . 3)). In this case, the 3 comes into this function as (3) via the apply-list-expr argument; if we don't include that and bind only the remaining fix-args, then we get the output (1 (2)).
* compiler: fix (apply (fun (lambda ..))).Kaz Kylheku2019-02-281-1/+1
| | | | | | | * share/txr/stdlib/compiler.tl (compiler comp-fun-form): Fix an instance of sym not being unquoted into the quasiquote template, causing the compiler to compile a call to the nonexistent function called sym.
* compiler: move parameter parsing to separate file.Kaz Kylheku2019-02-282-38/+68
| | | | | | | | | | Some upcoming work is going to use these structures. * share/txr/stdlib/compiler.tl (param-parser-base fun-param-parser, mac-param-parser): These struct definitions move to param.tl. * share/txr/stdlib/param.tl: New file.
* asm: getlx, setlx: disassembler bug.Kaz Kylheku2019-02-271-2/+2
| | | | | * share/txr/stdlib/asm.tl (op-getlx dis, op-setlx dis): Decode the small operand destination field correctly as such.