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

NIHIL is an arity-0 COMMENT function that just vanishes, 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...

However...

This kind of application no longer works, as there's been a necessary casualty of scaling back what "invisibility" could do inside of a single step. :frowning:

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

Making Invisible Functions (e.g. COMMENT, ELIDE)

So to have invisibles vaporize anything, you'd need to go through a COMPOSE or REDUCE step and then EVAL the result... so not that succinct. CASCADE 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