[plt-scheme] The infamous "no #%app syntax transformer is bound" error

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Sat Jun 24 09:14:40 EDT 2006

I have run into the infamuous

  "function application is not allowed,
   no #%app syntax transformer is bound"

error, but can't figure out why.


This works:

 > (let-syntax ((let1
                 (lambda (stx)
                   (syntax-case stx ()
                     [(_ i v b)
                      (datum->syntax-object #'here
                        (list (list (syntax lambda) (list (syntax i))
                                    (syntax b))
                              (syntax v)))]))))
     (let-syntax ((or2
                   (lambda (stx)
                     (syntax-case stx ()
                       [(_ e1 e2)
                        (datum->syntax-object #'here
                          (list (syntax let1) (syntax t) (syntax e1)
                                (list (syntax if) (syntax t)
                                      (syntax t)
                                      (syntax e2))))]))))
       (let1 if 42
             (or2 if #f))))
42

Now let's put this pattern in a module embodied by plambda:

 > (module plambda mzscheme
   (provide plambda)
   (define-syntax plambda
     (lambda (so)
       (syntax-case so ()
         [(_ (id ...) b)
          #'(lambda (stx)
              (datum->syntax-object #'here
                                    (syntax-case stx ()
                                      [(_ id ...)
                                       b])))])))
   )

 > (require-for-syntax plmabda)


Now I can do this:

 > (let-syntax ((let1
                 (plambda (i v b)
                   (datum->syntax-object #'here
                      (list (list (syntax lambda) (list (syntax i))
                                  (syntax b))
                            (syntax v))))))
     (let-syntax ((or2
                   (plambda (e1 e2)
                     (datum->syntax-object #'here
                        (list (syntax let1) (syntax t) (syntax e1)
                              (list (syntax if) (syntax t)
                                    (syntax t) (syntax e2)))))))
       (let1 if 42
             (or2 if #f))))

42


I was actually expecting this to work without the
datum->syntax-object, but alas:

 > (let-syntax ((let1
                 (plambda (i v b)
                   (list (list (syntax lambda) (list (syntax i))
                                  (syntax b))
                            (syntax v)))))
     (let-syntax ((or2
                   (plambda (e1 e2)
                      (list (syntax let1) (syntax t) (syntax e1)
                            (list (syntax if) (syntax t)
                                  (syntax t) (syntax e2))))))
       (let1 if 42
             (or2 if #f))))

compile: bad syntax; function application is not allowed, because no 
#%app syntax transformer is bound in: ((lambda (if) (or2 if #f)) 42)

How can I change the definition of plambda, such that the last
example works?


-- 
Jens Axel Søgaard



Posted on the users mailing list.