An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20091029/612ac3d8/attachment.pl>
Help with lang4
6 messages · Abhijit Bera, Seth Falcon, Duncan Murdoch +1 more
On 10/29/09 7:00 AM, Abhijit Bera wrote:
Hi I seem to have run into a situation where I have more than 3 arguments to pass to a function from C. the following functions help me build an expression for evaluation: lang lang2 lang3 lang4 What should one do if there are more arguments than lang4 can handle?
If you take a look at the source code for those functions, something may suggest itself. R function calls at the C level are composed like in lisp: a pair-list starting with the function cons'ed with the args. + seth
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20091029/4bbf5db9/attachment.pl>
On 29/10/2009 10:38 AM, Abhijit Bera wrote:
Can't find the source to Rf_lang* series of functions. :|
They're in src/include/Rinlinedfuns.h. Duncan Murdoch
But I'm thinking it should be like this correct me if I'm wrong:
PROTECT(e=lang4(install("myfunction"),arg1,arg2,arg3);
PROTECT(SETCAR(CDR(e),portConstraints));
PROTECT(portVal=R_tryEval(e,R_GlobalEnv, NULL));
Regards
Abhijit Bera
On Thu, Oct 29, 2009 at 7:14 PM, Seth Falcon <seth at userprimary.net> wrote:
On 10/29/09 7:00 AM, Abhijit Bera wrote:
Hi I seem to have run into a situation where I have more than 3 arguments to pass to a function from C. the following functions help me build an expression for evaluation: lang lang2 lang3 lang4 What should one do if there are more arguments than lang4 can handle?
If you take a look at the source code for those functions, something may suggest itself. R function calls at the C level are composed like in lisp: a pair-list starting with the function cons'ed with the args. + seth
[[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
On 10/29/09 7:38 AM, Abhijit Bera wrote:
Can't find the source to Rf_lang* series of functions. :|
But I'm thinking it should be like this correct me if I'm wrong:
PROTECT(e=lang4(install("myfunction"),arg1,arg2,arg3);
PROTECT(SETCAR(CDR(e),portConstraints));
PROTECT(portVal=R_tryEval(e,R_GlobalEnv, NULL));
Perhaps I'm misunderstanding your goal, but I do not think this is correct.
After this call:
> PROTECT(e=lang4(install("myfunction"),arg1,arg2,arg3);
e can be visualized as:
(myfunction (arg1 (arg2 (arg3 nil))))
If you want to end up with:
(myfunction (arg1 (arg2 (arg3 (arg4 nil)))))
Then you either will want to build up the pair list from scratch or you
could use some of the helpers, e.g. (all untested),
SEXP last = lastElt(e);
SEXP arg4Elt = lang1(arg4);
SETCDR(last, arg4Elt);
Reading Rinlinedfuns.h should help some.
+ seth
On Oct 29, 2009, at 13:56 , Seth Falcon wrote:
On 10/29/09 7:38 AM, Abhijit Bera wrote:
Can't find the source to Rf_lang* series of functions. :|
But I'm thinking it should be like this correct me if I'm wrong:
PROTECT(e=lang4(install("myfunction"),arg1,arg2,arg3);
PROTECT(SETCAR(CDR(e),portConstraints));
PROTECT(portVal=R_tryEval(e,R_GlobalEnv, NULL));
Perhaps I'm misunderstanding your goal, but I do not think this is correct. After this call:
> PROTECT(e=lang4(install("myfunction"),arg1,arg2,arg3);
e can be visualized as:
(myfunction (arg1 (arg2 (arg3 nil))))
If you want to end up with:
(myfunction (arg1 (arg2 (arg3 (arg4 nil)))))
Then you either will want to build up the pair list from scratch or
you could use some of the helpers, e.g. (all untested),
SEXP last = lastElt(e);
SEXP arg4Elt = lang1(arg4);
SETCDR(last, arg4Elt);
In general, I'd avoid SETCDR -- why not use CONS/LCONS? That is the generic way to do this (I'd suggest some reading about the fundamentals of it) -- langX/listX are just convenience macros (although not really macros ..). Cheers, Simon