Karim Belabas on Mon, 06 Aug 2012 12:20:06 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Patch: default(sopath), default(outputsp[aces])


* Bill Allombert [2012-08-05 18:32]:
>>> 1) have two functions printsep() [ with \n ] and printsep1() [ without ],
>>>
>>> 3) allow user functions with a variable number of arguments and let the user
>>> define his own variant.
>>>
>>> Allowing "varargs" user functions is obviously very desirable independently of
>>> the printsep() feature, but it's currently not available, so not an immediate
>>> option.
> 
> Only options 1 and 3 are consistent with the rest of the interface.

I'm not so sure: the interface is already inconsistant

- print() / write() have a print1() / write1() variant, but printtex() /
  writetex() do not [ one must use print1(Strtex(...)) ]

- printf() doesn't have the trailing \n, like its C counterpart.
  And nobody complained so far.

- since I'm so used to printf, I find myself often mistakenly including
  a "\n" at the end of character strings output by print() ... [ ugly
  double carriage return ]

I don't see why having a printsep() behave like printf() would be
inconsistent, it's a kind of "formatted printing" after all.

If we agree that 0) is not inconsistent, then 2) makes sense because
it's annoying to be unable to print a \n without an extra separator
showing up. In fact, one could also propose never to print a separator
before a "\n" element, wherever it might appear in the argument list.

> Now, if we allow user functions with a variable number of arguments, what would be the
> syntax ? Maybe
> 
> f(a,b,c,v[])=
> {
>   print(a);
>   for(i=1,#v,print(v[i]))
>   
> }

Looks good:

  Printsep(join, v[]) =
  {
    for (i=1,#v,
      print1(v[i]);
      if (i < #v, print1(join)));
  }

Would one be able to pass it like va_lists, as in

  Printsepln(join, v[]) = Printsep(join, v[]); print();

? (Not a major feature, though.)

Cheers,

    K.B.
-- 
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`