Hi Yann, and welcome to the list! :)
On 04/27/2012 09:14 PM, Yann Le Du wrote:
> I tried to google my way to an
> answer, and it seems that q authorized such arity variation, but that
> Pure's compiler now explicitly forbade that.
Yes, in difference to Q, once you decide the number of parameters for a
given function in Pure, it's fixed, and the compiler will then complain
if you add an equation which defines the function with a different
number of arguments. I decided to do it that way mainly because it
catches a common type of errors. Also, currying and variadic really
don't go that well together, so while it's possible to do that kind of
thing in Q, it's not really that straightforward to get it right and
such use cases are often somewhat obscure.
NB: Another technical reason for doing it that way is that it makes it
much easier to compile a Pure function to efficient LLVM IR code. While
LLVM IR allows variadic functions, last I checked they weren't available
with the fastcc calling convention, which Pure uses internally, e.g., to
optimize tail calls.
> Am I right then to conclude that I need to define and name differently
> as many max as I expect the number of arguments to be ?
No, you'd define a variadic function in exactly the same way as in Q
using tuple arguments (or using any other aggregate that you find
convenient, such as lists or vectors). E.g.:
namespace my;
max (x,y) = if x<y then y else x when y = max y end;
max x = x otherwise;
Note that I defined this in a separate namespace so that it doesn't
collide with the max function in the standard library.
Albert
--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email:
Dr.G...@t-online.de,
a...@muwiinfa.geschichte.uni-mainz.de
WWW:
http://www.musikinformatik.uni-mainz.de/ag