chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] need help with hygienic macros


From: Jörg F . Wittenberger
Subject: [Chicken-users] need help with hygienic macros
Date: 12 May 2013 14:41:05 +0200

Hi all,

not exactly chicken related; but I hope someone here can help me.

I'm trying to replace an unhygienic macro with a syntax-rules
based version.  Just I can't.

What I need is a sub-macro.
http://community.schemewiki.org/?scheme-faq-macros#H-1tseqi3

I want to have a define-alike to create procedures with
a certain signature.  Within the body of the created procedure
I need some syntax to access the parameters of the created
procedure.  The purpose however is to *not* repeat the
parameter list in the definitions (since that's what might
change, hence the definer macro to hide the precise signature).

Here my current state of affairs:

;; The definer:

(define-syntax deftig
 (syntax-rules ()
   ((_ name . body)  ;; Within this "body" I want some rewrites.
    (define name
      (lambda (x y)
         (let-syntax
             ((pinapple
               (syntax-rules ()
                 ((_ ((p v) ...) . body)
                  (let-syntax ((helper (syntax-rules ()
((_ p ...) (begin . body))))) (helper v ...))))))

          ;; trying to bind "foo" and "gosh" within "body" here

           (pinapple ((foo (x y)) (gosh y)) . body)))))

;; This alternate version did not grok it either:

   ((_ "pinapple" ((p v) ...) . body)
    (let-syntax ((helper (syntax-rules ()
((_ p ...) (begin . body))))) (helper v ...)))
   #;((_ name body ...)
    (define name
      (lambda (x y)
         (deftig "pinapple" ((foo (x y)) (gosh y)) body ...))))
   ))

;; An example of intended usage:

(define (foog x) (* x 2))

;; "foo" and "gosh" ought to be replaced, but aren't.

(deftig bar (foo) (foog 2) (foog 2.5) (let ((n (gosh))) (foog n)) 'phar)


----

The pinapple is actually stolen from let-alias
http://community.schemewiki.org/?scheme-faq-macros#H-uren6
which was the closes thing I could find so far.

But it seems only to get close to the job when used in the
let-syntax way as above.  At least I've been able to
get partial results.  But no flowers.

Any help very much appreciated.

/Jörg




.......





reply via email to

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