Hello, I don't see why you say that the documentation seems to be wrong: class(args(`+`)) #[1] "function" args() on a primitive does return a closure. At least in this case it does. Rui Barradas ?s 14:05 de 07/10/2018, Peter Dalgaard escreveu:> There is more "fun" afoot here, but I don't recall what the point may be: > >> args(get("+")) > function (e1, e2) > NULL >> args(get("[")) > NULL >> get("[") > .Primitive("[") >> get("+") > function (e1, e2) .Primitive("+") > > The other index operators, "[[", "[<-", "[[<-" are similar > > The docs are pretty clear that args() on a primitive should yield a closure, so at least the documentation seems to be wrong. > > -pd > > >> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com> wrote: >> >> Hi, >> >> A short code example showing the warning might the only thing needed here: >> >> ``` >>> formals(args(`[`)) >> NULL >> >> *Warning message:In formals(fun) : argument is not a function* >>> is.function(`[`) >> [1] TRUE >>> is.primitive(`[`) >> [1] TRUE >> ``` >> >> Now with an other primitive: >> >> ``` >>> formals(args(`sum`)) >> $... >> >> >> $na.rm >> [1] FALSE >> >>> is.function(`sum`) >> [1] TRUE >>> is.primitive(`sum`) >> [1] TRUE >>> class(`[`) >> [1] "function" >> ``` >> >> Is this a feature ? >> >> >> Laurent >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel >
Note that having "function" in its class attribute does not make an object a primitive. For example:> class(`[`)[1] "function"> is.primitive(`[`)[1] TRUE> class(`rnorm`)[1] "function"> is.primitive(`rnorm`)[1] FALSE Le dim. 7 oct. 2018 ? 10:04, Rui Barradas <ruipbarradas at sapo.pt> a ?crit :> Hello, > > I don't see why you say that the documentation seems to be wrong: > > > class(args(`+`)) > #[1] "function" > > > args() on a primitive does return a closure. At least in this case it does. > > > Rui Barradas > > ?s 14:05 de 07/10/2018, Peter Dalgaard escreveu: > > There is more "fun" afoot here, but I don't recall what the point may be: > > > >> args(get("+")) > > function (e1, e2) > > NULL > >> args(get("[")) > > NULL > >> get("[") > > .Primitive("[") > >> get("+") > > function (e1, e2) .Primitive("+") > > > > The other index operators, "[[", "[<-", "[[<-" are similar > > > > The docs are pretty clear that args() on a primitive should yield a > closure, so at least the documentation seems to be wrong. > > > > -pd > > > > > >> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com> wrote: > >> > >> Hi, > >> > >> A short code example showing the warning might the only thing needed > here: > >> > >> ``` > >>> formals(args(`[`)) > >> NULL > >> > >> *Warning message:In formals(fun) : argument is not a function* > >>> is.function(`[`) > >> [1] TRUE > >>> is.primitive(`[`) > >> [1] TRUE > >> ``` > >> > >> Now with an other primitive: > >> > >> ``` > >>> formals(args(`sum`)) > >> $... > >> > >> > >> $na.rm > >> [1] FALSE > >> > >>> is.function(`sum`) > >> [1] TRUE > >>> is.primitive(`sum`) > >> [1] TRUE > >>> class(`[`) > >> [1] "function" > >> ``` > >> > >> Is this a feature ? > >> > >> > >> Laurent > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-devel at r-project.org mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-devel > > >[[alternative HTML version deleted]]
> On 7 Oct 2018, at 16:04 , Rui Barradas <ruipbarradas at sapo.pt> wrote: > > Hello, > > I don't see why you say that the documentation seems to be wrong: > > > class(args(`+`)) > #[1] "function" > > > args() on a primitive does return a closure. At least in this case it does.But in this case it doesn't:> is.primitive(get("["))[1] TRUE> class(args(get("[")))[1] "NULL" Or, for that matter:> is.primitive(`[`)[1] TRUE> class(args(`[`))[1] "NULL" -pd> > > Rui Barradas > > ?s 14:05 de 07/10/2018, Peter Dalgaard escreveu: >> There is more "fun" afoot here, but I don't recall what the point may be: >>> args(get("+")) >> function (e1, e2) >> NULL >>> args(get("[")) >> NULL >>> get("[") >> .Primitive("[") >>> get("+") >> function (e1, e2) .Primitive("+") >> The other index operators, "[[", "[<-", "[[<-" are similar >> The docs are pretty clear that args() on a primitive should yield a closure, so at least the documentation seems to be wrong. >> -pd >>> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com> wrote: >>> >>> Hi, >>> >>> A short code example showing the warning might the only thing needed here: >>> >>> ``` >>>> formals(args(`[`)) >>> NULL >>> >>> *Warning message:In formals(fun) : argument is not a function* >>>> is.function(`[`) >>> [1] TRUE >>>> is.primitive(`[`) >>> [1] TRUE >>> ``` >>> >>> Now with an other primitive: >>> >>> ``` >>>> formals(args(`sum`)) >>> $... >>> >>> >>> $na.rm >>> [1] FALSE >>> >>>> is.function(`sum`) >>> [1] TRUE >>>> is.primitive(`sum`) >>> [1] TRUE >>>> class(`[`) >>> [1] "function" >>> ``` >>> >>> Is this a feature ? >>> >>> >>> Laurent >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> R-devel at r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-devel-- 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 at cbs.dk Priv: PDalgd at gmail.com
Hello, Inline. ?s 15:07 de 07/10/2018, Laurent Gautier escreveu:> Note that having "function" in its class attribute does not make an > object a primitive.I did not say it does. What Peter said is that "args() on a primitive should yield a closure" and this return value is indeed a closure. Rui Barradas> For example: > > > class(`[`) > [1] "function" > > is.primitive(`[`) > [1] TRUE > > class(`rnorm`) > [1] "function" > > is.primitive(`rnorm`) > [1] FALSE > > > Le?dim. 7 oct. 2018 ??10:04, Rui Barradas <ruipbarradas at sapo.pt > <mailto:ruipbarradas at sapo.pt>> a ?crit?: > > Hello, > > I don't see why you say that the documentation seems to be wrong: > > > class(args(`+`)) > #[1] "function" > > > args() on a primitive does return a closure. At least in this case > it does. > > > Rui Barradas > > ?s 14:05 de 07/10/2018, Peter Dalgaard escreveu: > > There is more "fun" afoot here, but I don't recall what the point > may be: > > > >> args(get("+")) > > function (e1, e2) > > NULL > >> args(get("[")) > > NULL > >> get("[") > > .Primitive("[") > >> get("+") > > function (e1, e2)? .Primitive("+") > > > > The other index operators, "[[", "[<-", "[[<-" are similar > > > > The docs are pretty clear that args() on a primitive should yield > a closure, so at least the documentation seems to be wrong. > > > > -pd > > > > > >> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com > <mailto:lgautier at gmail.com>> wrote: > >> > >> Hi, > >> > >> A short code example showing the warning might the only thing > needed here: > >> > >> ``` > >>> formals(args(`[`)) > >> NULL > >> > >> *Warning message:In formals(fun) : argument is not a function* > >>> is.function(`[`) > >> [1] TRUE > >>> is.primitive(`[`) > >> [1] TRUE > >> ``` > >> > >> Now with an other primitive: > >> > >> ``` > >>> formals(args(`sum`)) > >> $... > >> > >> > >> $na.rm > >> [1] FALSE > >> > >>> is.function(`sum`) > >> [1] TRUE > >>> is.primitive(`sum`) > >> [1] TRUE > >>> class(`[`) > >> [1] "function" > >> ``` > >> > >> Is this a feature ? > >> > >> > >> Laurent > >> > >>? ? ? [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-devel at r-project.org <mailto:R-devel at r-project.org> mailing list > >> https://stat.ethz.ch/mailman/listinfo/r-devel > > >
Hello, This is because args(`[`) returns NULL and class(NULL) is NULL. So the question would be why is the return value of args(`[`) NULL? Rui Barradas ?s 15:14 de 07/10/2018, Peter Dalgaard escreveu:> > >> On 7 Oct 2018, at 16:04 , Rui Barradas <ruipbarradas at sapo.pt> wrote: >> >> Hello, >> >> I don't see why you say that the documentation seems to be wrong: >> >> >> class(args(`+`)) >> #[1] "function" >> >> >> args() on a primitive does return a closure. At least in this case it does. > > But in this case it doesn't: > >> is.primitive(get("[")) > [1] TRUE >> class(args(get("["))) > [1] "NULL" > > Or, for that matter: > >> is.primitive(`[`) > [1] TRUE >> class(args(`[`)) > [1] "NULL" > > -pd > >> >> >> Rui Barradas >> >> ?s 14:05 de 07/10/2018, Peter Dalgaard escreveu: >>> There is more "fun" afoot here, but I don't recall what the point may be: >>>> args(get("+")) >>> function (e1, e2) >>> NULL >>>> args(get("[")) >>> NULL >>>> get("[") >>> .Primitive("[") >>>> get("+") >>> function (e1, e2) .Primitive("+") >>> The other index operators, "[[", "[<-", "[[<-" are similar >>> The docs are pretty clear that args() on a primitive should yield a closure, so at least the documentation seems to be wrong. >>> -pd >>>> On 6 Oct 2018, at 19:26 , Laurent Gautier <lgautier at gmail.com> wrote: >>>> >>>> Hi, >>>> >>>> A short code example showing the warning might the only thing needed here: >>>> >>>> ``` >>>>> formals(args(`[`)) >>>> NULL >>>> >>>> *Warning message:In formals(fun) : argument is not a function* >>>>> is.function(`[`) >>>> [1] TRUE >>>>> is.primitive(`[`) >>>> [1] TRUE >>>> ``` >>>> >>>> Now with an other primitive: >>>> >>>> ``` >>>>> formals(args(`sum`)) >>>> $... >>>> >>>> >>>> $na.rm >>>> [1] FALSE >>>> >>>>> is.function(`sum`) >>>> [1] TRUE >>>>> is.primitive(`sum`) >>>> [1] TRUE >>>>> class(`[`) >>>> [1] "function" >>>> ``` >>>> >>>> Is this a feature ? >>>> >>>> >>>> Laurent >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> R-devel at r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-devel >