unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* srfi-26 (cut, cute)
@ 2002-10-03 20:45 Daniel Skarda
  2002-10-05  8:55 ` Neil Jerram
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Skarda @ 2002-10-03 20:45 UTC (permalink / raw)


Hello,

  during summer I browsed through srfi specification and as an excercice 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-10-05 20:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-03 20:45 srfi-26 (cut, cute) Daniel Skarda
2002-10-05  8:55 ` Neil Jerram
2002-10-05 20:15   ` Rob Browning

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).