English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
paralell assignment problem
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2005-02-08 (17:55)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] paralell assignment problem
On Wed, 2005-02-09 at 03:29, Marcin 'Qrczak' Kowalczyk wrote:
> skaller <skaller@users.sourceforge.net> writes:
> > x1,x2,x3..xn = e1,e2,e3 .. en
> >
> > where ei might contain the variables xj. (Note = here is assignment).
> If they contain calls to unknown functions, they might depend on these
> variables indirectly. 

This is true, and I need to ensure that this doesn't cause
a problem, which can be done, for example, by evaluating
the call to the unknown function first, and then using
that value. In this case, you'd be quite right that subsequent
optimisation would probably be worthless (calling a function
through a variable in Felix is quite expensive)

> So I'm not convinced that it's worth to eliminate
> temporaries in those rare cases when it's possible. After all, people
> rarely assign the value of a variable to another variable.

That may be so, however many function calls are direct,
that is, to known functions. In particular tail rec
calls typically involve passing 'old value - 1' or something
similar where no temporary is required. The actual example
which prompted this investigation is ackermann, which has two
tail-rec calls:

fun ack(x:int,y:int):int =>
  if x == 0 then y + 1
  elif y == 0 then ack(x-1, 1)
  else ack(x-1, ack(x, y-1))

No temporaries are needed in either tail call,
and either order of assignment will work.
But my actual code created 2 temporaries for each
tail call, unnecessarily.

John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net