Post Reply 

[Script-Fu Error] set! function is interpreted as an illegal function

Sep 11, 2014, 19:32
Post: #1
[Script-Fu Error] set! function is interpreted as an illegal function
[Script-Fu Error] set! function is interpreted as an illegal function within an if expression nested in a while expression.


I'm a novice GIMP Script-Fu scripter, who started scripting a few days ago: while scripting my very first GIMP Script-Fu script, I ran into an error that I've been having a great deal of trouble resolving.

I have written and tested a sub-procesure within my script, which checks the validity of the input parameters given by the user, on a Windows 7 computer with GIMP 2.8.10.

Code:
(define-with-return (check-output-sub-range-lower-limit-list-validty
        inNumberOfOutputSubRanges
        inOutputSubRangeLowerLimitList
    ) ;End of check-output-sub-range-lower-limit-list-validty function declaration.
(let*
    (
        (localTestResult #t)
        (localOutputSubRangeLowerLimitList inOutputSubRangeLowerLimitList)

        (localNumberOfOutputSubRanges inNumberOfOutputSubRanges)

        (localOutputSubRangeIndex 1)
    ) ;End of local variable declarations.


    ;-------------------------------------------------------;
    ;Check if the number of output sub-range lower limits
    ;is correct.  If not, return false.
    ;-------------------------------------------------------;
    (if
        (or
            (<= inNumberOfOutputSubRanges 1)
            (> inNumberOfOutputSubRanges 10)
        )

        ;Invalid number of output sub-range lower limits.
        (return #f)
    )


    ;-------------------------------------------------------;
    ;Check if all of the output sub-range lower limits are valid.
    ;-------------------------------------------------------;
    (while (< localOutputSubRangeIndex localNumberOfOutputSubRanges)
           (if
            (<
                (car localOutputSubRangeLowerLimitList)
                (car (cdr localOutputSubRangeLowerLimitList))
            )

            (
                (set! localOutputSubRangeLowerLimitList
                      (cdr localOutputSubRangeLowerLimitList)) ;Highly likely to cause error if reached (this execution branch is not yet tested).
                (set! localOutputSubRangeIndex (+ localOutputSubRangeIndex 1)) ;Highly likely to cause error if reached (this execution branch is not yet tested).
            )

            (
                (set! localTestResult #f) ;The culprit.
                (set! localOutputSubRangeIndex localNumberOfOutputSubRanges) ;The culprit.
            )
        )
    )
    localTestResult
) ;End of let* block.
) ;check-output-sub-range-lower-limit-list-validty function defintion end.

I've gotten the following error, upon trying the sub-procedure with inNumberOfOutputSubRanges set to 2, and inOutputSubRangeLowerLimitList to (0 0 0 0 0); in the main procedure of my Script-Fu script, both of the sub-procedure input variables were set to the Script-Fu provided variables from the user-input interface.

Quote:Fuzzy Intensity Spectrum Compression Message

Error while executing script-fu-fuzzy-intensity-spectrum-compression:

Error: ( : 1) illegal function

So, in my quest to localize the issue, I had tried inserting (gimp-message) expressions in a few places, and have located where the error was being thrown at: the (set!) functions within the false-case clause of the if expression within the while expression, commented as "the culprits", were causing the errors. When I commented out those two (set!) functions, there was no error during execution.

I can't figure out (yet) why the (set!) functions are interpreted as illegal functions within that context.

What is the cause of this error? How can I resolve it?
Find all posts by this user
Quote this message in a reply
Sep 11, 2014, 20:43 (This post was last modified: Sep 11, 2014 20:44 by paynekj.)
Post: #2
RE: [Script-Fu Error] set! function is interpreted as an illegal function
Your mistake is to try and group multiple function calls using parentheses:
Code:
(if (< 1 2)
  (
     (set! first 1)
     (set! second 2)
  )
  (
     (set! first 0)
     (set! second 1)
  )
)
Because Scheme then tries to interpret the contents of the parentheses as a function to execute.
If you make it like this it should work:
Code:
(if (< 1 2)
  (begin
     (set! first 1)
     (set! second 2)
  )
  (begin
     (set! first 0)
     (set! second 1)
  )
)
Scheme then knows that what you have grouped together in the "begin" are separate functions.

Kevin
Find all posts by this user
Quote this message in a reply
Sep 11, 2014, 20:54
Post: #3
RE: [Script-Fu Error] set! function is interpreted as an illegal function
With "begin", it works perfectly now. Thank you so much. Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Need help in running a gui script-fu via command line eyalzek 2 223 Oct 4, 2014 14:05
Last Post: eyalzek
  Color menuitems in script or plugin Barbie 4 379 Sep 29, 2014 09:51
Last Post: paynekj
  script-fu ok in gimp, not in commad line dominique 1 260 Sep 28, 2014 03:18
Last Post: dominique
  Script fu and Color to alpha john 4 388 Sep 20, 2014 08:46
Last Post: rich2005
  Setting text markup from python script Burbly 1 286 Sep 16, 2014 12:29
Last Post: Burbly

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS