This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

question about define-syntax


The simplified example:

;; convert list to list of pairs

(define-syntax make-pair-list
 (syntax-rules ()
   ((_ any)
    (error "Broken arguments count for pair-list"))
   ((_ name value)
    (cons (cons name value) ()))
   ((_ name value . args)
    (cons (cons name value) (make-pair-list . args)))))

;; call function with list of pairs

;; this is wrong:
(define-syntax func-with-pairs
 (syntax-rules ()
   ((_ func . args)
    (func . (make-pair-list . args)))))
;; result of (func-with-pairs list 1 2 3 4)
;; is (#<macro make-pair-list> 1 2 3 4), not ((1 . 2) (3 . 4))

;; this is right
(define-syntax func-with-pairs
 (syntax-rules ()
   ((_ func . args)
    (apply func (make-pair-list . args)))))
;; but why need `apply`?


How write macro without `apply`?


Thanks!

--
WBR, Yaroslav Kavenchuk.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]