[Top][All Lists]

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

Re: [PATCH v1 1/6] docs/match: add pattern matching examples

From: Maxime Devos
Subject: Re: [PATCH v1 1/6] docs/match: add pattern matching examples
Date: Sat, 28 Jan 2023 14:18:25 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0

On 26-01-2023 19:57, Blake Shaw wrote:
+A pattern matcher does precisely what the name implies: it matches
+some arbitrary pattern, and returns some result accordingly.

It doesn't need to return anything -- while functional style is common in Guile, imperative is still possible. It can return multiple things with 'values'. I propose replacing 'result' with 'results'.

-(let ((l '(hello (world))))
-  (match l           ;; <- the input object
-    (('hello (who))  ;; <- the pattern
-     who)))          ;; <- the expression evaluated upon matching
-@result{} world
+(define (english-base-ten->number name)
+  (match name
+    ('zero   0)
+    ('one    1)
+    ('two    2)
+    ('three  3)
+    ('four   4)
+    ('five   5)
+    ('six    6)
+    ('seven  7)
+    ('eight  8)
+    ('nine   9)))
+(english-base-ten->number 'six)
+@result{} 6

This is a suboptimal example; this would be better done with 'case'.
I propose replacing it with another example, or adding a note that one would normally use 'case' for this.


Attachment: OpenPGP_0x49E3EE22191725EE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

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