unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: Eli Zaretskii <eliz@gnu.org>, Oleh Krehel <ohwoeowho@gmail.com>,
	Emacs Development <emacs-devel@gnu.org>
Subject: Re: Question on pcase
Date: Sat, 24 Oct 2015 09:01:46 +0000	[thread overview]
Message-ID: <20151024090146.GA1849@acm.fritz.box> (raw)
In-Reply-To: <87fv115t20.fsf@web.de>

Hello, Michael.

On Fri, Oct 23, 2015 at 08:38:31PM +0200, Michael Heerdegen wrote:
> Eli Zaretskii <eliz@gnu.org> writes:

> > Sounds good to me, thanks.

> I wrote a step by step introduction for people who (1) are frightened by
> `pcase' and (2) are willing to invest some (not much, but some) time to
> learn it.  It is how I would describe `pcase' to a friend, maybe it is
> good for learning, maybe it is ugly, dunno.  Some errors included.

> Someone who wants to try to learn pcase (Oleh? Oleh!) can help by
> reading it and telling me if it is understandable, and send corrections
> - or write a better introduction ;-) - and format it nicely for
> inclusion into Elpa or Emacs when it turns out to help people.

Thanks for writing this.  I've enclosed some corrections - a few typos,
and some places where the English usage isn't quite correct.

Some notes:
1. The guide you have written is _not_ trivial.  :-)  It is detailed and
helpful.

2. "Semantics", as a noun, is always plural in English (a bit like
"Eltern" in German).  It is also a mass noun, so you couldn't write "one
of the semantics is ...."; you'd need to write something like "one part
of the semantics is ....".

3. "Else" can't come at the end of a sentence.  (It can't really come at
the start of a sentence either.)  If you're going to use "else" it needs
to come _before_ the clause it applies to.

4. In "How would you roughly describe ...", the "roughly" means doing the
describing without delicacy, perhaps with violence, without any finesse.
In "How, roughly, would you describe ...", it means "approximately".
:-)

5. "the `pred' pattern form allows to simplify ...." is a very common
solecism.  The verb "allow" needs a direct object, not an infinitive verb.
That object can either be the person (or thing) who is being allowed to do
something, or the thing (a noun or gerund) which is being allowed.  So
here, you'd want one of
  o - "the `pred' pattern form allows YOU to simplify ...." or
  o - "the `pred' pattern form allows THE SIMPLIFICATION OF ...." or even 
  o - "the `pred' pattern form allows SIMPLIFYING ...."
I think the first of these is marginally the best.

6. "Now, only one basic pattern form is missing:".  Well, it's not
missing, it's there.  There's no snappy translation of "es fehlt", in
this sense.  You'd have to qualify it with something like "Now, only one
basic pattern form is missing from our list so far:", which is a bit
clumsy.  What I've suggested in my patch is, perhaps, a little less
clumsy.

7. "If you are used to understand grammers ...".  "Used to" takes a
direct object (or gerund), not an infinitive verb.  "Grammar" doesn't
have an "e" in it.  :-)


Here's the patch (not guaranteed complete).



--- pcase-guide.el~	2015-10-24 07:16:29.000000000 +0000
+++ pcase-guide.el	2015-10-24 08:52:53.000000000 +0000
@@ -1,4 +1,4 @@
-;; Understand `pcase' now! - A trivial guide to a powerful tool
+;; Understand `pcase' now! - An easy guide to a powerful tool
 ;; ============================================================
 
 
@@ -23,24 +23,24 @@
 ;; specify PATTERNs instead of CONDITIONs, and the PATTERNS are tested
 ;; for whether they match the evaluated EXPRESSION, in order.  If one
 ;; PATTERN matches, it's CODE is evaluated.  Like in `cond', all
-;; branches are tested until one is found whose PATTERN matches.  All
+;; branches are tested until one whose PATTERN matches is found.  All
 ;; remaining branches are ignored.
 ;;
 ;; The PATTERNs are not lisp code, like `cl-loop' forms they are
-;; written with an own simple language.  There are a few simple basic
+;; written in their own simple language.  There are a few simple basic
 ;; patterns, and you can combine them.
 ;;
 ;; A very useful thing is that matching a pattern can bind variables
-;; as a side effect.  This bindings are in effect when the CODE of
+;; as a side effect.  These bindings are in effect when the CODE of
 ;; that branch is executed (actually, they are already in effect when
-;; then the remaining parts of the pattern are processed; that fact
+;; the remaining parts of the pattern are processed; that fact
 ;; will prove useful later in this guide).
 ;;
-;; All yet to understand is the semantic each of the basic PATTERNs.
+;; All that remains to understand are the semantics of each of the basic PATTERNs.
 ;; Since you can do quite a lot with `pcase' - e.g. you can use it
 ;; like `let*', like `cond', like `case', like `destructuring-bind',
-;; all in combination and more, it is clear that the semantic can't be
-;; absolutely trivial.  However, there are only very few basic forms
+;; all in combination and more, it is clear that the semantics can't be
+;; absolutely trivial.  However, there are only a very few basic forms
 ;; of patterns, and all are easy to understand.  And those forms can
 ;; be combined.  That's already it.  I will explain the basic patterns
 ;; one after the other, you may want to take one or two breaks in
@@ -80,7 +80,7 @@
   (_        3))
 
 ;; This will return 1 if x is bound to the symbol `a', 2 if x is bound
