compiler question ?

luc.taesch <>
Wed Oct 11 17:54:31 CEST 2000


cool.and what about lists or tuples?

f({A,B})->{g(A),B}. is B copied ?

g([H¦T])-> [k(H) ¦ T]. is T copied ? ( forget about tail recursiveness, can 
unmodified part of list be not copied ?
 	

> -----Original Message-----
> From: bjorn [mailto:]
> Sent: Mittwoch, 11. Oktober 2000 17:43
> To: Taesch, Luc
> Cc: erlang-questions; bjorn
> Subject: Re: compiler question ?
> 
> 
>  writes:
> 
> > is the compiler smart enough to detect that something is 
> unchanged, and then 
> > not copy it again ( on stacks, or whatever )
> > 
> > f(A) ->2* g(A).
> > 
> > is A copied on the stack, or just passed around ? ( Ais big 
> in my case, and 
> > quite deep recursion is happenning)
> 
> The Beam compiler only saves variables on the stack if they 
> will actually
> be used later in the same function. In your case, A will not 
> be saved on
> the stack.
> 
> > 
> > generally speaking , in FP , are things passed around as 
> values or pointer ?
> > 
> 
> It depends on the type. In Erlang we use 32 bits words that 
> can contain
> either a value (for instance an integer or an atom), or 
> pointer to complex
> terms likes list cells or tuples. In both cases there a tag bits that
> indicates the type.
> 
> /Bjorn
> -- 
> Björn Gustavsson            Ericsson Utvecklings AB
>       ÄT2/UAB/F/P
> 			    BOX 1505
> +46 8 727 56 87 	    125 25 Älvsjö
> 




More information about the erlang-questions mailing list