Thanks to all.  I think that I am sepping closer to The Truth.

Note to future readers of this thread: I will try to organise this
discussion in a section of "The Other Ikarus User's Guide" (which
by now one can find by googling "ikarus texinfo").

On Nov 9, 8:37 pm, Abdulaziz Ghuloum <[EMAIL PROTECTED]> wrote:
> Correct.  You are using a run-time variable at expand time.
> [at the time ikarus is expanding your code, it cannot know
> the value of slurp which is computed later, after the whole
> code is expanded and the expressions and definitions are
> evaluated.]

Got it.  This is different from what Guile does, and it is
probably related to the fact that Guile (up to 1.8) has no real
hygiene.  And it means that to use the same helper functions
in the body of more than one macro, the helpers have to be in
a separate library:

;; helper.sls --
;;

(library (helper)
         (export gasp)
         (import (ikarus))
         (define (gasp arg)
           arg))

;;; end of file

;; proof.sls --
;;

(import (ikarus)
        (srfi lightweight-testing)
        (for (helper) expand))

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

(define-syntax define-macro
  (lambda (macro-definition-stx)
    (syntax-case macro-definition-stx ()
      ((_ (?name . ?args) ?form ...)
       (syntax
        (define-macro ?name (lambda ?args ?form ...))))
      ((_ ?name ?func)
       (let ()
         (syntax
          (define-syntax ?name
            (lambda (macro-use-stx)
              (syntax-case macro-use-stx ()
                ((kwd . rest)
                 (datum->syntax
                  (syntax kwd)
                  (apply ?func (syntax->datum (syntax rest)))))))))))
       )
      ))

(check
 (let ()
   (define-macro (proof a . args)
     (gasp
      `(,a ,(+ 1 (car args)) ,(cadr args))))
   (proof list 123 'three))
 => '(124 three))

(check-report)

;;; end of file

"Abdulaziz Ghuloum" wrote:
>On Nov 9, 2008, at 11:49 AM, marcomaggi wrote:
>> So, with my notation, the following two are equivalent:
>
>> (datum->syntax #'kwd (apply ?func (syntax->datum (syntax rest))))
>> (datum->syntax #'kwd (apply ?func (cdr (syntax->datum x))))
>
>Yes.  And you probably should say:
>
>(syntax-case x ()
>   [(kwd rest ...)
>    (datum->syntax #'kwd (apply ?func (syntax->datum #'(rest ...))))])
>
>instead of:
>
>(syntax-case x ()
>   [(kwd . rest)
>    (datum->syntax #'kwd (apply ?func (syntax->datum #'rest)))])

This gives me an "extra ellipsis in syntax form" error because the
form is in a <syntax-case clause>, but it compiles if I quote the
ellipses with an ellipsis form:

(syntax-case macro-use-stx ()
  ((kwd rest (... ...))
   (datum->syntax (syntax kwd)
                           (apply ?func (syntax->datum #'(rest
(... ...)))))))))

I understand why it works but not why your proposal should be
better; both the ". rest" and "rest ..." subpatterns match zero or
more elements of the input, and here they both appear in cdr
position and we take the whole "rest" we do not need to
destructure it.

Reply via email to