summaryrefslogtreecommitdiffstats
path: root/share
Commit message (Collapse)AuthorAgeFilesLines
* Version 157.txr-157Kaz Kylheku2016-11-141-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Fix spectacular bug in number of syntactic places.Kaz Kylheku2016-11-131-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Test case: (symacrolet ((f g)) (set [f x] y)) fails to expand. The root cause is that f is not expanded, because a nil environment is passed down to with-update-expander macro. This problem affects not only the dwim place, but nthcdr, sub and others. This bug was surprising at first because the Awk macro establishes the field array f via symbol macro. But assignments like (set [f 0] ...) worked! The thing is, they only worked by fluke due to the way expansions are handled in the Awk macro. That fluke came to an end in the November 4 commit 157fd76ee20125f409929b95b768b931268b43cf, just before 156 was released. The changes there don't cause this problem, but they remove the circumstances which protect the awk macro from the problem. So yes, that commit effectively caused another regression in 156: assignment to awk fields not working. * share/txr/stdlib/place.tl (nthcdr, nthlast, ref, sub, dwim): Do not pass an environment value of nil to with-update-expander! Pass the value of the special variable sys:*pl-env* which is there exactly for this purpose: to give to place expanders like these the original macro environment where the form occurs, so they can expand embedded places.
* New functions for command or file I/O in one call.Kaz Kylheku2016-11-131-0/+83
| | | | | | | | | | | | | | | | * lisplib.c (getput_set_entries, getput_instantiate): New static functions. (dlt_register): Register auto-loading for getput module via new functions. * share/txr/stdlib/getput.tl: New file. * txr.1: Documented new functions file-get, file-put, file-append, file-get-string, file-put-string, file-append-string, file-get-lines, file-put-lines, file-append-lines, command-get, command-put, command-get-string, command-put-string, command-get-lines, and command-put-lines.
* New :use-from clause in defpackage.Kaz Kylheku2016-11-111-1/+23
| | | | | | | | * share/txr/stdlib/package.tl (defpackage): Implemented new :use-from clause. * txr.1: Documented :use-from and made some improvements to the defpackage documentation.
* Add defpackage macro.Kaz Kylheku2016-11-111-0/+61
| | | | | | | | | | | * lisplib.c (package_set_entries, package_instantiate): New static functions. (lisplib_init): Register auto-loading for new package.tl file using new functions. * share/txr/stdlib/package.tl: New file. * txr.1: Documented.
* Fix regression: infinite loop in place expansion.Kaz Kylheku2016-11-061-4/+6
| | | | | | | | | | | | This shows up when the anaphoric ifa is used. Test case: | (ifa (f a) | (set it (g it))) * share/txr/stdlib/place.tl (sys:pl-expand): In the origin chasing loop, use a stack to more thoroughly detect a cycle.
* Version 156.txr-156Kaz Kylheku2016-11-051-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Fix broken tracking of place expansion origins.Kaz Kylheku2016-11-041-14/+22
| | | | | | | | | | | | | | | | | | | | | | | | | This change actually achieves the original intent that forms generated by place expansion register the place as their macro-expansion origin, enabling clearer diagnostics when things go wrong in that generated code. * share/txr/stdlib/place.tl (sys:cp-origin): Drop the syms argument; it's useless because we want to walk over the fully expanded to-tree in which those syms (denoting the names of local macros) will no longer appear. Now instead we find any conses in to-tree which already have macro ancestors. We trace the ancestor chain to the end and install the place form as the grand-ancestor, to express that all the expansion ultimately is derived from the place that is being manipulated. (call-update-expander, call-clobber-expander, call-delete-expander): After calling the expander, fully expand whatever it returns in the given environment. Then, propagate place as the macro origin throughout the forms contained in the expansion before returning it.
* Support simple list arguments in getopts.Kaz Kylheku2016-11-031-9/+26
| | | | | | | | | | | | | | | | | * share/txr/stdlib/getopts.tl (defstruct sys:opt-parsed): New slot eff-type, appearing as an optional parameter in the boa constructor parameter list. (opt-desc check): Allow a type to be a cons with list in the car position. (sys:opt-parsed convert-type): Use the eff-type slot if it is set instead of the type from the descriptor. This lets us override the type for a slot, which is key to the recursive approach to how lists are handled in this same function. (opthelp): Show list type options in a visual way which suggests the use. No details are given. * txr.1: Documented list option type.
* Introducing command line option processing system.Kaz Kylheku2016-11-031-0/+320
| | | | | | | | | | | * lisplib.c (getopts_set_entries, getopts_instantiate): New functions. (lisplib_init): Register auto-loading for getopt.tl via new functions. * share/txr/stdlib/getopts.tl: New file. * txr.1: Documented new library area.
* Relax restrictions on dwim places.Kaz Kylheku2016-10-311-22/+54
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | No longer require the leftmost expression in a dwim place to itself be a place, except when the expression evaluates to a list, and the list is subject to an element deletion or a range operation. * eval.c (eval_init): Register dwim-set and dwim-del with one additional argument that the C functions now take. * lib.c (dwim_set, dwim_del): Take a new place_p argument which informs these functions whether the object they are operating on came from a syntactic place. The forbidden situations are diagnosed based on this flag: modification of the subrange of a list, or deletion of a list ref. Some error messages reworded. * lib.h (dwim_set, dwim_del): Declarations updated. * share/txr/stdlib/place.tl (defplace dwim): Produce a different update, clobber and delete expansion when the obj-place form isn't a place. In the non-place case, do not assign the result of the sys:dwim-set or sys:dwim-del operation back obj-place. Furthermore, pass a Boolean flag to sys:dwim-set and sys:dwim-del indicating which situation is the case: did the object argument come from a place or non-place. * txr.1: Documentation updated.
* lambda-set method: treat [struct ...] as place.Kaz Kylheku2016-10-301-32/+24
| | | | | | | | | | | | | | | | | | | | | | | | * eval.c (eval_init): Change registration of dwim-set to only one required argument, with the rest variadic. * lib.c (lambda_set_s): New symbol variable. (dwim_set): Change to variadic function that takes all arguments other than the object/sequence being operated on as struct args *. Rewrite to do a test on the object type first, handling hashes and structs specially. (obj_init): Initialize lambda_set_s. * share/txr/stdlib/place.tl (defplace dwim): Rewritten for more generic syntax. The only argument required is obj-place; the other arguments are treated as a variable argument list, all treated uniformly. This eliminates the special handling of the default value for hash lookups. * args.h (args_count): New inline function. * txr.1: Updated documentation for dwim operator, which neglects to mention use over objects thanks to the lambda function. Documented lambda-set.
* Extend symbol-function accessor to methods.Kaz Kylheku2016-10-291-7/+17
| | | | | | | | | | | | | | | | | | * eval.c (looup_fun): Handle (meth ...) syntax. * share/txr/stdlib/place.tl (sys:get-fb): Function removed. (sys:get-fun-getter-setter): New function. (defplace symbol-function): Rework getter and setter using new function which works for method as well as regular function bindings. * txr.1: Documentation updated in several places. The mention of symbol-function in the list of place forms altered so it doesn't insinuate that the argument must be a symbol. Description of symbol-function updated. Also under the trace and untrace macros, a note added that tracing methods is possible.
* Adding function tracing support.Kaz Kylheku2016-10-291-0/+50
| | | | | | | | | | | | | New variable *trace-output*, and macros trace and untrace. * lisplib.c (trace_set_entries, trace_instantiate): new static functions. (dlt_register): Register new functions to auto-load trace module. * share/txr/stdlib/trace.tl: New file. * txr.1: Documented.
* New awk capability: file/pipe I/O redirection.Kaz Kylheku2016-10-281-2/+42
| | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slot, streams. Holds hash table of open streams. New :fini finalizer which closes all streams. (sys:awk-state ensure-stream, sys:awk-state close-or-flush): New methods. (sys:awk-redir): New macro. (sys:awk-let): Bind new local macros ->, ->>, <-, !> and !<. (awk): Call finalizers on awk state to get all streams to close. * txr.1: Document new awk macros.
* dwim place: multiple accesses, eval order.Kaz Kylheku2016-10-271-19/+18
| | | | | | | | | | | | | * share/txr/stdlib/place.tl (defplace dwim): In updater, removing unused and redundant gensyms. Engaging unused oldval-sym as a temporary to hold the result of invoking (,ogetter-sym), the "getter" for the sequence object place we are operating on. Both references then refer to this resut instead of expanding the getter twice. Though getters should not have side effects, they could be expensive. In simple setter and deleter, setting up obj-sym similarly. We don't make multiple accesses to the sequence, but we were evaluating it in the wrong order w.r.t the index and new-val.
* Fix unbound variable in seq place update.Kaz Kylheku2016-10-261-2/+2
| | | | | | * share/txr/stdlib/place.tl (defplace sub): Fix unbound variable seq-setter in update expander. Wrong unquoting level.
* Improve alet macro.Kaz Kylheku2016-10-261-8/+10
| | | | | | | | | | | | | | | | | | | | | | | The alet macro should always convert bindings to constants into symbol macros; the all-or-nothing logic should be applied to any remaining bindings. * share/txr/stdlib/place.tl (sys:r-s-let-expander): Generalize this function somewhat more by passing in the fallback binding symbol to use for bindings that can't be turned into symbol macros, instead of hard-coding them to let. (rlset, slet): Specify 'let when calling sys:r-s-let-expander. (alet): If there are any bindings with constantp init expressions, then recurse: produce an expansion which separates constantp from non-constantp using sys:r-s-let-expander. Pass 'alet as fallback binding symbol; thus the expansion will recurse back to alet, but without all the constantp bindings, if there are any. We then deal with those using the existing all-or-nothing logic (which simplifies slightly since it doesn't have to check for constantp any more). * txr.1: Revised description of alet.
* last, butlast: become accessors, get optional arg.Kaz Kylheku2016-10-261-0/+20
| | | | | | | | | | | | | | | | | | | | * eval.c (optimize_qquote_form): Pass nil to default new argument of butlast. (me_whilet, me_iflet_whenlet): Likewise for last. (eval_init): Add optional argument to registration of last and butlast intrinsics. * lib.c (last, butlast): Support optional numeric argument, like in Common Lisp. * lib.h (last, butlast): Declarations updated. * share/txr/stdlib/place.tl (last, butlast): New place macros. * txr.1: Updated documentation. The description of last is now moved into the sequence functions section.
* sub function becomes accessor.Kaz Kylheku2016-10-261-0/+39
| | | | | | * share/txr/stdlib/place.tl (defplace sub): New place. * txr.1: Document sub as accessor.
* New accessors nthlast and butlastn.Kaz Kylheku2016-10-251-0/+39
| | | | | | | | | | | | | | * eval.c (eval_init): register nthlast and butlastn intrinsicis. * lib.c (nthlast, butlastn): New function. * lib.h (nthlast, butlastn): Declared. * share/txr/stdlib/place.tl (defplace nthlast, defplace butlastn): New places. * txr.1: Documented nthlast and butlastn.
* nthcdr place bugfix: wrong return value.Kaz Kylheku2016-10-251-1/+1
| | | | | | * share/txr/stdlib/place.tl (defplace nthcdr): In the case when list is a place, the setter operation returns the wrong value: the entire list, rather than the value assigned.
* Version 155.txr-155Kaz Kylheku2016-10-211-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Fix struct lit problem exposed by circular syntax.Kaz Kylheku2016-10-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The semantics of how struct literals come to life is poorly designed: namely, the slot-value pairs in the struct literal are used as the plist argument in a call to make-struct. This is wrong because the implied initializations are then clobbered by the structure type's :init and :postinit handlers, resulting in an object with slot values that don't match what is in the literal. When you add circular syntax to the mix, things get worse. Slots may be initialized with (sys:circ-ref ...) expressions corresponding to #<n># syntax. These expressions then get clobbered by the constructor actions before the circ_backpatch processes the syntax. * parser.y (struct): Use make_struct_lit rather than make_struct to instantiate struct object. * struct.tl (sys:struct-lit): Expand to a form which calls sys:make-struct-lit, rather than make-struct. * struct.c (struct_init): Register new make_struct_lit function as sys:make-struct-lit intrinsic. (make_struct_lit): New function. * struct.h (make_struct_lit): Declared. * tests/012/struct.tl: struct literal expansion test case updated. * txr.1: Updated documentation of struct literals. Added compat notes.
* Cycle detection in sys:cp-origin.Kaz Kylheku2016-10-191-9/+13
| | | | | | | | | | | | | | | Tree-walking code in the place expander runs into trouble if the expression contains cycles. Test case: (defparm a '(#1=(a . #1#))). * share/txr/stdlib/place.tl (sys:cp-origin): Take list of symbols as a single argument instead of trailing arguments. Support an optional argument that gives serves as a cycle-detecting stack. Bail if a cycle is detected. (call-udpate-expander, call-clobber-expander, call-delete-expander): Update sys:cp-origin calls to follow interface change.
* Bugfix: unable to assign to x.y.z place.Kaz Kylheku2016-10-151-4/+1
| | | | | | | | | | | | | | | | | | | This regression was caused by commit 957f80f "Bugfix: issue with expansion of place macros" on Sep 7, 2016. The commit itself is sound, but exposes a hidden problem in nearby code. * share/txr/stdlib/place.tl (sys:pl-expand): The conditions for terminating the loop and returning the expansion are too weak, due to the inclusion of an incorrect test. We must not bail when the expansion of a compound form is a compound form with the same symbol. This is because some macros behave that way, such as, oh: qref! The expansion of (qref a b c) is (qref (slot a 'b) 'c): another qref form. To fully expand, we must keep iterating until the returned form is eq to the input form. The original macroexpand (which was replaced by macroexpand-1 in 957f80f) hid this problem because macroexpand doesn't use this broken termination test.
* Version 154.txr-154Kaz Kylheku2016-10-151-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* Adding family slot to socket addresses.Kaz Kylheku2016-10-131-4/+8
| | | | | | | | | | | | | | | A static slot indicating the address family simplifies code which wants to map a socket address to its family. * lisplib.c (sock_instantiate): Call sock_load_init before loading socket.tl rather than after, because socket.tl now references variables defined inside sock_load_init. * share/txr/stdlib/socket.tl (sockaddr, sockaddr-in, sockaddr-in6, sockaddr-un): New static slot, family. * txr.1: Documented family slots.
* New accessor: hash-userdata.Kaz Kylheku2016-10-121-0/+12
| | | | | | | | | | | | | | The get-hash-userdata function is now deprecated in favor of hash-userdata, which is an accessor. * hash.c (hash_init): Register hash-userdata as a synonym for the same function as get-hash-userdata. * share/txr/stdlib/place.tl (hash-userdata): New defplace. * txr.1: Document new accessor, marking get-hash-userdata as a deprecated synonym. Replace references to get-hash-userdata with references to hash-userdata.
* Support curried args in method and meth.Kaz Kylheku2016-10-091-2/+2
| | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (meth): Take trailing arguments and pass them down to method, which now accepts them. * struct.c (struct_init): Register method intrinsic to the function method_args instead of the method function. (method_args_fun): New static function. (method_args): New function. Behaves like method function if args is empty, otherwise creates a function by means of method_args_fun. * struct.h (method_args_fun): Declared. * tests/012/oop.tl: New test case. * tests/012/oop.expected: Updated. * txr.1: Documented new features in method and meth, revising the documentation in the process.
* Support curried arguments in umethod and umeth.Kaz Kylheku2016-10-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | * share/txr/stdlib/struct.tl (umeth): accept variadic arguments. Evaluate them using the dwim brackets and pass to umethod. The (fun umethod) trick is used to refer to the umethod in the function namespace even if it is shadowed by a variable. * struct.c (struct_init): Update registration of umethod to reflect its new variadic argument signature. (umethod_args_fun): New static function. (umethod): Return a function based on umethod_fun, as before, if there are no variadic args. Otherwise, use umethod_args_fun which deals with them. * struct.h (umethod): Declaration updated. * tests/012/oop.tl: Modest testcase for umeth with curried argument. * tests/012/oop.expected: Updated. * txr.1: Updated documentation of umeth and umethod.
* Version 153.txr-153Kaz Kylheku2016-10-071-1/+1
| | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise.
* Version 152.txr-152Kaz Kylheku2016-10-041-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* New awk clauses :set and :set-file.Kaz Kylheku2016-10-041-0/+2
| | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-expander): Recognize :set and :set-file cases. * txr.1: Documented :set and :set-file, replacing some :begin uses with :set in the examples.
* Synchronize license comments with LICENSE.Kaz Kylheku2016-10-0117-272/+289
| | | | | | | | | | | | | | | | | | | | * Makefile, args.c, args.h, arith.c, arith.h, cadr.c, cadr.h, combi.c, combi.h, configure, debug.c, debug.h, eval.c, eval.h, filter.c, filter.h, ftw.c, ftw.h, gc.c, gc.h, glob.c, glob.h, hash.c, hash.h, jmp.S, lib.c, lib.h, lisplib.c, lisplib.h, match.c, match.h, parser.c, parser.h, parser.l, parser.y, rand.c, rand.h, regex.c, regex.h, share/txr/stdlib/awk.tl, share/txr/stdlib/build.tl, share/txr/stdlib/cadr.tl, share/txr/stdlib/conv.tl, share/txr/stdlib/except.tl, share/txr/stdlib/hash.tl, share/txr/stdlib/ifa.tl, share/txr/stdlib/path-test.tl, share/txr/stdlib/place.tl, share/txr/stdlib/socket.tl, share/txr/stdlib/struct.tl, share/txr/stdlib/termios.tl, share/txr/stdlib/txr-case.tl, share/txr/stdlib/type.tl, share/txr/stdlib/with-resources.tl, share/txr/stdlib/with-stream.tl, share/txr/stdlib/yield.tl, signal.c, signal.h, socket.c, socket.h, stream.c, stream.h, struct.c, struct.h, sysif.c, sysif.h, syslog.c, syslog.h, termios.c, termios.h, txr.1, txr.c, txr.h, unwind.c, unwind.h, utf8.c, utf8.h: Revert to verbatim 2-Clause BSD.
* Revision of static slot inheritance.Kaz Kylheku2016-09-301-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixing the broken static slot handling in TXR Lisp's "OOP structs" object system. Inherited static slots are now shared with the base type; only static slots explicitly defined in a derived type have a distinct global instance in that type. * share/txr/stdlib/struct.tl (sys:prune-nil-inits): Function removed. (sys:prune-missing-inits): New function. We now handle static slot forms with missing inits specially, not those with nil or missing inits. (defstruct): Translate a (word name) form to (word name) rather than (word name nil) if word is :static, because we need this nuance for non-shared static slots, so they can inherit the value from the base struct. For the purposes of generating the static init function, prune away all the static slot forms that do not have an initializer; we let those default. * struct.c (struct stslot): New struct for representing a static slot. (stslot_loc, stslot_place): New macros. (struct struct_type): Member eqmslot changes to a pointer to a struct stslot. The stslot dynamic array is no longer an array of val, but an array of stslot structs. (call_stinitfun_chain): The superclass chain of static init functions is now called only in compatibility mode. Otherwise only the type's own static init fun is called, which defclass uses to initialize just the new or repeated static slots. Inherited static slots are completely left alone; they do not require initialization. (static_slot_home_fixup): New static function; needed to fix some internal pointers within the static slot arrays if they are realloc'ed. (make_struct_type): Considerably revised to implement new scheme, while providing backward compatibility switching. New slots live in the struct stslot in which they are allocated. Inherited slots have home pointers to within the array in the base. (struct_type_mark): When walking the static slots, mark only the store cells of those which live in this array. Those that live elsewhere should have store cells that are nil; let's assert on it. (lookup_slot): Static slot lookup code has to retrieve slots in the new way, indirecting through the home pointer, which is hidden behind the stslot_loc macro. (lookup_static_slot_desc): New function, like lookup_static_slot, but returning a pointer to the struct stslot. Formed from the guts of lookup_static_slot. (lookup_static_slot): Gutted and turned into a wrappar around lookup_static_slot_desc. (static_slot_set): Simple change here: add cast because of the pointer type of eqmslot. (static_slot_home_fixup_rec): New static function. Fixes up the cached home in slot arrays in an entire type hierarchy rooted at a given type, which has to be done when its static slot has been reallocated, so all those inherited static slot pointers in the derived types are invalid. (static_slot_rewrite_rec): New static function: rewrites a particular inherited static slot in an inheritance hierarchy to point to a different slot. (static_slot_ens_rec): New static function: factored out recursive logic of static_slot_ensure. Substantially rewritten to handle new static slot scheme, plus support backward compatibility. There is a bug fixed here: if an instance slot is encountered in the no_error_p mode, it looks like we were dereferencing through an invalid ptr through the set(ptr, newval) line. (static_slot_ensure): A wrapper now for static_slot_ens_rec. (get_equal_method): Rework the logic related to the eqmslot member of the struct_type structure, in terms of it being a pointer now rather than an integer. The value -1 cast to a pointer serves the previous -1 sentinel value which indicates that it is confirmed (for the time being) that this type doesn't have an equal method. * txr.1: All documentation related to static slots updated, and compatibility notes added. * tests/012/oop.tl, tests/012/oop.expected: New files.
* Version 151.txr-151Kaz Kylheku2016-09-271-1/+1
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* awk macro: code formatting.Kaz Kylheku2016-09-251-4/+4
| | | | | * share/txr/stdlib/awk.tl (awk): Fix indentation in two places.
* awk macro: proper fs semantics in paragraph mode.Kaz Kylheku2016-09-251-13/+27
| | | | | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slots: par-mode, par-mode-fs, par-mode-prev-fs. (sys:awk-state rec-to-f): In paragraph mode, detect that fs has changed since the last call. In that case, take the user's fs and add to it a newline match. If it is a regex, take the source, add the syntax and recompile the regex. If it's a string, build regex around it and compile. (sys:awk-state loop): Maintain the par-mode-t variable in the state structure as the rs value triggers transitions into or out of paragraph mode. * txr.1: Updated documentation for rs.
* awk macro: support paragraph mode.Kaz Kylheku2016-09-251-9/+22
| | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): If the rs variable is nil, provide a record reader which reads paragraphs, like under Awk's paragraph mode when RS is blank. This does not support the requirement that newline is always a field separator, regardless of the value of FS. * txr.1: Documented paragraph mode.
* awk macro: loop uses closure to read records.Kaz Kylheku2016-09-251-23/+27
| | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state loop): Refactor code so that record-processing loop obtains a lambda which is called to extract a record. If rs and krs did not change, then the same lambda is obtained from a variable which caches it. The get-rec-reader local function thus encapsulates the whole record delimiting strategy as well as changes to the variables. With this structure, it will be relatively easy to add support for Awk's paragraph mode, which is notably missing in the implementation.
* awk macro: handle dynamic changes in rs variable.Kaz Kylheku2016-09-251-20/+28
| | | | | | | | * awk.tl (sys:awk-state loop): The loop now notices when rs or krs changes and switches to a new record-adapter or to the raw stream as necessary. * txr.1: Notes added about changes to rs and krs.
* awk macro: add orec variable.Kaz Kylheku2016-09-241-2/+4
| | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-state): New slot, orig-rec. (sys:awk-state loop): Initialize orig-rec after reading each record. (sys:awk-let): Provide orec symbol macro. * txr.1: Document orec variable.
* awk macro: use range test logic for clause conditions.Kaz Kylheku2016-09-241-4/+5
| | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:range-test): Function renamed to sys:awk-test, since it's not just for ranges. (sys:awk-let): Uses of sys:range-test follow rename. sys:awk-test introduced into expansion of cond parts of cond-action clauses. * txr.1: Documented new behavior (conditions can produce a function or regex, which is implicitly invoked on rec).
* awk macro: exit if no cond-action clauses.Kaz Kylheku2016-09-241-12/+14
| | | | | | | | * share/txr/stdlib/awk.tl: If there are no cond-action clauses in the macro, do not generate the main record processing lambda, or the begin-file and end-file lambdas, and do not generate the call to the awk state object's loop method.
* awk macro: fconv conversions iz, xz, oz, bz and rz.Kaz Kylheku2016-09-241-1/+11
| | | | | | | * share/txr/stdlib/conv.tl (sys:conv-let): New flets iz, oz, xz, bz and rz. * txr.1: Documented under fconv.
* awk macro: support regexes better in ranges.Kaz Kylheku2016-09-231-4/+14
| | | | | | | | | | | | | | | | | | | * share/txr/stdlib/awk.tl (sys:awk-compile-time): New slot, rng-rec-temp. Specifies the name of a temporary variable which is scoped over the evaluation of ranges, and which caches a reference to the current record string. (sys:range-test): New function. (awk:let): Rename the original rng macrolet to sys:rng, and introduce rng as a wrapper around it which inserts the logic for calling the regex or function that might emerge from the evaluation of from-expr or to-expr. (awk): If ranges are present in the syntax, then bind the temporary variable which caches the record around the evaluations of the ranges. * txr.1: Document new special behavior of rng w.r.t functions and regexes. Add admonition against modifying rec and some other awk variables from range expressions.
* Use rlet in a few place macros for better code.Kaz Kylheku2016-09-211-3/+3
| | | | | | * share/txr/stdlib/place.tl (pset, push, pushnew): Use rlet for binding the assigned or pushed value to a temporary, so the temporary can disappear if the value is a constant.
* Fix broken sys:rslot place.Kaz Kylheku2016-09-211-4/+4
| | | | | | | | | | | | This is used in the awk macro. Breaking test case is an update modification of f, like (push 3 f); a broken call to sys:rslotset is generated with a too few arguments. * share/txr/stdlib/struct.tl (defplace sys:rslot): Fix name clash between gensym and parameter. Add the meth-slot-sym parameter into the sys:rslotset call where it is missing as a required parameter.
* awk macro: streamline field splitting.Kaz Kylheku2016-09-211-13/+7
| | | | | | | | | * share/txr/awk.tl (sys:awk-state rec-to-f): Check for empty record only in the fs case; it's not necessary when tokenizing with ft. Check (not self.kfs) first, since it's the common case. Handle default case (no fs or ft) using tok-str using the regex #/[^ \t\n]+/, which requires no trim-str and no empty record check.