guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v1 4/6] docs/match: match-let* unwrap example


From: Blake Shaw
Subject: [PATCH v1 4/6] docs/match: match-let* unwrap example
Date: Fri, 27 Jan 2023 01:57:59 +0700

[pdf] now builds, but there are some spacing issues I want to correct
in the PDF, that will be introduced next.
---
 doc/ref/match.texi | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/doc/ref/match.texi b/doc/ref/match.texi
index 567146a35..4f3dc86fc 100644
--- a/doc/ref/match.texi
+++ b/doc/ref/match.texi
@@ -248,7 +248,7 @@ The names @code{quote}, @code{quasiquote}, @code{unquote},
 @code{or}, @code{not}, @code{set!}, @code{get!}, @code{...}, and
 @code{___} cannot be used as pattern variables.
 
-Here is a more complex example:
+Here is a more complex example using records and promises:
 
 @example
 (use-modules (srfi srfi-9))
@@ -361,11 +361,22 @@ bind the variables in sequence, with preceding match 
variables in scope.
 (match-let (((x y) (list 1 2)))
   (match-let (((a b) (list x 4)))
     (list a b x y)))
-@result{}
-(1 4 1 2)
+@result{} (1 4 1 2)
 @end example
 @end deffn
 
+@example
+(define wrap '(((((unnest arbitrary nestings))))))
+
+(let unwrap ((peel wrap)) 
+  (match-let* ([([core ...]) peel]
+              [(wrapper ...) core])
+    (if (> (length wrapper) 1) 
+       wrapper 
+       (unwrap wrapper))))
+@result{} (unnest arbitrary nestings)
+@end example
+
 @deffn {Scheme Syntax} match-letrec ((variable expression) @dots{}) body
 Similar to @code{match-let}, but analogously to @code{letrec}, match and
 bind the variables with all match variables in scope.
-- 
2.39.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]