Error in conditional (cond …) script-fu

我与影子孤独终老i 提交于 2019-12-13 04:48:37

问题


I'm trying to do a script-fu and I'm using a cond statement theoretically correct, but it always gives the error "Error: ( : 1) illegal function ".

This is the code:

(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")
)

What error is there?

I also want to make a conditional statement with multiple statements in both affirmative and negative cases.

Thanks for helping.


回答1:


The script-fu interpreter thinks you are using cond as a variable and trying to initialize it with some sequence of misformed function calls. It doesn't appear that you need the let* syntactic form; its syntax is (let ((<name1> <init1>) ...) body1 body2 ...). Notice that your code makes cond appear as name.

Also, don't forget that cond is an expression; similar to the C language <pred> ? <conseqeuent> : <alternate>. You could thus distill your code to this:

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

Edit: As Óscar López notes, your use of edicionInteractiva is inconsistent; apparently a string or a function, can't be both.




回答2:


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))))


来源:https://stackoverflow.com/questions/20174176/error-in-conditional-cond-script-fu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!