Search code examples
schemelispgimpscript-fu

Error in conditional (cond ...) script-fu


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.


Solution

  • 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.