guile-devel
[Top][All Lists]
Advanced

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

Re: srfi-26


From: Daniel Skarda
Subject: Re: srfi-26
Date: Thu, 15 Jan 2004 10:36:45 +0100
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/20.7 (gnu/linux)

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 <address@hidden>
Subject: srfi-26 (cut, cute)
To: address@hidden, address@hidden
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)))))




reply via email to

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