diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-07-22 07:37:22 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-07-22 07:37:22 -0700 |
commit | 420a230dbae897ee32c03297f7e4bb18f683a8b1 (patch) | |
tree | ca542bbde5776b9a5f8ed5ecbd1769dc19956038 | |
parent | fb8a30d4540d04b02f98e7895cdb02d5c7f6c2e6 (diff) | |
download | txr-420a230dbae897ee32c03297f7e4bb18f683a8b1.tar.gz txr-420a230dbae897ee32c03297f7e4bb18f683a8b1.tar.bz2 txr-420a230dbae897ee32c03297f7e4bb18f683a8b1.zip |
Implementing second through tenth as places.
* eval.c (eval_init): Register second through tenth as intrinsic.
* gencadr.txr: New cadr.c changes encoded.
* lib.c (second, third, fourth, fifth, sixth): Functions
reimplemented using ref, so they are much more efficient
for vectors and strings.
(seventh, eighth, ninth, tenth): New functions.
* lib.h (seventh, eighth, ninth, tenth): Declared.
* share/txr/stdlib/place.tl: place macros defined for
second through tenth.
* txr.1: Documented.
-rw-r--r-- | ChangeLog | 20 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | lib.c | 40 | ||||
-rw-r--r-- | lib.h | 4 | ||||
-rw-r--r-- | share/txr/stdlib/place.tl | 9 | ||||
-rw-r--r-- | txr.1 | 41 |
6 files changed, 96 insertions, 22 deletions
@@ -1,5 +1,25 @@ 2015-07-22 Kaz Kylheku <kaz@kylheku.com> + Implementing second through tenth as places. + + * eval.c (eval_init): Register second through tenth as intrinsic. + + * gencadr.txr: New cadr.c changes encoded. + + * lib.c (second, third, fourth, fifth, sixth): Functions + reimplemented using ref, so they are much more efficient + for vectors and strings. + (seventh, eighth, ninth, tenth): New functions. + + * lib.h (seventh, eighth, ninth, tenth): Declared. + + * share/txr/stdlib/place.tl: place macros defined for + second through tenth. + + * txr.1: Documented. + +2015-07-22 Kaz Kylheku <kaz@kylheku.com> + * lisplib.c (place_set_entries): Add *place-macro* and define-place-macro to list of names. @@ -4140,6 +4140,10 @@ void eval_init(void) reg_fun(intern(lit("fourth"), user_package), func_n1(fourth)); reg_fun(intern(lit("fifth"), user_package), func_n1(fifth)); reg_fun(intern(lit("sixth"), user_package), func_n1(sixth)); + reg_fun(intern(lit("seventh"), user_package), func_n1(seventh)); + reg_fun(intern(lit("eighth"), user_package), func_n1(eighth)); + reg_fun(intern(lit("ninth"), user_package), func_n1(ninth)); + reg_fun(intern(lit("tenth"), user_package), func_n1(tenth)); reg_fun(intern(lit("conses"), user_package), func_n1(conses)); reg_fun(intern(lit("conses*"), user_package), func_n1(lazy_conses)); reg_fun(intern(lit("copy-list"), user_package), func_n1(copy_list)); @@ -367,29 +367,49 @@ val rest(val cons) return cdr(cons); } -val second(val cons) +val second(val obj) { - return car(cdr(cons)); + return ref(obj, one); } -val third(val cons) +val third(val obj) { - return car(cdr(cdr(cons))); + return ref(obj, two); } -val fourth(val cons) +val fourth(val obj) { - return car(cdr(cdr(cdr(cons)))); + return ref(obj, three); } -val fifth(val cons) +val fifth(val obj) { - return car(cdr(cdr(cdr(cdr(cons))))); + return ref(obj, four); } -val sixth(val cons) +val sixth(val obj) { - return car(cdr(cdr(cdr(cdr(cdr(cons)))))); + return ref(obj, num_fast(5)); +} + +val seventh(val obj) +{ + return ref(obj, num_fast(6)); +} + +val eighth(val obj) +{ + return ref(obj, num_fast(7)); +} + +val ninth(val obj) +{ + return ref(obj, num_fast(8)); +} + +val tenth(val obj) +{ + return ref(obj, num_fast(9)); } val conses(val list) @@ -445,6 +445,10 @@ val third(val cons); val fourth(val cons); val fifth(val cons); val sixth(val cons); +val seventh(val cons); +val eighth(val cons); +val ninth(val cons); +val tenth(val cons); val conses(val list); val lazy_conses(val list); val listref(val list, val ind); diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 0356e81e..67a593fb 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -614,3 +614,12 @@ (define-place-macro first (obj) ^(car ,obj)) (define-place-macro rest (obj) ^(cdr ,obj)) +(define-place-macro second (obj) ^(ref ,obj 1)) +(define-place-macro third (obj) ^(ref ,obj 2)) +(define-place-macro fourth (obj) ^(ref ,obj 3)) +(define-place-macro fifth (obj) ^(ref ,obj 4)) +(define-place-macro sixth (obj) ^(ref ,obj 5)) +(define-place-macro seventh (obj) ^(ref ,obj 6)) +(define-place-macro eighth (obj) ^(ref ,obj 7)) +(define-place-macro ninth (obj) ^(ref ,obj 8)) +(define-place-macro tenth (obj) ^(ref ,obj 9)) @@ -13713,26 +13713,43 @@ specifies the contents of the entire string or vector, as if the operation were done on a non-empty vector or string, followed by the deletion of the first element. -.coNP Functions @, second @, third @, fourth @ fifth and @ sixth +.coNP Accessors @, second @, third @, fourth @, fifth @, sixth @, seventh @, eighth @ ninth and @ tenth .synb -.mets (first << list ) -.mets (second << list ) -.mets (third << list ) -.mets (fourth << list ) -.mets (fifth << list ) -.mets (sixth << list ) +.mets (first << object ) +.mets (second << object ) +.mets (third << object ) +.mets (fourth << object ) +.mets (fifth << object ) +.mets (sixth << object ) +.mets (seventh << object ) +.mets (eighth << object ) +.mets (ninth << object ) +.mets (tenth << object ) +.mets (set (first << object ) << new-value ) +.mets (set (second << object ) << new-value ) +.mets ... +.mets (set (tenth << object ) << new-value ) .syne .desc -These functions access the elements of a proper list by position. - -If the list is shorter than implied, these functions return +Used as functions, these accessors retrieve the elements of a sequence by +position. If the sequence is shorter than implied by the position, these +functions return .codn nil . +When used as syntactic places, these accessors denote the storage locations +by position. The location must exist, otherwise an error exception results. +The places support deletion. + + .TP* Examples: .cblk (third '(1 2)) -> nil - (second '(1 2)) -> 2 - (third '(1 2 . 3)) -> **error** + (second "ab") -> #\eb + (third '(1 2 . 3)) -> **error, improper list* + + (let ((x (copy "abcd"))) + (inc (third x)) + x) -> "abce" .cble .coNP Functions @, append @ nconc and @ append* |