1

我正在尝试做一个脚本,我正在使用理论上正确的 cond 语句,但它总是给出错误“错误:(:1)非法函数”。

这是代码:

(define (script-fu-prueba 
        edicionInteractiva) 
    (let* 
        (
            (cond 
                ( (equal? edicionInteractiva "Interactivo") (edicionInteractiva RUN-INTERACTIVE) )
                ( (equal? edicionInteractiva "No interactivo") (edicionInteractiva RUN-NONINTERACTIVE) )
            )
        )
    )
)

(script-fu-register "script-fu-prueba" 
    "<Image>/Filters/PRUEBA"
    "Prueba"
    "Author"
    "Copyright"
    "Date"
    ""

    SF-OPTION   "Interactive" '("Interactivo" "No interactivo")
)

有什么错误?

我还想在肯定和否定的情况下用多个语句做一个条件语句。

感谢您的帮助。

4

2 回答 2

1

For starters, the code shown does not follow good Lisp indentation conventions. You must not close parentheses in individual lines, they're not like curly brackets in a C-like language! Also, that let* is completely unnecessary, you're not declaring variables in it. You should use a good IDE or text editor with syntax coloring that also helps you balance the parentheses, otherwise syntax errors will be difficult to catch.

And there's a more serious problem lurking. The parameter (which appears to be a string) is called edicionInteractiva, but that's also the name of the function you want to call - that won't work, they must have different names. I renamed the parameter to modo. I believe you meant this, and notice the correct indentation and the proper way to handle unknown inputs:

(define (script-fu-prueba modo)
  (cond ((equal? modo "Interactivo")
         (edicionInteractiva RUN-INTERACTIVE))
        ((equal? modo "No interactivo")
         (edicionInteractiva RUN-NONINTERACTIVE))
        (else
         ; it's a good idea to add some error handling
         (error "Modo de edición desconocido" modo))))
于 2013-11-24T13:58:10.023 回答
0

script-fu 解释器认为您将cond其用作变量并尝试使用一些格式错误的函数调用序列对其进行初始化。看来您不需要let*语法形式;它的语法是(let ((<name1> <init1>) ...) body1 body2 ...). 请注意,您的代码cond显示为name.

另外,不要忘记这cond是一个表达式;类似的C语言<pred> ? <conseqeuent> : <alternate>。因此,您可以将您的代码提炼为:

(define (script-fu-prueba edicionInteractiva) 
  (edicionInteractiva (cond ((equal? edicionInteractiva "Interactivo")    RUN-INTERACTIVE)
                            ((equal? edicionInteractiva "No interactivo") RUN-NONINTERACTIVE)
                            (else (error "edicionInteractiva unknown")))))

编辑:正如 Óscar López 所指出的,您的使用edicionInteractiva不一致;显然是一个字符串或一个函数,不能两者兼而有之。

于 2013-11-24T14:20:33.587 回答