From aced8689f932eeb2a0042a7b89ce4485e3be9c04 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 14 May 2013 19:23:13 -0700 Subject: * RELNOTES: Updated in preparation for release. * eval.c (eval_init): Expose delete-package, rehome-sym and packagep. * lib.c (make_package, intern): use ~s formatting for package name in error message. (packagep, delete_package, rehome_sym): New functions. * lib.h (packagep, delete_package, rehome_sym): Declared. * txr.1: Documented process functions and packages. --- ChangeLog | 15 +++++ RELNOTES | 69 +++++++++++++++++++++ eval.c | 3 + lib.c | 34 +++++++++- lib.h | 3 + txr.1 | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 330 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f2cbea9..56010ae1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2013-05-14 Kaz Kylheku + + * RELNOTES: Updated in preparation for release. + + * eval.c (eval_init): Expose delete-package, rehome-sym + and packagep. + + * lib.c (make_package, intern): use ~s formatting for package name in + error message. + (packagep, delete_package, rehome_sym): New functions. + + * lib.h (packagep, delete_package, rehome_sym): Declared. + + * txr.1: Documented process functions and packages. + 2013-01-11 Kaz Kylheku * eval.c (eval_init): New instrinsic function iffi registered. diff --git a/RELNOTES b/RELNOTES index b5779936..2c0d5e11 100644 --- a/RELNOTES +++ b/RELNOTES @@ -1,3 +1,72 @@ + TXR 66 + 2013-05-xx + + + Features + + - Documentation completely filled in. + + - Added specfile for RPM builds. + + - @(repeat) introduced as shorthand for @(collect :vars nil). + + - New open-command and open-process functions. The open-pipe + function becomes deprecated. + + - New multi-sort function for sorting two or more lists + at the same time as if they were columns of a table. + + - assq and aconsq functions are renamed to assql and + aconsql becuse they use eql equality, not eq. + + - New prop function for property list lookup. + + - New stat function for information about files. + + - New functions in hashing library: + - Copying hashes: make-similar-hash, copy-hash + - Set operations: hash-uni, hash-diff, hash-isec. + + - Gapingly missing hexadecimal integer constants have been + implemented. + + - New bit operation functions that work with TXR's arbitrary precision + integers: loand, logior, loxor, lognot, logtest, ash. + + - Test form in for loop can be omitted. + + - New package-related functions. + + Bugs + + - Fixed broken (+ ) case in addition. + This fixes the range and range* functions too. + + - Fixed nonworking building in a separate directory. + + - Fixed broken eval function. + + - Bugfix in form expander's handling of regular expression + syntax, causing the (set ...) notation for character + sets being mistaken for the (set ...) assignment operator. + + - Bugfix in format: apply field formatting to argument + not only if a nonzero with has been specified, but also + if a precision has been specified. + + - Bugfix in format: ~s on a floating point number now + always shows .0 except when a precision is given, + and it is zero. + + - Fixed broken @(last) clause processing of @(collect), + int he case when the last material matches at the end of a stream. + + - Fixed certain function applications not being able to + call functions that have optional arguments with + fewer than + + + TXR 65 2012-04-20 diff --git a/eval.c b/eval.c index b80149af..8337fed0 100644 --- a/eval.c +++ b/eval.c @@ -2342,10 +2342,13 @@ void eval_init(void) reg_fun(intern(lit("gensym"), user_package), func_n0v(gensymv)); reg_fun(intern(lit("make-package"), user_package), func_n1(make_package)); reg_fun(intern(lit("find-package"), user_package), func_n1(find_package)); + reg_fun(intern(lit("delete-package"), user_package), func_n1(delete_package)); reg_fun(intern(lit("intern"), user_package), func_n2o(intern, 1)); + reg_fun(intern(lit("rehome-sym"), user_package), func_n2o(rehome_sym, 1)); reg_fun(intern(lit("symbolp"), user_package), func_n1(symbolp)); reg_fun(intern(lit("symbol-name"), user_package), func_n1(symbol_name)); reg_fun(intern(lit("symbol-package"), user_package), func_n1(symbol_package)); + reg_fun(intern(lit("packagep"), user_package), func_n1(packagep)); reg_fun(intern(lit("keywordp"), user_package), func_n1(keywordp)); reg_fun(intern(lit("mkstring"), user_package), func_n2(mkstring)); diff --git a/lib.c b/lib.c index dfc1e75d..2d9fa99a 100644 --- a/lib.c +++ b/lib.c @@ -2360,7 +2360,7 @@ val gensymv(val args) val make_package(val name) { if (find_package(name)) { - uw_throwf(error_s, lit("make_package: ~a exists already"), name, nao); + uw_throwf(error_s, lit("make_package: ~s exists already"), name, nao); } else { val obj = make_obj(); obj->pk.type = PKG; @@ -2372,11 +2372,29 @@ val make_package(val name) } } +val packagep(val obj) +{ + return type(obj) == PKG ? t : nil; +} + val find_package(val name) { return cdr(assoc(name, packages)); } +val delete_package(val package) +{ + if (stringp(package)) { + package = find_package(package); + if (!package) + uw_throwf(error_s, lit("delete-package: no such package: ~s"), package, nao); + } + + type_check (package, PKG); + packages = alist_nremove(packages, package->pk.name); + return nil; +} + val intern(val str, val package) { val new_p; @@ -2387,7 +2405,7 @@ val intern(val str, val package) } else if (stringp(package)) { package = find_package(str); if (!package) - uw_throwf(error_s, lit("make_package: ~a exists already"), str, nao); + uw_throwf(error_s, lit("intern: symbol ~s exists already"), str, nao); } type_check (package, PKG); @@ -2403,10 +2421,20 @@ val intern(val str, val package) } } -static val rehome_sym(val sym, val package) +val rehome_sym(val sym, val package) { if (!sym) return nil; + + if (nullp(package)) { + package = user_package; + } else if (stringp(package)) { + val p = find_package(package); + if (!p) + uw_throwf(error_s, lit("rehome-sym: no such package: ~s"), package, nao); + package = p; + } + type_check (package, PKG); type_check (sym, SYM); diff --git a/lib.h b/lib.h index e22a265c..33207145 100644 --- a/lib.h +++ b/lib.h @@ -536,8 +536,11 @@ val make_sym(val name); val gensym(val prefix); val gensymv(val args); val make_package(val name); +val packagep(val obj); val find_package(val name); +val delete_package(val package); val intern(val str, val package); +val rehome_sym(val sym, val package); val symbolp(val sym); val symbol_name(val sym); val symbol_package(val sym); diff --git a/txr.1 b/txr.1 index 4cdc568c..acb8fc45 100644 --- a/txr.1 +++ b/txr.1 @@ -9149,7 +9149,7 @@ Syntax: Description: These functions each compute an integer hash value from the internal -representation of , which satisifes the following properties. +representation of , which satisfies the following properties. If two objects A and B are the same under the eql function, then (hash-eql A) and (hash-eql B) produce the same integer hash value. Similarly, if two objects A and B are the same under the equal function, then (hash-equal @@ -9913,26 +9913,234 @@ are invoked on it. .SS Functions open-command, open-process +.TP +Syntax: + + (open-command ) + (open-process ) + +.TP +Description: + +These functions spawn external programs which execute concurrently +with the TXR program. Both functions return a unidirectional stream for +communicating with these programs: either an output stream, or an input +stream, depending on the contents of . + +The open-command function accepts, via the string parameter, a +system command, which is in a system-dependent syntax. On a POSIX system, this +would be in the POSIX Shell Command Language. + +The open-process function specifies a program to invoke via the +argument. This is subject the the operating system's search strategy. +On POSIX systems, if it is an absolute or relative path, it is treated as +such, but if it is a simple base name, then it is subject to searching +via the components of the PATH environment variable. + +The argument is compatible with the convention used by the POSIX +popen function. + +The argument is a list of strings which specifies additional +optional arguments to be passed passed to the program. The argument +becomes the first argument, and become the second and +subsequent arguments. + +If a coprocess is open for writing ( is specified as "w"), then +writing on the returned stream feeds input to that program's standard input +file descriptor. Indicating the end of input is performed by closing the +stream. + +If a coprocess is open for reading ( is specified as "r"), then +the program's output can be gathered by reading from the returned stream. +When the program finishes output, it will close the stream, which can be +detected as normal end of data. + +If a coprocess terminates abnormally or unsuccessfully, an exception is raised. + .SH SYMBOLS AND PACKAGES +A package is an object which serves as a container of symbols. + +A symbol which exists inside a package is said to be interned in that package. +A symbol can be interned in at most one package at a time. + +string, but not necessarily unique. A symbol name is unique within a package, +however: two symbols cannot be in the same package if they have the same name. +Moreover, a symbol cannot exist in more than one package at at time, although +it can be relocated from one package to antoher. Symbols can exist which are +not in packages: these are called uninterned symbols. + +Packages are held in a global list which can be used to search for a package by +name. The find-package function performs this lookup. A package may be +deleted from the list with the delete-package function, but it continues +to exist until the program loses the last reference to that package. + .SS Variables *user-package*, *keyword-package*, *system-package* +These variables hold predefined packages. The *user-package* is the one +in which symbols are read when a TXR program is being scanned. +The *keyword-package* holds keyword symbols, which are printed with +a leading colon. The *system-package* is for internal symbols, helping +the implementation avoid name clashes with user code in some situations. + .SS Function make-sym +.TP +Syntax: + + (make-sym ) + +Description: + +The make-sym function creates and returns a new symbol object. The argument +, which must be a string, specifies the name of the symbol. The symbol +does not belong to any package (it is said to be "uninterned"). + +Note: an uninterned symbol can be interned into a package with the rehome-sym +function. Also see the intern function. + .SS Function make-package +.TP +Syntax: + + (make-package ) + +.TP +Description: + +The make-package function creates and returns a package named , where + is a string. It is an error if a package by that name exists already. + +.SS Function packagep + +.TP +Syntax: + + (packagep ) + +.TP +Description: + +The packagep function returns t if is a package, otherwise it returns +nil. + .SS Function find-package +.TP +Syntax: + + (find-package ) + +.TP +Description: + +The argument should be a string. If a package called exists, +then it is returned. Otherwise nil is returned. + .SS Function intern +.TP +Sytax: + + (intern []) + +.TP +Description: + +The argument should be a symbol. The optional argument +should be a package. If is not supplied, then the value +taken is that of *user-package*. + +The intern function searches for a symbol called . +If that symbol is found, it is returned. If that symbol is not found, +then a new symbol called is created and inserted into , +and that symbol is returned. In this case, the package becomes the +symbol's home package. + +.SS Function rehome-sym + +.TP +Syntax: + + (rehome-sym []) + +.TP +Description: + +The arguments and must be a symbol and package object, +respectively. If is not given, then it defaults to the value of +*user-package*. + +The rehome-sym function moves into . If +is already in a package, it is first removed from that package. +If a symbol of the same name exists in that symbol is first removed +from . + .SS Function symbolp +.TP +Syntax: + + (symbolp ) + +.TP +Description: + +The symbolp function returns t if is a symbol, otherwise it returns +nil. + .SS Function symbol-name +.TP +Syntax: + + (symbol-name ) + +.TP +Description: + +The symbol-name function returns the name of . + .SS Function symbol-package +.TP +Syntax: + + (symbol-package ) + +.TP +Description: + +The symbol-package function returns the home package of . + +.SS Function packagep + +.TP +Syntax: + + (packagep ) + +.TP +Description: + +The packagep function returns t if is a package, otherwise it returns +nil. + .SS Function keywordp +.TP +Syntax: + + (keywordp ) + +.TP +Description: + +The keywordp function returns t if is a keyword symbol, otherwise it +returns nil. + + .SH PSEUDO-RANDOM NUMBERS .SS Variable *random-state* -- cgit v1.2.3