unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Skarda <0rfelyus@ucw.cz>
Cc: guile-devel@gnu.org
Subject: Re: srfi-26
Date: Thu, 15 Jan 2004 10:36:45 +0100	[thread overview]
Message-ID: <m0oet5mu36.fsf@hobitin.ucw.cz> (raw)
In-Reply-To: <878ykauf96.wl@strelka.synthcode.com> (Alex Shinn's message of "Thu, 15 Jan 2004 11:17:41 +0900")

Hello,

  srfi-26 and cut/cute are indeed cute macros. I sent my implementation to
guile-devel about fourteen months ago, but it seems nobody cared to commit
it to CVS (so I wish you good luck ;-)

0.

From: Daniel Skarda <0rfelyus@ucw.cz>
Subject: srfi-26 (cut, cute)
To: guile-devel@gnu.org, guile-user@gnu.org
Date: 03 Oct 2002 22:45:55 +0200

Hello,

  during summer I browsed through srfi specification and as an exercise I
implemented srfi-26 (curry-which-is-not-curry :-). I hope somebody with
write access to CVS will like it and commit it.

  I found cut and cute macros very handy (they usually safe you a lot of
boring typing and screen space :-) so maybe they should be also part of
ice-9/boot-9.scm.

Have a nice day,
0.

ps: The reference implementation uses define-syntax instead of define-macro.
I chose define-macro since I prefere this way of writing macros and
(use-modules (ice-9 syncase)) doubles guile startup time (at least on my comp).

;--- srfi/srfi-26.scm: ----------------------------------------------------------

(define-macro (cut slot . slots)
  (let loop ((slots	(cons slot slots))
	     (params	'())
	     (args	'()))
    (if (null? slots)
	`(lambda ,(reverse! params) ,(reverse! args))
      (let ((s	  (car slots))
	    (rest (cdr slots)))
	(case s
	  ((<>)
	   (let ((var (gensym)))
	     (loop rest (cons var params) (cons var args))))
	  ((<...>)
	   (if (pair? rest)
	       (error "<...> not on the end of cut expression"))
	   (let ((var (gensym)))
	     `(lambda ,(append! (reverse! params) var)
		(apply ,@(reverse! (cons var args))))))
	  (else
	   (loop rest params (cons s args))))))))

(define-macro (cute . slots)
  (let ((temp (map (lambda (s) (and (not (memq s '(<> <...>))) (gensym))) slots)))
    `(let ,(delq! #f (map (lambda (t s) (and t (list t s))) temp slots))
       (cut ,@(map (lambda (t s) (or t s)) temp slots)))))


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  reply	other threads:[~2004-01-15  9:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-15  2:17 srfi-26 Alex Shinn
2004-01-15  9:36 ` Daniel Skarda [this message]
2004-01-21  0:44   ` srfi-26 Marius Vollmer
2004-01-23  0:44     ` srfi-26 Kevin Ryde
2004-01-24 10:22       ` srfi-26 Daniel Skarda
2004-02-28 20:15   ` srfi-26 Kevin Ryde
2004-02-29 10:04     ` srfi-26 Daniel Skarda
2004-03-01 21:10       ` srfi-26 Kevin Ryde
2004-01-15 22:08 ` srfi-26 Kevin Ryde
2004-01-16  3:28   ` srfi-26 Alex Shinn
2004-01-16  4:13     ` srfi-26 Paul Jarc
2004-01-16 18:53       ` srfi-26 Greg Troxel
2004-01-19  8:22         ` srfi-26 Alex Shinn
2004-01-19 16:43           ` srfi-26 Stephen Compall

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=m0oet5mu36.fsf@hobitin.ucw.cz \
    --to=0rfelyus@ucw.cz \
    --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).