Gimp-Fu / Tinyscheme:在函数定义宏中取消引用符号

时间:2014-08-20 21:06:23

标签: macros scheme gimp script-fu

我试图编写一个tinyscheme宏来定义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)

问题在于这一行:(define (,func-name img layer)

特别是,func-name位。当我取消引用,func-name时,我收到错误&#34;变量不是符号。&#34;但我非常确定,func-name 是一个符号,因为(symbol->string ,func-name)工作正常。

如果我不引用func-name,那么gimp&#34;程序&#34;并没有受到限制,大概是因为函数没有用正确的名称定义。程序被注册并显示在菜单中,但是当我尝试使用它时,我得到了这个&#34;未绑定的变量脚本-fu-move-layer-down&#34;错误。

想法?我猜测它与define如何评估其第一个参数有关,但我却失败了。如果您不熟悉它们,请Page on tinyscheme macros

1 个答案:

答案 0 :(得分: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)