[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:48:01 +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:
-(match lst
-  (((heads tails ...) ...)
-   heads))
+(match '(((a b c) e f g) 1 2 3)
+  (((head ...) tails ...)
+   `(,@tails ,head)))
+@result{} (1 2 3 ((a b c) e f g))
  @end example

Contrary to the commit message, this isn't an addition of a pattern matching example, it's a change.
Aside from inlining 'lst', what's this change for?

+A pattern matcher can match an object against several patterns and
+extract the elements that make it up. +
+(let ((m '((a . b) (c . d) (e . f))))
+  (match m
+    (((left . right) ...) left)))
+@result{} (a c e)
+@end example

There is only a single pattern here, not several patterns.
Several patterns would be, e.g.,

(let ((m '(#(a b) #(c d) #(e f)))
  (match m
    (((left . right) ...) left)
    ((#(left right) ...) left))).

+Patterns can represent any Scheme object: lists, strings, symbols,
+records, etc.

Missing end-of-sentence period. The . in 'etc.' is part of the abbreviation 'etc.', not an end-of-sentence marker. I know it's 'standard' English (for some value of 'standard' in English) to conflate all the dots, but we don't have to follow standard when they are buggy.

(This is like the example at <> about not moving the end-of-sentence period inside quotation marks:

    Then delete a line from the file by typing “dd”.

    Then delete a line from the file by typing “dd.”

-- while in this particular case (i.e., 'etc.') the distinction is unimportant, for consistency with other cases where the distinction is important, I would go for '..., symbols, records, etc..'.


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]