[racket] keep bindings in unhygienic macros?

From: Ismael Figueroa Palet (ifigueroap at gmail.com)
Date: Tue Jul 19 14:06:36 EDT 2011

Hi all, I'm trying to implement some simple macros to use monads in racket
using a Haskell-like do notation. I have the following macros, and my
problem is that I want the do macro to capture the bind identifier created
by with-monad, and in each recursive step of the do macro expansion keep the
same identifier. I don't know it is possible, I tried using (with-syntax
((bind (datum->syntax 'bind) ))) but it doesn't work.

Thanks

(module monad racket
  (provide with-monad do)

  (define-syntax-rule (with-monad (<unit-f> <bind-f>) <body>)
    (let ((unit <unit-f>)
          (bind <bind-f>))
      <body>))

  (define-syntax (do stx)
    (syntax-case stx (let let* letrec letrec* <-)
      ((do s) #'s)
      ((do (x <- s) ss ...) #'(bind (lambda (x) (do ss ...)) s))
      ((do (let bs) ss ...) #'(let bs (do ss ...)))
      ((do (let* bs) ss ...) #'(let* bs (do ss ...)))
      ((do (letrec bs) ss ...) #'(letrec bs (do ss ...)))
      ((do (letrec* bs) ss ...) #'(letrec* bs (do ss ...)))
      ((do s ss ...) #'(bind s (lambda (_) (do ss ...))))))
  )

-- 
Ismael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110719/fdf21a09/attachment.html>

Posted on the users mailing list.