Looking into a *usermode* POINTFREE

One of the big ideas here is giving people options vs. there being a "one way to do it", and I think having placeholders would fit a lot of people's intuition better than other transformations...

However... parameter reordering is an important thing, and it's been slowly moving up on the agenda...so I went ahead and added a REORDER primitive.

It doesn't have quite the syntax form you used with FLIP in the box. But it's a building block for making FLIP-like things.

I actually put in a little bit of a hacky twist to REORDER so that it would ignore refinements. That way you could do things like REVERSE a parameter list. e.g. when you ask for PARAMETERS OF the APPEND operation, you get the optional parameters too:

>> parameters of :append
== [series value /part /only /dup /line]

So if you tried to build a FLIP command that reversed the parameter list, you'd have to filter them out. But having reorder do that automatically makes it a bit easiser.

>> reeval reorder :append (reverse parameters of :append) <item> [a b c]
== [a b c <item>]

Notice that making a function doesn't re-dispatch it, so you have to reeval-uate it. It works for other types, too.

>> reeval second [a: b: c:] 10 + 20
== 30

>> b
== 30

POINTFREE is still under development thought here (with interim experiments in various levels of disrepair). But in the meantime we have MACRO:

flip: macro ['name [word!] <local> action] [
    action: ensure action! get name
    reduce [reorder :action (reverse parameters of :action)]
]

I have it do the quoting (so it takes ['name [word!]] instead of [action [action!]]... so that the call matches your example's syntax:

>> flip append <item> [a b c]
== [a b c <item>]

>> flip subtract 10 1
== -9

Oege worked with my group briefly at Microsoft Research many, many years ago...seems he's gone on to building a fairly popular thing (LGTM). I tried to use it, but it doesn't work on forked repos. Maybe I'll try it again when this project gets renamed/re-launched...whenever that is... :hourglass:

2 Likes