guile-user
[Top][All Lists]
Advanced

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

Strange error from syntax transformer


From: Panicz Maciej Godek
Subject: Strange error from syntax transformer
Date: Thu, 3 Sep 2015 00:40:19 +0200

Hi,
As I wrote in another post, I've cut out some more mature pieces of my personal library to a separate module. The module uses (ice-9 match) library and replaces the lambda binding with mlambda (the greek letter came from emacs, but they're just regular words):

(define-syntax mlambda
  (λ (stx)
    (syntax-case stx ()

      ((_ (first-arg ... last-arg . rest-args) . body)
       (and (every identifier? #'(first-arg ... last-arg))
            (or (identifier? #'rest-args) (null? #'rest-args)))
       #'(λ (first-arg ... last-arg . rest-args) . body))

      ((_ arg body ...)
       (or (identifier? #'arg) (null? #'arg))
       #'(λ arg body ...))

      ((_ args body ...)
       #'(match-lambda* (args body ...)))
      )))

For the reason explained below, it also wraps the regular "lambda" form as "primitive-lambda":

(define-syntax primitive-lambda
  (syntax-rules ()
    ((_ . whatever)
     (λ . whatever))))

So I have another module that uses this one. It defines, among the other things, the following macro:

(define-syntax supply
  (syntax-rules ()
    ((_ (((<to-do-something-with> . <args>) <do-what> ...) ...) . <actions>)
     (let ((handlers (make-hash-table))
           (unsupported (λ details
                          (apply throw 'unsatisfied-demand
                                 details))))
       (hash-set! handlers (quote <to-do-something-with>)
                  (λ <args> <do-what> ...))
       ...
       (catch 'demand
         (λ () . <actions>)
         (primitive-lambda (key go-on demand . the-args)
           (go-on (apply (hash-ref handlers demand unsupported) the-args))))))))

it requires a "demand" function to be useful:

(define (demand to-do-something-with . args)
  (call/cc (λ (go-on)
             (apply throw 'demand go-on to-do-something-with args))))


When I try to expand that macro, e.g. by using the following form, it works alright.

(let ((people '()))
   (supply (((free person)
             (set! people (cons person people))))
     (let ((the-person 'Nelson-Mandela))
       (demand 'free the-person)))
   people)

However, if I replace the primitive-lambda with regular lambda (which should refer to mlambda from (ice-9 nice-9)), I get the following error:

ice-9/psyntax.scm:728:15: In procedure join-wraps:
ice-9/psyntax.scm:728:15: In procedure car: Wrong type argument in position 1 (expecting pair): #(syntax-object the-args ((m-o6xyC1TbsJRwjxP9561LW$-9754 top) #(ribcage \
() () ()) shift #(ribcage #(dummy <to-do-something-with> <args> <do-what> <actions>) #((m-o6xyC1TbsJRwjxP9561LW$-9334 top) (top) (top) (top) (top)) #("l-o6xyC1TbsJRwjxP\
9561LW$-9339" "l-o6xyC1TbsJRwjxP9561LW$-9340" "l-o6xyC1TbsJRwjxP9561LW$-9341" "l-o6xyC1TbsJRwjxP9561LW$-9342" "l-o6xyC1TbsJRwjxP9561LW$-9343")) #(ribcage () () ()) #(ri\
bcage #(x) #((m-o6xyC1TbsJRwjxP9561LW$-9334 top)) #("l-o6xyC1TbsJRwjxP9561LW$-9336"))) (hygiene extra common))

Anyone has a clue what is going on here?


Regards, 
M.

reply via email to

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