[R] return inconsistency?
peter dalgaard
pd@|gd @end|ng |rom gm@||@com
Wed Apr 30 16:12:26 CEST 2025
Nice example!
However, things do not always have a purpose beyond consistency:
Since return(...) is a function call, it gets parsed like any other function call, and can be a part of a more complicated expression.
The special semantics of terminating the caller will not take place until the return() subexpression is evaluated (which might not even happen - think function(x) quote(return(pi)) ).
Tweaking the R syntax and semantics to special-case return() might be possible, but my gut feeling is that it would just lead to complications further down the line.
- pd
> On 30 Apr 2025, at 15:27 , Ivan Krylov via R-help <r-help using r-project.org> wrote:
>
> On Wed, 30 Apr 2025 11:15:02 +0200
> Ralf Goertz via R-help <r-help using r-project.org> wrote:
>
>> If this is not an error what is its purpose?
>
> From the point of view of the R syntax, everything is an expression.
>
> One of the uses of return() being an expression is base::callCC(). The
> ability to use it inside an expression makes it possible to put it into
> a delayed-evaluation object and offer it as a continuation point to
> another function.
>
> Admittedly obscure, but sometimes useful.
>
> --
> Best regards,
> Ivan
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-help
mailing list