-;; to a string equal to "Hallo", and 3 else.  Hey, already two pattern
+;; to a string equal to "Hallo", and 3 otherwise.  Hey, already two pattern
 ;; types learned!
 ;;
 ;; A SYMBOL (different from `_') "matches anything and binds it to
@@ -129,7 +129,7 @@
                                       3))
 
 ;; This will return 1 if x is bound to a list, 2 if what x is bound to
-;; fulfils eihter `arrayp' or `numberp'.  And 3 if the binding of x is
+;; fulfils either `arrayp' or `numberp'.  And 3 if the binding of x is
 ;; a string that contains "blue".  If none of that is true, no branch
 ;; matches, and `pcase' returns nil.
 
@@ -155,7 +155,7 @@
 ;; strange special case of matching via the `guard' pattern.
 
 ;; Exercise: We noted that `pcase' can be used to substitute `let*',
-;; `cond' or `case' in your code.  How would you roughly describe how
+;; `cond' or `case' in your code.  How, roughly, would you describe how
 ;; one can rewrite an arbitrary `let*', `cond' or `case' form using
 ;; `pcase'? (Hint: It's not hard.)
 
@@ -166,7 +166,7 @@
 ;;
 ;; This is a pattern form that allows you to match a pattern PAT
 ;; against an _arbitrary_ expression EXP.  This is not special,
-;; matching PAT is done as you have learned, just against the EXP you
+;; matching PAT is done as you have learned, just on the EXP you
 ;; specify there, and not the EXPRESSION given to pcase at top level.
 ;;
 ;; Example:
@@ -178,7 +178,7 @@
   (_ nil))
 
 ;; This will return t if x is bound to a number whose absolute value
-;; is larger than 5, like 7 or -13, and nil else, e.g. for 0 or -2 or
+;; is larger than 5, like 7 or -13, and nil otherwise, e.g. for 0 or -2 or
 ;; "Hallo".
 
 ;; Why is it called `let' then?  Because you can use it to
@@ -192,9 +192,9 @@
   l)
 
 ;; will return the string length of STRING if it is bound to a string
-;; of non-zero length, and nil else.
+;; of non-zero length, and nil otherwise.
 
-;; BTW, the `pred' pattern form allows to simplify things like
+;; BTW, the `pred' pattern form allows one to simplify things like
 
 (pred (lambda (x) (< 5 x)))
 
@@ -226,7 +226,7 @@
    abs-val))
 
 ;; will return the absolute value of x if x is a number and its
-;; absolute value is larger than 5, and nil else.
+;; absolute value is larger than 5, and nil otherwise.
 
 ;; (app FUN PAT) matches if FUN applied to the object matches PAT.
 
@@ -240,7 +240,7 @@
 ;; will return t if and only if x is bound to a string with length
 ;; smaller than 60 chars.
 
-;; Now, only one basic pattern form is missing:
+;; Now, only one basic pattern form remains to be described:
 ;;
 ;;   `QPAT         Backquote-style pcase patterns.
 ;;
@@ -263,7 +263,7 @@
 
   (1 2 3)  (1 . (2 3))
 
-;; desribe the same list structure using two different reader
+;; describe the same list structure using two different reader
 ;; syntaxes.  When being read by the Lisp reader, those forms are
 ;; equal.  So, in the above description, the
   
@@ -272,14 +272,14 @@
 ;; form can be used to match any kind of arbitrary list, and you don't
 ;; need to use the read syntax using dot.
 ;;
-;; If you are used to understand grammers: the above description of
-;; `QPAT describes a quite simpel grammer.  You make like to try it
+;; If you are used to understanding grammars: the above description of
+;; `QPAT describes a quite simple grammar.  You might like to try it
 ;; out with some examples yourself, it's simple, though the results
-;; might look unfamiliar.  It doesn't take long to familiarize with
+;; might look unfamiliar.  It doesn't take long to familiarize yourself with
 ;; it, though.
 ;;
 ;; Note that though the backquote _syntax_ is used here, the backquote
-;; macro is never called (!), just it's syntax is used to describe
+;; macro is never called (!), just its syntax is used to describe
 ;; patterns for destructuring because it is convenient to write, and
 ;; also a bit related to how backquote works.
 
@@ -297,17 +297,17 @@
 ;; to "foo", it returns the second element.
 ;;
 ;; If x is bound to a cons whose car equals "foo", and the cdr is
-;; listp, this cdr is returned.  Else, nil is returned.
+;; listp, this cdr is returned.  Otherwise, nil is returned.
 ;;
 ;; For destructuring, the `_' pattern is handy to match anything.
 ;; Pitfall: Be sure to unquote `_' if you don't want to match the
 ;; symbol `_' literally, because _ is not a QPAT.
 ;;
