diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-01-18 00:10:46 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-01-18 00:10:46 -0800 |
commit | a6a692caa3421b00aa0154854134edd472ce5354 (patch) | |
tree | fc787090cc754f5a6cfb84c70a4da1ac7767f32c | |
parent | 67b724ab51c37e9ab8294eecc1c90eb96327e060 (diff) | |
download | txr-a6a692caa3421b00aa0154854134edd472ce5354.tar.gz txr-a6a692caa3421b00aa0154854134edd472ce5354.tar.bz2 txr-a6a692caa3421b00aa0154854134edd472ce5354.zip |
doc: document @(op) and predicate operator.
-rw-r--r-- | txr.1 | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -40095,6 +40095,87 @@ values. x) -> 2 .brev +.coNP Pattern operator @ op +.synb +.mets @(op << form +) +.syne +.desc +The +.code op +operator uses the syntax of the +.code op +macro to produce an anonymous function, which is used as the basis of a +predicate match. The function is applied to the corresponding object. +If the function yields true, the match succeeds, otherwise it fails. + +The syntax and semantics of +.code op +is exactly that of the +.code op +macro. + +The syntax must be used in such a way that the resulting anonymous +function is capable of being called with exactly one argument. + +.TP* Example + +.verb + ;; 11 matches, since it is in the 10-13 range + (if-match @(op <= 10 @1 13) 11 :yes :no) -> :yes + + ;; let can be used to capture into a variable + (when-match @(let x @(op <= 10 @1 13)) 11 x) -> 11 +.brev + +.NP* Pattern predicate operator +.synb +.mets >> @( function <> [ symbol ]) +.syne +.desc +Whenever the operator of a pattern predicate is not recognized, that operator +is assumed to be the name of a function, and the syntax is treated as the +predicate operator. + +The pattern predicate operator invokes the function, passing it the +corresponding object as an argument. The match is successful if the function +returns true. + +Optionally, if the +.meta symbol +is specified, and is not +.codn nil , +it is bound to the corresponding object. + +The +.meta symbol +argument, if present, must be a +.code bindable +symbol, or else +.codn nil . + +The +.meta function +must be capable of accepting exactly one argument. + +Note: a +.code lambda +expression may be used as +.metn function . + +.TP* Example: + +.verb + (when-match (@(evenp) @(oddp x)) '(2 3) x) -> 3 +.brev + +An instance of the +.mono +.meti >> @( operator ...) +.onom +syntax denotes the predicate operator whenever the +.meta operator +symbol is not one of the predicates. + .SS* Quasiquote Operator Syntax .coNP Macro @ qquote .synb |