Help a guy out!

Both because I need it and as an exercise in learning
SYNTAX-CASE I have tried for hours to write a Common
Lisp like DEFINE-MACRO.  I could not get around how to use/modify/
whatever:

(define lisp-transformer
  (lambda (p)
    (lambda (x)
      (syntax-case x ()
        ((keyword . rest)
         (datum->syntax (syntax keyword)
                        (p (syntax->datum x))))))))

nor how to change the implementation in the PLT Scheme
module "defmacro.ss".

Finally, after a lot of headbanging, I have this:

;; this-file.sls --

(import (ikarus)
        (srfi lightweight-testing))

(check-set-mode! 'report-failed)

(define-syntax define-macro
  (lambda (incoming)
    (syntax-case incoming ()
      ((_ (?name ?arg ...) ?form ...)
       (syntax
        (define-macro ?name (lambda (?arg ...) ?form ...))))
      ((_ ?name ?func)
       (syntax
        (define-syntax ?name
          (lambda (x)
            (syntax-case x ()
              ((kwd . rest)
               (datum->syntax #'kwd (apply ?func (cdr (syntax->datum
x))))))))))
      )))

(check
 (let ()
   (define-macro (proof a b c)
     `(list ,a ,b ,c))
   (proof 'one 'two 'three))
 => '(one two three))

(check
 (let ()
   (define-macro (proof a b c)
     `(,a ,(+ 1 b) ,c))
   (proof list 123 'three))
 => '(124 three))

(let ()
  (define-macro (false-if-exception expr)
    `(guard (exc (else #f))
            ,expr))

  (check
   (false-if-exception (list 1 2 3))
   => '(1 2 3))

  (check
   (false-if-exception (raise 'slap))
   => #f))

(check-report)

;;; end of file

which I do not fully understand but seems to work.
Is it actually correct?

TIA

Reply via email to