4.4 proc->list and slow deprecated-listDownload and install the old
iccii-aquabou.scm version 1.3e in the script folder of the user.
Restart Gimp. Then call the Gimp Lambda Lib function that transforms the definition of a function into a list.
(proc->list script-fu-aqua-button2)
;-> (define (script-fu-aqua-button2 ...
fond ombre base lum reflh)))The body of the legacy
script-fu-aqua-button2 is enough long to scroll vertically the Script-Fu window.
Hereafter enclosed is the parser seeking for deprecated functions in the definition of the function
fnc:
(define (deprecated-list fnc)
(let* ( (lstDeprecFnc (cadr (gimp-procedural-db-query ".*" ".*deprecated.*" ".*deprecated.*" ".*" ".*" ".*" ".*"))))
(let loop ((lstBody (proc->list fnc)) (lstDeprecUsed nil))
(if (not-pair? lstBody) lstDeprecUsed
(let* ((item (car lstBody)))
(if (symbol? item)
(let* ( (strItem (symbol->string item))
(len (string-length strItem))
)
(if (and (> len 5) (not (member strItem lstDeprecUsed)) (member strItem lstDeprecFnc))
(loop (cdr lstBody) (cons strItem lstDeprecUsed))
(loop (cdr lstBody) lstDeprecUsed)
) )
(if (list? item)
(loop (cdr lstBody) (loop item lstDeprecUsed))
(loop (cdr lstBody) lstDeprecUsed)
) ) ) ) ) ) )
;-> deprecated-listIn the
let loop, the
loop function accepts two parameters:
- lstBody: the list of the definition of the function fnc initialized with (proc->list fnc)
- lstDeprecUsed: the list of deprecated functions used in the body of fnc initialized with nil = '() the empty list.
If
item of the list of the body of
fnc is a symbol (that is to say a word), we convert it to the string
strItem with
(symbol->string item).
So we can extract its lenght
len with
(string-length strItem).
The criteria
if (and (> len 5) (not (member strItem lstDeprecUsed)) (member strItem lstDeprecFnc)) means:
- the lenght len of the string strItem must be superior to 5 characters such as "gimp-something"
- strItem must not be already known in the list lstDeprecUsed of deprecated functions already found
- strItem must belong to the list of deprecated function of PDB: (member strItem lstDeprecFnc)
Then part: the criteria matches.
strItem is a deprecated function that we insert in the list of results by:
(cons strItem lstDeprecUsed)(loop (cdr lstBody) (cons strItem lstDeprecUsed)) continues to parse the rest of the
lstBody with partial result
(cons strItem lstDeprecUsed).
Else part: In case where
item is not a symbol but a list:
(if (list? item) (loop (cdr lstBody) (loop item lstDeprecUsed))we loop at two levels:
- (cdr lstBody): the rest of the definition of the function fnc
- (loop item lstDeprecUsed): since item is a list, we will scan each element of the list called item
This recursive call is extremely powerful. So always use
let loop instead of classical
while or
do.
Finally, if
item is not a symbol and not a list, continue with the rest of
lstBody with the current result in
lstDeprecUsed:
(loop (cdr lstBody) lstDeprecUsed)Let us call our new function
deprecated-list with as parameter the legacy function
script-fu-aqua-button2.
Please pay attention that we directly use the name of the legacy function without double quotes.
It is a procedure, a function, a closure but not a string.
(deprecated-list script-fu-aqua-button2)
![Hands on hips :hoh](./images/smilies/hoh.gif)
What's happening?
Nothing is written and the title of the title of the Script-Fu window becomes: Script-Fu (does
not answer) or something like that.
Please wait.
Then...
;-> ("gimp-perspective" "gimp-selection-layer-alpha" "gimp-drawable-set-visible" "gimp-patterns-set-pattern" "gimp-blend" "gimp-gradients-set-gradient" "gimp-image-add-layer" "gimp-palette-set-background" "gimp-palette-set-foreground" "gimp-rect-select" "gimp-ellipse-select" "gimp-patterns-get-pattern" "gimp-gradients-get-gradient" "gimp-palette-get-background" "gimp-palette-get-foreground")Generally a second call is faster.
So close Gimp, restart it and restore the same running context.
How many times the parser needed to scan this legacy function?
The function
time-stat belongs to GimpLambdaLib:
(let* ( (timeStart (gettimeofday)))
(deprecated-list script-fu-aqua-button2)
(time-stat timeStart (gettimeofday) 1)
)
;-> 27 s 053 ms 816 µs for one run ![Z's :zzz](./images/smilies/015.gif)