From simon.urbanek at r-project.org  Thu Oct 29 19:47:45 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 29 Oct 2009 14:47:45 -0400
Subject: [Rd] Help with lang4
In-Reply-To: <4AE9D739.2060804@userprimary.net>
References: <fc212e850910290700u4cb2be67n53d7efbfa787e7b6@mail.gmail.com>	
	<4AE9A328.5050305@userprimary.net>
	<fc212e850910290738y1a6b901dk611f49b47e0893fa@mail.gmail.com>
	<4AE9D739.2060804@userprimary.net>
Message-ID: <4DF619B0-F6FB-4BA3-9706-A263B427F039@r-project.org>


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



[Rd] Help with lang4
Simon Urbanek