unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: srfe records in reworked match
Date: Wed, 21 Apr 2010 10:40:29 +0200	[thread overview]
Message-ID: <878w8hkxky.fsf@gnu.org> (raw)
In-Reply-To: 201004201514.18375.stefan.tampe@spray.se

Hello Stefan,

stefan <stefan.tampe@spray.se> writes:

> I have started to code in some record recognition into the match construct

Excellent!  :-)

Are you hacking Wright’s match as currently in Guile or Alex Shinn’s
rewrite from <http://synthcode.com/scheme/>?

> I need first to make sure that I grok the intention of the syntax!

Do the comments in (ice-9 match) and the examples in the paper that in
match.tar.gz at
<http://www.cs.indiana.edu/scheme-repository/code.match.html> help?

You could ask on comp.lang.scheme too.  :-)

> Now, one can do ...
>
> * (define rtf      (make-record-type "n" '(x y z)))
> * (define make-n   (record-constructor rtf))
> * (define v        (make-n 1 2 3))
> * (define g        (record-accessor rtf 'x))
> * (define s        (record-modifier rtf 'x))

FWIW I’d really prefer if it could work with SRFI-9 (which is purely
syntactic, so there’s no run-time record type descriptor) rather than
with Guile’s records (as above).

> * (match v ((= g 1) 'yes))    ;; This is the old behavior
> yes
>
> ;; = allow for a getter and setter argument so that we can do ...
> * (match v ((= (g s) (and (set! x.set) 
> *			  (get! x.get) 
> *			  1)) 
> *	    (begin (x.set 2) 
> *		   (x.get))))
> 2
>
> ;;Now the $ syntax work, although a lot of unpacking of accessors and 
> modifiers
> ;;are done dynamically and not at compile time.
> * (match v (($ rtf x 2 3) x))
> 2

I think it should be:

  (match v (($ n x 2 3) x))

The original API assumes that when ‘n’ appears as the record-type above,
then there exists a type predicate called ‘n?’, a procedure called ‘n-x’
to access the ‘x’ field, etc.

> * (match v (  ($ rtf 
> *		 x 
> *		 (and (set! y.set) 
> *		      (get! y.get)) 
> *		 3) 
> *	    (begin (y.set 4) 
> *		   (+ x (y.get)))))
> 6
>
> It's recursive.

OK.

So would the following work?

  (define x (make-n 1 2 (make-n (3 4 (make-n 5 6 7)))))
  (match x
    (($ n x y ($ n p q ($ n a b c)))
     (list a b c p q x y)))

As noted in Shinn’s match-cond-expand.scm, this record matching form is
not ideal:

  ;; Annoying unhygienic record matching.  Record patterns look like
  ;;   ($ record fields...)
  ;; where the record name simply assumes that the same name suffixed
  ;; with a "?" is the correct predicate.

Thanks!

Ludo’.





  reply	other threads:[~2010-04-21  8:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-20 13:14 srfe records in reworked match stefan
2010-04-21  8:40 ` Ludovic Courtès [this message]
     [not found]   ` <07487229-BEA5-49C8-B73F-83370F028513@spray.se>
2010-04-21 11:47     ` Ludovic Courtès
2010-04-22 11:13   ` Andy Wingo
2010-04-22 12:27     ` Ludovic Courtès
2010-04-22 12:52       ` Andy Wingo
2010-04-22 12:57         ` Ludovic Courtès
2010-04-22 13:48           ` Andy Wingo
2010-04-22 17:09       ` stefan
2010-04-23  7:52   ` stefan
2010-04-23  9:23     ` Ludovic Courtès
2010-04-23 20:21   ` stefan
2010-04-28  8:40     ` Ludovic Courtès
     [not found] <CCF7F725-F332-40DE-8193-65FB81ADD08C@spray.se>
2010-04-28 13:50 ` Stefan
2010-05-03 12:38   ` Ludovic Courtès
2010-05-03 13:35     ` Stefan
2010-05-03 13:51       ` Ludovic Courtès
2010-05-03 16:24         ` stefan

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=878w8hkxky.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=guile-devel@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).