-;; Example: The ;; pattern
+;; Example: The pattern
 
 `(1 ,_ . ,_)
 
-;; matches any list whoose first element is 1, and which has at least
+;; matches any list whose first element is 1, and which has at least
 ;; one more element.
 
 ;; Just like with the "real" backquote, you can use "unquote" in lower
@@ -321,7 +321,7 @@
 ;; element is 1, and the second argument is a list of two elements;
 ;; the first element is bound to the variable `x', and the second
 ;; element is bound to `y', and it is tested whether x + y is smaller
-;; than 10.  Only then the whole pattern matches.
+;; than 10.  Only then does the whole pattern match.
 
 ;; Example:
 

> Thanks,

> Michael.

-- 
Alan Mackenzie (Nuremberg, Germany).



  parent reply	other threads:[~2015-10-24  9:01 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-22 14:46 Question on pcase Oleh Krehel
2015-10-22 21:19 ` Michael Heerdegen
2015-10-23  6:30   ` Eli Zaretskii
2015-10-23 11:58     ` Oleh Krehel
2015-10-23 12:23       ` Michael Heerdegen
2015-10-23 12:42         ` Oleh Krehel
2015-10-23 13:07           ` Michael Heerdegen
2015-10-23 13:26             ` Oleh Krehel
2015-10-23 13:59               ` Michael Heerdegen
2015-10-27 23:50                 ` Johan Bockgård
2015-10-30  1:33                   ` Michael Heerdegen
2015-10-23 14:23               ` Michael Heerdegen
2015-10-23 12:17     ` Michael Heerdegen
2015-10-23 12:22       ` Oleh Krehel
2015-10-23 13:26       ` Eli Zaretskii
2015-10-23 14:14         ` Michael Heerdegen
2015-10-23 14:41           ` Eli Zaretskii
2015-10-23 18:38             ` Michael Heerdegen
2015-10-23 18:43               ` Eli Zaretskii
2015-10-23 19:59               ` Przemysław Wojnowski
2015-10-23 21:01                 ` Michael Heerdegen
2015-10-23 20:23               ` Przemysław Wojnowski
2015-10-23 20:39                 ` Michael Heerdegen
2015-10-24 11:37                   ` Przemysław Wojnowski
2015-10-24  9:01               ` Alan Mackenzie [this message]
2015-10-24 12:58                 ` Stephen Berman
2015-10-24 17:47                   ` Alan Mackenzie
2015-10-24 19:10                     ` Stephen Berman
2015-10-24 19:28                       ` Alan Mackenzie
2015-10-25  0:00                         ` pcase docstring tweaks (was: Question on pcase) Michael Heerdegen
2015-10-27 14:54                           ` pcase docstring tweaks Michael Heerdegen
2015-10-27 18:57                             ` Stefan Monnier
2015-10-27 20:14                               ` Michael Heerdegen
2015-10-28  3:15                             ` Richard Stallman
2015-10-28 17:08                               ` Michael Heerdegen
2015-10-24 17:00                 ` Question on pcase Drew Adams
2015-10-24 17:22                   ` Alan Mackenzie
2015-10-24 17:36                     ` Drew Adams
2015-10-24 20:03                     ` Johan Bockgård
2015-10-24 23:11                       ` Michael Heerdegen
2015-10-26 15:55               ` Oleh Krehel
2015-10-26 16:07                 ` Michael Heerdegen
2015-10-27  8:42                   ` Oleh Krehel
2015-10-26 16:20                 ` Michael Heerdegen
2015-10-27  8:42                   ` Oleh Krehel
2015-10-27 14:27                     ` Michael Heerdegen
2015-10-27 14:47                       ` Michael Heerdegen
2015-10-28 18:05                         ` Michael Heerdegen
2015-10-29  9:44                           ` Oleh Krehel
2015-10-30  1:11                             ` Michael Heerdegen
2015-10-26 16:35                 ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151024090146.GA1849@acm.fritz.box \
    --to=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=michael_heerdegen@web.de \
    --cc=ohwoeowho@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).