Using Invisibles To Opt Out of Functions In a Chain

One idea for using invisibles is to chain functions where you make some functions disappear from the chain if they're not needed.

Imagine an image processor where you apply sequential effects but only the ones specify as refinements.

imagemagick: func [ data 
    /monochrome
    /sharpen
    /blur
    /pixelise
][
    ... code ..
    sharpen: either sharpen [:sharpenf] [:nihil]
    blur: either blur [:blurf] [:nihil]
    pixelise: either pixelize [:pixelf] [:nihil]

    return sharpen blur pixelise data
]

imagemagick/sharpen imagedata

...giving a much cleaner look. If the refinements are absent, the functions just disappear.

1 Like

This is a creative idea... and I think this sort of creativity is what makes the language fun... having so many different ways to attack problems!

But in this particular case, you could actually use CHAIN to build the composite function, and it might be more obvious:

imagemagick: func [
    data 
    /monochrome
    /sharpen
    /blur
    /pixelise
][
     ... code ..
    return run chain reduce [
        if sharpen [:sharpenf]
        if blur [:blurf]
        if pixelize [:pixelf]
    ] data
]

This kind of application no longer works, as it was a casualty of scaling back what "invisibility" could do. :frowning:

"Non-Interstitial Invisibility" was removed for good reasons that are outlined here:

Invisibility Reviewed Through Modern Eyes

So to have invisibles vaporize anything, you'd need to go through a COMPOSE or REDUCE step and then DO the result... so not that succinct. CHAIN is a better bet here.

Though at time of writing, you can get the original intent with macros:

sharpen: macro [] [return if sharpen [sharpenf]]
blur: macro [] [return if blur [blurf]]
pixelise: macro [] [return if pizelize [pixelf]]

return sharpen blur pixelise data