diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2024-02-09 07:34:15 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2024-02-09 07:34:15 -0800 |
commit | ab58598e62eb7ca718d2ee083c1c2c2ede4d6db3 (patch) | |
tree | 245dd7aa545d26db0d62fefa61de13ff5310ed4c /txr.1 | |
parent | 3fb108272f762a4e3afa3f2f925db03b3128c272 (diff) | |
download | txr-ab58598e62eb7ca718d2ee083c1c2c2ede4d6db3.tar.gz txr-ab58598e62eb7ca718d2ee083c1c2c2ede4d6db3.tar.bz2 txr-ab58598e62eb7ca718d2ee083c1c2c2ede4d6db3.zip |
New function: cons-count.
* eval.c (eval_init): Register cons-count intrinsic.
* lib.c (cons_count_rec): New static function.
(cons_count): New function.
* lib.h (cons_count): Declared.
* tests/012/cons.tl: New tests.
* txr.1: Documented.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -36112,6 +36112,47 @@ The function returns the count of the number keys for which .meta predfun returns true. +.coNP Function @ cons-count +.synb +.mets (cons-count < obj < tree <> [ test-function ]) +.syne +.desc +The +.code cons-count +function returns the number of times the object +.meta obj +occurs in the +.code cons +cell structure +.metn tree , +under the equality imposed by the +.metn test-function . + +If the optional +.meta test-function +argument is omitted, it defaults to +.codn equal . + +First, +.meta obj +and +.meta tree +are compared using +.metn test-function . +If they are equal, that counts as one occurrence. + +Then, if +.meta tree +is a +.code cons +cell, the function recurses over the +.code car +and +.code cdr +fields. + +The sum of all these counts is returned. + .coNP Functions @, posq @ posql and @ posqual .synb .mets (posq < object << sequence ) |