0

I'm attempting to write a tinyscheme macro to define four mostly-identical procedures in GIMP:

(macro (define-layer-moving-function body) 
       (let* (
              (func-name (cadr body))
              (direction (caddr body))
              (x-off (cadddr body))
              (y-off (cadddr (cdr body)))
              )
       `(begin 
        ;(define (func-name img layer) ;binding doesn't happen
        (define (,func-name img layer) ;variable is not a symbol
                (begin
                  (gimp-layer-translate layer ,x-off ,y-off)
                  (gimp-displays-flush))) 
        (script-fu-register
          (symbol->string ,func-name)
          (string-append "Translate layer " ,direction)                        
          (string-append "Moves current layer slightly " ,direction)                        
          "mugwhump"
          "Foobar License"
          "August 2014"
          ""                                    
          SF-IMAGE "Image" 0
          SF-DRAWABLE "Drawable" 0
        )

        (script-fu-menu-register (symbol->string ,func-name) "<Image>/Move Layer")
)))

(define-layer-moving-function 'script-fu-move-layer-down "down" 0 10)
(define-layer-moving-function 'script-fu-move-layer-up "up" 0 -10)
(define-layer-moving-function 'script-fu-move-layer-left "left" -10 0)
(define-layer-moving-function 'script-fu-move-layer-right "right" 10 0)

The problem is this line: (define (,func-name img layer)

Specifically the ,func-name bit. When I unquote ,func-name, I get the error "variable is not a symbol." But I'm pretty sure ,func-name is a symbol, because (symbol->string ,func-name) works fine.

If I don't unquote func-name, the gimp "procedure" doesn't get bound, presumably because the function wasn't defined with the right name. The procedure gets registered and shows up in the menu, but when I try to use it I get this "unbound variable script-fu-move-layer-down" error.

Ideas? I'm guessing it's related to how define doesn't evaluate its first argument, but I'm lost otherwise. Here's a Page on tinyscheme macros if you're not familiar with them.

4

1 回答 1

0

宏不评估它的参数,因此func-name绑定到(quote script-fu-move-layer-down)(或'script-fu-move-layer-down简称)它确实不是一个符号,而是两个符号的列表。

如果您这样称呼它,也许它会起作用?:

(define-layer-moving-function script-fu-move-layer-down "down" 0 10)
于 2014-08-21T01:07:05.523 回答