unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Vivien Kraus <vivien@planete-kraus.eu>
To: Damien Mattei <damien.mattei@gmail.com>, guile-user <guile-user@gnu.org>
Subject: Re: comparator in match pattern
Date: Wed, 28 Jun 2023 15:51:48 +0200	[thread overview]
Message-ID: <e59054af35f36df061bc520cef9d49f8cb6060be.camel@planete-kraus.eu> (raw)
In-Reply-To: <CADEOadfRrU6SW1XV_dsa9gXL0Z84_ZNA+FB3Ru3-y_VcRnqaDg@mail.gmail.com>

Le mercredi 28 juin 2023 à 15:38 +0200, Damien Mattei a écrit :
> scheme@(guile-user)> (use-modules (ice-9 match))
> scheme@(guile-user)> (match (list 1 /) ((list c (cut equal? <> /))

So, you want to match against the / symbol, not the value of a variable
named /?

The simplest case would be to use quasiquote/unquote syntax in the
pattern:

(match (list 1 '/) 
  (`(,c /) 
   c))

should give: 1, the value of c

If you don’t understand quasiquote/unquote, you can use the slightly
uglier:

(match (list 1 '/) 
  ((c '/) 
   c))

If / is the name of a variable (why not), you can do:

(use-modules (srfi srfi-26))
(let ((/ 42)) 
  (match (list 1 42) 
    ((c (? (cut equal? <> /))) 
     c)))

In any case, no need to write "list" in the pattern.

Vivien



  reply	other threads:[~2023-06-28 13:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28  8:44 comparator in match pattern Damien Mattei
2023-06-28  8:55 ` Vivien Kraus
2023-06-28 13:38   ` Damien Mattei
2023-06-28 13:51     ` Vivien Kraus [this message]
2023-06-28 13:55       ` Vivien Kraus
2023-06-28 15:10         ` Damien Mattei
2023-06-28 15:31           ` Vivien Kraus
2023-06-28 19:47             ` Damien Mattei
2023-06-28 20:52               ` Damien Mattei

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/guile/

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

  git send-email \
    --in-reply-to=e59054af35f36df061bc520cef9d49f8cb6060be.camel@planete-kraus.eu \
    --to=vivien@planete-kraus.eu \
    --cc=damien.mattei@gmail.com \
    --cc=guile-user@gnu.org \
    /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.
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).