klmr / klmr/decorator

Add prefix syntax

Open
#1 2 comments 2 reactions 1 assignee Claimed by @klmr View on GitHub
enhancement help wanted question
Dominant language
R
Stars
38
Forks
6
PR merge metrics
No merged PRs in 30d

Description

The currently supported syntax is

``` r
hello = flask$route('/') %@% function (name)
sprintf('Hello %s', name)
```

Ideally, the following syntax should be supported:

``` r
flask$route('/') %@%
hello = function (name)
sprintf('Hello %s', name)
```

Unfortunately, I’m not sure that this is workable with the R syntax rules. The following at least works:

``` r
decorator %@%
hello = function (name)
sprintf('Hello %s', name)
```

To make this work, all that’s necessary is to provide ``%@%<-``. However, when applying this to a decorator that’s not a simple identifier, R throws the following error:

> target of assignment expands to non-language object

The reason for this is logical; R allows assignments of the form `f(arguments) = value`, provided that the function`f<-` exists. However, this only works if the first argument to `f` is a simple identifier, since R will ultimately re-assign an object to that first argument (see [R’s subset assignment documentation](https://cran.r-project.org/doc/manuals/R-lang.html#Subset-assignment)). So `f('test') = value` cannot be made to work (that despite the fact that the assignment `'test' = value` is valid in R!).

Making this work may therefore require (backwards-compatible) changes to the R parser. Good luck with that.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.