diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-01-17 14:51:45 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-01-17 14:51:45 -0800 |
commit | 08239be747be98700d02ff627b49bda0e8f0426a (patch) | |
tree | 32082453ad8b695fb3bb43b3c2ed9f66cb28d839 /txr.1 | |
parent | e6cf686633c15bfcf787f82b86a1eef17b401fa8 (diff) | |
download | txr-08239be747be98700d02ff627b49bda0e8f0426a.tar.gz txr-08239be747be98700d02ff627b49bda0e8f0426a.tar.bz2 txr-08239be747be98700d02ff627b49bda0e8f0426a.zip |
doc: document @(let) and @(require) pattern ops.
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 88 |
1 files changed, 88 insertions, 0 deletions
@@ -39731,7 +39731,9 @@ atom pattern nil .codn nil . The syntax +.mono .meti (. << pattern ) +.onom is valid, but indistinguishable from .meta pattern and therefore is not a list pattern. @@ -39876,6 +39878,92 @@ object's structure type: the type itself, rather than its symbolic name. (#<struct-type widget> :widg)) .brev +.coNP Pattern operator @ let +.synb +.mets @(let < name << pattern) +.syne +.desc +The +.code let +pattern operator allows the entire object matched by a +.meta pattern +to be bound to a the variable given by +.metn name . + +The +.meta name +argument must be a bindable symbol, or else +.codn nil . +If +.meta name +is +.codn nil , +then no name is bound. Thus +.mono +.meti @(let nil << pattern ) +.onom +is equivalent to just +.metn pattern . + +If +.meta pattern +matches, then +.meta name +is included among the variables, and receives the entire +object matched by +.meta pattern +as its value. + +.TP* Example: + +.verb + ;; w captures the entire (1 2 3) list: + + (when-match @(let w (@a @b @c)) '(1 2 3) (list w a b c)) + -> ((1 2 3) 1 2 3) +.brev + +.coNP Pattern operator @ require +.synb +.mets @(require < pattern << expression *) +.syne +.desc +The pattern operator +.code require +applies the specified +.meta pattern +to the corresponding object. +If the +.meta pattern +matches, the operator then imposes the additional conditions specified by +the extra +.metn expression . +The +.meta expression +is evaluated in a scope in which the variables from +.meta pattern +have already been established. +However, the mach is considered to have succeeded only if +.meta expression +yields true. If it yields +.codn nil , +then the match is deemed to have failed. + +.TP* Examples: + +.verb + ;; Match a (+ a b) expression where a and b are similar: + + (when-match @(require (+ @a @b) (equal a b)) '(+ z z) (list a b)) + --> (z z) + + ;; Mismatched case + (if-match @(require (+ @a @b) (equal a b)) '(+ y z) + (list a b) + :no-match) + --> :no-match +.brev + .SS* Quasiquote Operator Syntax .coNP Macro @ qquote .synb |