Perc: Anonymous Parameters by Association

Just to clarify. Would you be okay with

%&:x for vararg keyword arguments
%&1 for indexing into the first vararg
%&1:x for looking up :x on the first vararg
%*[0 :x] for looking up :x by get-in on the first arg
%&*[0 :x] for looking up :x by get-in in the first vararg
%1*[:x] for looking up :x by get-in on the first arg
%&1*[:x] for looking up :x by get-in in the first vararg

?

Edit: well, that doesn’t do a map or filter across the args… Was there a syntax where you expected that?

Edit 2: btw, we need an extra symbol, like *, to signal that the following thing will be a vector for a get-in path. This feature will probably require rewriting things with zippers… So I may add that in a later version, unless somebody wants to take a crack at that.

Edit 3: I’ve edited the syntax above multiple times already :slight_smile: I just realized, indices within the get-in path are different than anon-arg indices, (%1) so those need to be zeros rather than ones for indexing into the first element. In which case, I guess I’ll allow %1*[... and %&1*[... to preserve one-based indexical access for the top level. Examples above updated.

Yes, this makes sense to me. I’m not fussed about the * syntax options – I think they’re just “clever” for the sake of it, and do not make code more readable.

1 Like

On this Independence Day weekend, let’s enjoy some anonymous function syntax independence! :statue_of_liberty::us::fireworks::tada:

Announcing perc version Alpha!

Now with:

Kwargs

Keyword arguments allow you to write anonymous functions like:

{...
 :demo/configure #%/%(println "val =" %1
                              " debug =" (or %&:debug false)
                              " verbose =" (or %&:verbose false)))
 ...}

So that you can pass keyword-labeled arguments in arbitrary order; like so:

#%/%(%:demo/configure 12 :verbose true :debug true)

Possible next steps

  • spec the syntax and provide useful feedback on errors

  • provide a predicative extension mechanism via dispacio to allow user defined transforms within existing percs, so that everyone can be free to taste the unlimited, sweet, sugary nectar of anonymous liberty! :statue_of_liberty: :smiley:

  • more/better tests

  • more/better documentation

  • possible zipper implementation, allowing for transforming groups of expressions at a time

Feel free to submit PRs, issues or hit me up with any questions and happy Independence Day weekend!

1 Like

2 Likes

Lol that’s hilarious :joy: I like it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.