Implement SRFI 26 cut and cute procedures
Submitted by saulgoode
Created attachment 267979 Script-fu implementation of SRFI 26
SRFI 26 defines the two functions 'cut' and 'cute' that would prove useful to script writers.
It is a common paradigm in writing code to employ temporary lambdas where the goal is to invoke a procedure with multiple parameters using only a specialized of those parameters. The 'cut' and 'cute' functions could simplify this process and make the code more readable.
Both functions behave similarly with 'cut' being implemented as a macro and 'cute' being implemented as a procedure. The main difference is that the "non-slots" in 'cute' are evaluated lexically, whereas with 'cut' they are evaluated when the function is ultimately executed.
Here a couple of examples of how they might be used in scripts.
Allow mapping of multi-parameter procedures: (map (cute gimp-item-set-visible <.> FALSE) all-layers)
Simplify interfaces of procedures using default arguments: (define rect-select ; ex: (rect-select x y w h) (cut gimp-rect-select image <.> <.> <.> <.> CHANNEL-OP-REPLACE FALSE 0) ) (define map-sphere ; ex: (map-sphere layer zoom rot-y rot-z) (cut plug-in-map-object RUN-NONINTERACTIVE image ; the value of the 'image' variable at runtime! <.> ; layer (a supplied parameter) 1 0.5 0.5 2 0.5 0.5 <.> ; zoom (a supplied parameter) 0 0 -1 0 1 0 0 <.> ; rot-y (a supplied parameter) <.> ; rot-z (a supplied parameter) 2 '(255 255 255) -0.5 -0.5 2.0 0 0 0 0.3 1.0 0.5 0.5 27.0 TRUE FALSE FALSE TRUE 1.0 0.5 0.5 0.5 1.0 -1 -1 -1 -1 -1 -1 -1 -1 ))
It might be possible to implement 'cute' as a macro to make it a little more efficient, but Script-fu is not generally optimized for speed. Also, the implementation of 'cut' is not completely hygienic in that the procedures 'apply' and 'cute' must not be redefined in the environment in which the lambda is ultimately executed. (The SRFI 26 implementations are hygienic but Script-fu does not support R5RS syntax-rules.)
Patch 267979, "Script-fu implementation of SRFI 26":
Version: git master