From m|kkm@rt @end|ng |rom protonm@||@com  Mon Nov  6 20:54:24 2023
From: m|kkm@rt @end|ng |rom protonm@||@com (mikkmart)
Date: Mon, 06 Nov 2023 19:54:24 +0000
Subject: [Rd] New syntax for positional-only function parameters?
Message-ID: <w-ucjjtNdxQhl8Zu_e2FPoUCgc_P2TH5EXER3li56cz76Zt6YjohZrns85_ZaNLITdRwiSkqPGN7tPmheYu-N4kZNX0MhRtgE64ysN8C6Zc=@protonmail.com>

Dear List,

I'm writing to gauge interest in new syntax for positional-only
function parameters to be added to R.

The pattern of functions accepting other functions as inputs and
passing additional ... arguments to them is prevalent throughout
the R ecosystem. Currently, however, all such functions must one
way or another tackle the problem of inadvertently passing arguments
meant to go to ... as arguments to the function itself instead.

The typical workaround is to use somehow obfuscated names for the
parameters in the main function in order to make such collisions
unlikely. For example lapply() and friends with signatures like:

    function (X, FUN, ...)

In practice this pattern avoids many collisions, but it cannot
guarantee that they won't happen. It would seem to me preferrable
to avoid the root cause of the issue altogether by having the
language feature of declaring function parameters as positional-only.

Python's PEP 570 discusses the same issue in the context of Python [1].

Concretely, borrowing syntax from Python, the proposal would be
to have something along the lines of:

    g <- function(x, f, /, ...) match.call()
    g(1, f, x = 2) == quote(g(1, f, x = 2))

Rather than the current situation of:

    g <- function(x, f, ...) match.call()
    g(1, f, x = 2) == quote(g(x = 2, f = 1, f))

Given the prevalence of the issue, is this something that you would
see as worth pursuing for R?

Best regards,

Mikko

[1]: https://peps.python.org/pep-0570/



[Rd] New syntax for positional-only function parameters?
mikkmart