Open lorenzwalthert opened 2 years ago
couple thoughts
def
and not lambda
. R's function
works closer to lambda.names()<-
and class()<-
work. They are not exactly the same, but could be used to do similar things. Thanks @nfultz. I know it's already taken for S4, but I think it would be still possible, since with S4, it's always within an expression as far as I know, e.g. x@y
, and never @y
, e.g. as the first token on a line. Right? There are symbols in R that have multiple meanings depending on the context, e.g. +
as an infix operator for two arguments or as a sign.
Would you be ok with explaining this to someone not knowing Python and that doesn't know what decorators are? :)
I think @
is a primitive so it's a special case. I guess if -
can have
a different meaning in prefix and infix form, there's no reason @
couldn't.
Another thought - R generally doesn't use significant whitespace like Python does, so not clear to me how it could know to apply a decorator to the next line.
@Colin Fay - decorators are syntax sugar for applying higher order functions. so instead of writing
a <- function(x) { ...}
a <- cache(a)
one would write
@cache
a <- function(x) { ... }
On Fri, Jan 28, 2022 at 8:29 AM Lorenz Walthert @.***> wrote:
Thanks @nfultz https://github.com/nfultz. I know it's already taken for S4, but I think it would be still possible, since with S4, it's always within an expression as far as I know, e.g. @.***, and never @y, e.g. as the first token on a line. Right?
— Reply to this email directly, view it on GitHub https://github.com/HenrikBengtsson/Wishlist-for-R/issues/131#issuecomment-1024383232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADGGTWZHDYT5CHEAK5MM2LUYK777ANCNFSM5NBFHTBA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you were mentioned.Message ID: @.***>
Potential related to this, is https://github.com/dirkschumacher/defmacro. It might provide a way to declare these this using R syntax.
For example like in Python. This would allow things like