1

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.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
uSOf
  • 19
  • 2

2 Answers2

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))))
Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • The code is the portion of the source code where the error occurred, so I left the "let *". 'edicionInteractiva' is a string parameter, although I understand that it is better to rename it to a new variable. Thanks for the help. – uSOf Nov 24 '13 at 17:57
  • @uSOf fair enough, but all the other comments still apply. When posting questions, make sure to post them as [SSCCE](http://sscce.org) – Óscar López Nov 24 '13 at 17:59
0

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.

GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • Thank you very much. Can I ask what is the equivalent to the following code? if (condition1) { function1; function2; } else { function3; function4; } – uSOf Nov 24 '13 at 18:03
  • @uSOf (if condition1 (begin function1 function2) (begin function3 function4)) 'begin' is a procedure/macro that forces sequential evaluation of each of its arguments from left to right, and returns the value of the last argument evaluated. In the cond form each clause is wrapped in an implicit begin. Also the define special form is also so wrapped, so you can do (cond (condition1 function1 function2) (else function3 function4)) – WorBlux Nov 24 '13 at 19:27
  • @WorBlux It appears that uSOf asked that second question in [What is the equivalence in scheme for 'if'?](http://stackoverflow.com/q/20179892/1281433). – Joshua Taylor Nov 25 '13 at 19:36