diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-07-21 22:14:23 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-07-21 22:14:23 -0700 |
commit | f10ed814f895f2527b99fc6a55057617a7750ba7 (patch) | |
tree | 7e0c421f9b284f195c8e3fae239ef84463d8f0ad /txr.1 | |
parent | 701d5ff8c6a2d4ca6023be345faf4f085db6c689 (diff) | |
download | txr-f10ed814f895f2527b99fc6a55057617a7750ba7.tar.gz txr-f10ed814f895f2527b99fc6a55057617a7750ba7.tar.bz2 txr-f10ed814f895f2527b99fc6a55057617a7750ba7.zip |
Implementing caar, cadr, cdar and friends.
* lib.c (init): Call cadr_init.
* lisplib.c (dl_table, set_dlt_entries, dlt_register): Externalize.
* lisplib.h (dl_table, set_dlt_entries, dlt_register): Declared.
* Makefile (OBJS): Add cadr.o.
* cadr.c: New file.
* cadr.h: New file.
* gencadr.txr: New file.
* share/txr/stdlib/cadr.tl: New file.
* txr.1: Document cadr accessors.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 80 |
1 files changed, 80 insertions, 0 deletions
@@ -14171,6 +14171,86 @@ then .code nil is returned. +.coNP Accessors @, caar @, cadr @, cdar @, cddr ... @ cdddddr +.synb +.mets (caar << object ) +.mets (cadr << object ) +.mets (cdar << object ) +.mets (cddr << object ) +.mets ... +.mets (cdddr << object ) +.mets (set (caar << object ) << new-value ) +.mets (set (cadr << object ) << new-value ) +.mets ... +.syne +.desc +The +.I a-d accessors +provide a shorthand notation for accessing two to five +levels deep into a cons-cell-based tree structure. For instance, the +the equivalent of the nested function call expression +.cblk +.meti (car (car (cdr << object ))) +.cble +can be achieved using the single function call +.cblk +.meti (caadr << object ). +The symbol names of the a-d accessors are a generalization of the words +"car" and "cdr". They encodes the pattern of +.code car +and +.code cdr +traversal of the structure using a sequence of the the letters +.code a +and +.code d +placed between +.code c +and +.codn r . +The traversal is encoded in right-to-left order, so that +.code cadr +indicates a traversal of the +.code cdr +link, followed by the +.codn car . +This order corresponds to the nested function call notation, which also +encodes the traversal right-to-left. The following diagram illustrates +the straightforward relationship: +.cblk + (cdr (car (cdr x))) + ^ ^ ^ + | / | + | / / + | / ____/ + || / + (cdadr x) +.cble + +\*(TL provides all possible a-d accessors up to five levels deep, from +.code caar +all the way through +.codn cdddddr . + +Expressions involving a-d accessors are places. For example, +.code (caddr x) +denotes the same place as +.codn (car (cddr x)) , +and +.code (cdadr x) +denotes the same place as +.codn (cdr (cadr x)) . + +The a-d accessor places support deletion, with semantics derived from +the deletion semantics of the +.code car +and +.code cdr +places. For example, +.code (del (caddr x)) +means the same as +.code (del (car (cddr x))) . + .coNP Functions @ flatten and @ flatten* .synb .mets (flatten << list ) |