guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v3] docs/match: pattern matcher example makeover


From: Blake Shaw
Subject: Re: [PATCH v3] docs/match: pattern matcher example makeover
Date: Fri, 03 Feb 2023 17:05:11 +0700

David Pirotte <david@altosw.be> writes:
> Not at all - and quite annoying. imo.
> So i'd 'vote' not to use them anywhere in the guile reference manual

take the following functions in both styles:

(let unwrap ((peel '(((((unnest arbitrary nestings))))))) 
  (match-let* (((core ...)) peel)
               ((wrapper ...) core))
    (if (> (length wrapper) 1) 
        wrapper 
        (unwrap wrapper))))

(let ()
  (define-record-type person
    (make-person name friends)
    person?
    (name    person-name)
    (friends person-friends))

  (letrec ((alice (make-person "Alice" (delay (list bob))))
           (bob (make-person "Bob" (delay (list alice)))))
    (match alice
      (($ person name (= force (($ person "Bob"))))
       (list 'friend-of-bob name)))))

(let unwrap ([peel '(((((unnest arbitrary nestings)))))]) 
  (match-let* ([([core ...]) peel]
               [(wrapper ...) core])
    (if (> (length wrapper) 1) 
        wrapper 
        (unwrap wrapper))))

(let ()
  (define-record-type person
    (make-person name friends)
    person?
    (name    person-name)
    (friends person-friends))

  (letrec ([alice (make-person "Alice" (delay (list bob)))]
           [bob   (make-person "Bob" (delay (list alice)))] 
    (match alice
      [($ person name (= force (($ person "Bob"))))
       (list 'friend-of-bob name)])))

Without copy and pasting, which have errors, and where?

My wager is that unless you are already quite well adjusted
to lisp, its much easier to catch the errors in the "Indiana"
style examples, and if you are quite well adjusted to lisp,
you aren't really impacted by these conventions in documentation
in any concrete, meaninglful way. 

> It makes the code appear as if it was another language, and requires
> you train yourself to ignore them - as they actually do _not_ have any
> specific meaning, but nonetheless 'pretend they do', by their mere
> presence, and this causes a reading nuisance.

Well, these conventions can be found throughout the gamut of scheme
literature going back to the 80s, and some of the largest scheme
projects, such as Chez, Racket, etc. employ them. So if you're
getting into Scheme, you'll necessarily encounter them, and if you
haven't been made aware that brackets are syntactic sugar for parens
in Scheme, or if that doesn't become apparent with some quick repl
experimentation, you've probably jumped into pattern matching a bit
too quickly.  

But overall, it seems the objections against the Indiana style here
are primarily concerned with individual, current user/contributor
preferences, rather than out of a concern for the target audience,
which are newcomers.



reply via email to

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