summaryrefslogtreecommitdiffstats
path: root/txr.1
Commit message (Collapse)AuthorAgeFilesLines
* doc: document :eq-based.Kaz Kylheku2019-10-111-12/+17
| | | | | | * txr.1: the :eq-based keyword and its semantics is documented, along with its mutual exclusion against the other two.
* op: new features for anonymous recursion.Kaz Kylheku2019-10-031-20/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | Within the op syntax, the new implicit variable @rec now refers to the function itself. There is also @(rec ...) for calling the function through a function binding. For instance, here is Fibonacci: (do if (> @1 1) (+ @(rec (pred @1)) @(rec (ppred @1))) 1) * share/txr/stdlib/op.tl (sys:op-ctx): New slots rec and recvar. (sys:op-rec-p, sys:op-ensure-rec): New functions. (sys:op-alpha-rename): Check for the new syntaxes and translate to appropriate gensymed expressions, while updating the context structure, so the expander is informed about the @rec or @(rec ...) activity in the expression. (sys:op-expand): Check whether @rec or @(rec ...) has been used in the expression, and generate the necessary variants to support it. We need to bind the lambda to a recursive binding using the same mechanism that labels uses, and possibly to bind the gensym underneat @rec to the value of that function binding. * txr.1: op documentation extended to cover the new feature, plus some wording improvements.
* symbol-function: support lambda expressions.Kaz Kylheku2019-09-271-6/+24
| | | | | | | | | | | | | | | | | * eval.c (lookup_fun): Check for a lambda expression and return a faked binding containing the interpreted function. (do_eval, op_fun): Remove checks for lambda that are now being done in lookup_fun. In many other places where lookup_fun is used, we still need lambda checks, like in the expander. * share/txr/stdlib/place.tl (sys:get-fun-getter-setter): Take form argument. Diagnose assignments to lambda, and to unknown function place syntax. (defplace symbol-function): Pass sys:*pl-form* to sys:get-fun-getter-setter as form argument. * txr.1: fboundp and symbol-function doc updated.
* buffers: allow inequality comparison with less.Kaz Kylheku2019-09-201-3/+7
| | | | | | | | * lib.c (less_tab_init): Assign category 6 to BUF type, so buffers are sorted after other types. (less): Add BUF case. * txr.1: Documented.
* doc: eval-only: article agreement.Kaz Kylheku2019-09-201-1/+1
| | | | * txr.1: Fix "a eval-only" in definition of top-level form.
* Version 225.txr-225Kaz Kylheku2019-09-111-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* list-builder: rewrite of basic methods.Kaz Kylheku2019-09-091-11/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rewriting be addition, pending and nconcing methods of list-builder to avoid loops and rely on lower list processing functions. This cleans up the semantics and error messages. Some examples of behavioral changes: (build (pend "abc") (add #\d)) now returns "abcd", consistent with (append "abc" '(#\d)). Previously it returned '(#\d). (build (add 1) (pend 2) (pend 3)) now produces a "cannot append to 2" error. Previously it produced "copy: cannot copy object of type fixnum". * share/txr/stdlib/build.tl (list-builder add): Don't use copy-list; rather the idiom for copying a sequence in preparation for appending to it is (append x nil). This will blow up nicely if x is an atom other than nil. We use this trick twice. (list-builder add*): Simplify with append. (pend, pend*, ncon): Rewrite. (ncon*): Use nconc once on a combined argument list: this is borrowed from the rewritten pend*. * txr.1: Documentation updated with clarifications, particularly in the area of the requirements regarding destructive manipulation and substructure sharing.
* subtypep: structs with car or length method are sequences.Kaz Kylheku2019-09-061-0/+2
| | | | | | | | | | | | | * lib.c (subtypep): For the sequence supertype, check whether the subtype is a structure that has a length or car method, returning t if so. * struct.c (get_special_slot_by_type): New function. * struct.h (get_special_slot_by_type): Declared. * txr.1: Add <structures with cars or length methods> to the type hierarchy diagram.
* lib: access special methods via special slot mechanism.Kaz Kylheku2019-09-061-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * ffi.c (ffi_flex_struct_in): Use get_special_slot to obtain length method. * lib.c (nullify_s, from_list_s, lambda_set_s): Definitions removed from here. (seq_info, car, cdr, rplaca, rplacd, make_like, nullify, replace_obj, length, empty, sub, ref, refset, dwim_set): Use get_special_slot to obtain special method from object, rather than maybe_slot. (obj_init): Remove initializations of nullify_s, from_list_s and lambda_set_s from here. * struct.c (enum special_slot): Definition removed from here. (nullify_s, from_list_s, lambda_set_s): Definitions moved here from lib.c. (special_sym): New static array. (struct_init): Initializations of nullify_s, from_list_s and lambda_set_s moved here from lib.c. (get_special_slot): New function. * struct.h (lambda_set_s): Declared. (enum special_slot): Definition moved here. (get_special_slot): Declared. * txr.1: Added compat note, since get_special_slot behaves like maybe_slot under 224 compatibility.
* New function: tailp.Kaz Kylheku2019-09-031-0/+53
| | | | | | | | | | * eval.c (eval_init): Register tailp intrinsic. * lib.c (tailp): New function. * lib.h (tailp): Declared. * txr.1: Documented.
* doc: fixes from vapnik spaknik.Kaz Kylheku2019-09-031-43/+80
| | | | | | | | | | | | | TXR user vapnik spaknik has found a swath of errors in the documentation. * txr.1: Fixed bugs in numerous examples, copy-and-paste errors in syntax sections, and other typos, including *stdin* mistyped as *std-input* in many places. A new executable code example is provided for expand-with-free-refs to calculate the result that was previously only verbally described. Fixed *stdin* mistyped as *std-input* (a non-existent symbol that imitates the internal C variable).
* doc: hyphenation of some compound words.Kaz Kylheku2019-09-031-4/+4
| | | | * txr.1: Hyphenate "heap-allocated" and "stack-allocated".
* Version 224.txr-224Kaz Kylheku2019-08-291-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* sha256/md5: allow characters and byte values.Kaz Kylheku2019-08-291-4/+6
| | | | | | | | | * chksum.c (sha256_utf8_byte_callback, md5_utf8_byte_callback): New static functions. (sha256_hash, md5_hash): Support character and integer objects. * txr.1: Documented.
* New state-object-based sha256 and md5 digesting.Kaz Kylheku2019-08-231-0/+112
| | | | | | | | | | | | | | | * chksum.c (sha256_ctx_s, md5_ctx_s): New symbol variables. (sha256_ops, md5_ops): New static structs. (sha256_begin, sha256_hash, sha256_end, md5_begin, md5_hash, md5_end): New functions. (chksum_init): New symbol variables initialized; sha256-begin, sha256-hash, sha256-end, md5-begin, md5-hash, md5-end intrinsics registered. * chksum.h (sha256_begin, sha256_hash, sha256_end, md5_begin, md5_hash, md5_end): Declared. * txr.1: Documented.
* New: MD5 digest functions.Kaz Kylheku2019-08-231-8/+29
| | | | | | | | | | | | | | | | | * Makefile (OBJS): New object file, chksums/md5.o. * chksum.c (sha256_ensure_buf): Renamed to chksum_ensure_buf and made generic so MD5 code can borrow it. (sha256_stream, sha256): Call chksum_ensure_buf instead of sha256_ensure_buf, passing in new length and hash name parameters. (md5_stream_impl, md5_buf, md5_str): New static functions. (md5_stream, md5): New functions. (chksum_init): Register md5-stream and md5 intrinsics. * chksum.h (md5_stream, md5): Declared. * chksums/md5.c, chksums/md5.h: New files.
* New function: cptr-buf.Kaz Kylheku2019-08-211-2/+37
| | | | | | | | | | * eval.c (eval_init): Register cptr-buf intrinsic. * lib.c (cptr_buf): New function. * lib.h (cptr_buf): Declared. * txr.1: Documented.
* doc: note about cptr-obj lifetime.Kaz Kylheku2019-08-211-0/+12
| | | | | | * txr.1: Include blurb about the independent lifetime of a ctpr made by cptr-obj and the original object. If the original is garbage collected, the ctpr is junk.
* New function: intern-fb.Kaz Kylheku2019-08-201-2/+24
| | | | | | | | | | | | | | | To accompany find-symbol-fb, there is intern-fb, which is like intern, but searches the fallback list. * eval.c (eval_init): Register intern-fb intrinsic. * lib.c (intern_fallback_intrinsic): New function. Does defaulting and error checks, then calls intern_fallback, just like intern_intrinsic calls intern. * lib.h (intern_fallback_intrinsic): Declared. * txr.1: Documented.
* doc: mistake in intern arg description.Kaz Kylheku2019-08-201-2/+2
| | | | | * txr.1: name must be a string, not a symbol. The optional argument must be a package, if supplied.
* new functions: find-symbol and find-symbol-fb.Kaz Kylheku2019-08-191-0/+58
| | | | | | | | | | | | | | | | | | Turns out, there is already a find_symbol in lib.c, completely unused. * eval.c (eval_init): Register find-symbol and find-symbol-fb intrinsics. * lib.c (find_symbol): Fix this hitherto unused function to do correct defaulting of the package argument and, to accept an additional argument specifying the not-found value. (find_symbol_fb): New function. * lib.c (find_symbol): Declaration updated. (find_symbol_fb): Declared. * txr.1: Documented.
* doc: new buildn example.Kaz Kylheku2019-08-181-0/+15
| | | | | * txr.1: Adding breadth-first traversal example showing queue capability of the list-builder.
* list-builder: inserter methods return nil.Kaz Kylheku2019-08-171-17/+32
| | | | | | | | | * share/txr/stdlib/build.tl (list-builder): Methods add, add*, pend, pend*, ncon and ncon* return nil. * txr.1: Updated documentation to state that these methods return nil, rather than an unspecified return value. Improvements in build macro documentation.
* list-builder: dequeue capabilities with del/del* operators.Kaz Kylheku2019-08-171-7/+80
| | | | | | | | | | | | | | | * lisplib.c (build_set_entries): Add buildn for autload, and intern del and del* symbols. * share/txr/stdlib/build.tl (list-builder): New methods del and del*. (sys:list-builder-flets): Generate flet for del*. (sys:build-expander): New function, consisting of expansion logic previously in build function. Macrolet added for del. (build): Call sys:build-expander. (buildn): New macro. * txr.1: Documented.
* doc: expand on load-time.Kaz Kylheku2019-08-161-0/+52
| | | | | | * txr.1: Add discussion highlighting use of load-time for effect staging, rather than value. Add rationale regarding the naming difference from ANSI CL.
* compile-file: include load-time as top-level form.Kaz Kylheku2019-08-161-5/+18
| | | | | | | | | | | | * share/txr/stdlib/compiler.tl (usr:compile-file): recognize sys:load-time-lit as a top-level form and recurse through to compiling its constituent form. We check the flag whether the syntax had already been processed by the evaluator, though that currently cannot possibly happen for a form that has just been parsed from a file by compile-file itself. * txr.1: Defintion of top-level form (from compile-file POV) updated. Documentation of load-time updated.
* Version 223: ten years!txr-223Kaz Kylheku2019-08-141-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* @(collect): don't default vars if all required missing.Kaz Kylheku2019-08-121-26/+49
| | | | | | | | | | | | | | | | | | | | | | | | | The @(collect) directive disallows the situation when there are required vars, but some are missing (not bound by the collect body). However, the special case is allowed when none of the required variables are bound; that doesn't trigger the exception. There is a poor specification in this area: the issue is that when there are optional variables, and all variables are missing (optional and required), the optional ones are still bound to their default values. Thus, the situations is half-baked: some of the :vars are bound and some are not. This violates the all-or-nothing principle of :vars. This patch addresses the poor specification: if all variables are missing, then the optional variables are not bound to their defaults. * match.c (h_collect, h_coll): Detect the situation when at least one variable is required, and all optional variables are defaulted. In this case, don't propagate any bindings to the collected lists. * txr.1: Doc updated.
* base-name: optionally remove suffix.Kaz Kylheku2019-08-091-1/+12
| | | | | | | | | | | | | | | | The base-name function now takes a second argument which is optional, specifying a suffix to be removed. The behavior is similar to that of the second argument of the POSIX basename command. * stream.c (base_name): Second argument added. If present, the returned value is adjusted by trimming the suffix, unless that would cause an empty string to be returned. (stream_init): Update registration of base-name intrinsic. * stream.h (base_name): Declaration updated. * txr.1: New base-name parameter documented.
* Version 222.txr-222Kaz Kylheku2019-07-301-3/+3
| | | | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated. * protsym.c: Likewise.
* doc: update FFI struct/union description.Kaz Kylheku2019-07-301-6/+152
| | | | | | | * txr.1: Document existing gensym behavior of nil struct/union tags. Document new rules regarding structs/unions that have no members, redefinitions of complete and incomplete types, and semantics of self-reference.
* doc: fix wrapping save-exe exampleKaz Kylheku2019-07-291-1/+2
| | | | | | * txr.1: Use backslash escape in the save-exe example to break up long string literal, so it won't be wrapped by man at 80 columns.
* FFI: elemtype as type operator, not just macro.Kaz Kylheku2019-07-261-4/+30
| | | | | | | | * ffi.c (elemtype_s): New symbol variable. (ffi_type_compile): Handle elemtype. (ffi_init): Initialize elemtype_s. * txr.1: Document elemtype.
* FFI: document: elemsize and elemtype work on enums.Kaz Kylheku2019-07-261-8/+14
| | | | | | | | * ffi.c (ffi_elemsize, ffi_elemtype): Fix error messages to include enum among possible argument types. * txr.1: Extend documentation for ffi-elemsize and ffi-elemtype to include base integer type of enumerations.
* FFI: allow member type reference using referencing dot.Kaz Kylheku2019-07-261-0/+43
| | | | | | * ffi.c (ffi_type_compile): New case handling qref_s symbol. * txr.1: Documented.
* Version 221.txr-221Kaz Kylheku2019-07-231-3/+3
| | | | | | | | | | * RELNOTES: Updated. * configure, txr.1: Bumped version and date. * share/txr/stdlib/ver.tl: Likewise. * txr.vim, tl.vim: Regenerated.
* doc: Latin overhaul.Kaz Kylheku2019-07-221-16/+27
| | | | | | * txr.1: Ensure all instances of vice versa are spellled consistently without a dash and italicized. Italicize every et cetera and one a priori.
* doc: remove "of course".Kaz Kylheku2019-07-221-47/+42
| | | | * txr.1: All instances of the hedge phrase "of course" are removed.
* doc: improvements tied to "very".Kaz Kylheku2019-07-221-31/+34
| | | | | | | * txr.1: A smattering of wording improvements motivated by a search for the fluff adjective "very". Most instances of "very" are deleted, and in some cases the surrounding wording is improved.
* doc: @(merge) improvement.Kaz Kylheku2019-07-221-6/+6
| | | | | * txr.1: Description of @(merge) is improved by eliminating fluff wording.
* doc: eliminate example uses of obsolete txr-path.Kaz Kylheku2019-07-221-3/+4
| | | | | | | | | * txr.1: In the --args example, don't use txr-path, but txr-exe-path. Also, path-cat instead of plain string catenation. The example for save-exe was additionally doing something wrong: taking the dir-name of txr-path, which would calculate the parent of the executable directory. This example is harmonized with the --args one.
* doc: wording under dir-name.Kaz Kylheku2019-07-221-1/+1
| | | | | * txr.1: the term "raw directory path" has not been introduced; it is a typo for "raw directory prefix".
* ffi: support flexible structures.Kaz Kylheku2019-07-201-3/+97
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds support for working with foreign structures which use the C99 "flexible array member", or possibly the old "C struct hack". Some improvements are made in the FFI code the area of incomplete types and bitfields. * ffi.c (struct txr_ffi_type): New flag members incomplete and bitfield. (ffi_varray_dynsize): Check incomplete type flag rather than for zero size. (ffi_flex_dynsize, ffi_flex_alloc, ffi_flex_struct_in): New static functions. (ffi_struct_in): Call ffi_flex_struct_in when doing by-value semantics on a flexible structure, just before converting last member. This checks for the length method, calls it, and adjusts the last member object as documented. (ffi_struct_get): Likewise. (bitfield_syntax_p): Static function removed; there is a flag for this now in the type, so no need to parse its syntax. (make_ffi_type_pointer): Test bitfield flag rather than using bitfield_syntax_p. (make_ffi_type_struct): Take new argument indicating that the struct is flexible. Wire in appropriate virtual functions based on this flag, and set the type's incomplete flag accordingly. Check bitfield flag rather than using bitfield_syntax_p for detecting bitfield members. Calculate the size of flexible struct differently: it is the offset of the last member. (make_ffi_type_union): Test bitfield flag rather than using bitfield_syntax_p. (ffi_struct_compile): Renamed to ffi_membs_compile. (ffi_membs_compile): New pointer parameter for returning an indication whether the member list specifies a flexible struct. Test the incomplete flag of a member type rather than size being zero. (ffi_type_compile): Follow rename of ffi_struct_compile to ffi_membs_compile. Pass down the flag obtained from ffi_membs_compile into make_ffi_type_struct so that a flexible struct type is created when necessary. Disallow arrays of bitfields. Set bitfield flag on bitfield types. (ffi_init_types): Set incomplete flag on void type. (ffi_make_call_desc): Test for incomplete and bitfield types using new flags. (ffi_typedef, ffi_size, ffi_alignof): Test for bitfield type using new bitfield flag. (carray_elem_check): New static function. (carray_buf, carray_pun, carray_unum, carray_num): Use new carray_elem_check to check for bad array element type. This uses the incomplete flag rather than checking for zero size, and also disallows bitfields. * lib.h (length_s): Declared. * txr.1: Flexible structs documented in new section. Also section on incomplete types. Description of sizeof operator gives more detaild about incomplete types including flexible structs.
* doc: document ffi-out.Kaz Kylheku2019-07-181-0/+53
| | | | * txr.1: Add missing documentation for ffi-out.
* doc: ffi-in: wrong direction word.Kaz Kylheku2019-07-181-1/+1
| | | | * txr.1: ffi-in is a decoding not an encoding action.
* doc: ffi-in offset argument description missing.Kaz Kylheku2019-07-181-1/+9
| | | | * txr.1: Document the offset argument of the ffi-in operation.
* relate: optimize with hashes.Kaz Kylheku2019-07-171-0/+5
| | | | | | | | | | | * lib.c (do_relate_hash, do_relate_hash_dfl): New static functions. (relate): If the number of keys and values is the same, and there are more than ten, then use hashing. If the default value is specified, and it is nil, then a hash table can be returned directly, instead of a function. * txr.1: Note added that relate may return a hash.
* New function: hash-zip.Kaz Kylheku2019-07-171-0/+30
| | | | | | | | | * hash.c (hash_zip): New function. (hash_init): hash-zip intrinsic registered. * hash.h (hash_zip): Declared. * txr.1: Documented.
* ffi: two-argument form of sizeof.Kaz Kylheku2019-07-111-5/+28
| | | | | | | | | | | | | | | If sizeof is given an extra argument (an expression which evaluates to an object), it can calculate the dynamic size of the FFI type in relation to representing that object. * ffi.c (dyn_size): New static function. (ffi_init): Register sys:dyn-size intrinsic. * share/txr/stdlib/ffi.tl (sizeof): Support additional argument, avoiding run-time compilation of the type expression with the help of load-time. * txr.1: Update documentation for sizeof macro.
* ffi: handle variable length types in buffer ops.Kaz Kylheku2019-07-111-3/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The motivating bug here is that (ffi-put #(1 2 3 5) (ffi (array int))) perpetrates a buffer overrun. The size of (array int) is zero, and so a zero-length buffer is allocated. But then an array of five ints is stored. This is made to work correctly: allocating a buffer large enough. A new virtual function is introduced into the txr_ffi_type structure to calculate a type's dynamic size, from a prototype Lisp object. * ffi.c (struct txr_ffi_type): New function pointer member, dynsize. (ffi_fixed_dynsize, ffi_varray_dynsize): New static functions. (make_ffi_type_builtin, make_ffi_type_pointer, make_ffi_type_struct, make_ffi_type_union, make_ffi_type_array): Initialize new dynsize member of type structure with pointer to ffi_fixed_dynsize. (ffi_type_compile): Initialize the dynsize pointer of variable array types to ffi_varray_dynsize. (ffi_put_into, ffi_put, ffi_in, ffi_out): Use dynsize to calculate the real size required to store or extract the given object. * txr.1: Update doc for ffi-put, ffi-put-into and ffi-in. Looks like we are missing ffi-out; it is not documented!