Re: pluralization idea that keeps bugging me

2008-01-31 Thread David Green

On 2008-Jan-26, at 9:58 am, Larry Wall wrote:

My first thought is that this is such a common idiom that we ought
to have some syntactic sugar for it:
say Received $m message\s.


I've always wanted a magic-S (and I don't think the anglocentrism  
matters, because Perl is already pretty anglocentric -- more so than  
plural S's, which apply to some other languages anyway).


Rather than extra syntax to specify alternatives, I wonder about  
having \s work with arrays (which also provides a way to deal with  
duals, for example):


say Received $_ {ox oxen oxes}\s for 1, 2, 77;
Received 1 ox
Received 2 oxen
Received 77 oxes

It might even be sophisticated enough to guess whether it should add  
es or just s, but anything beyond that probably belongs in a module.


use Locale::Lingua::EN;
say There was\s {3} ox\s;# There were 3 oxen

use Locale::Lingua::Romana::Perligata;
say {3} bos\s erat\s;# 3 boves erant

Although calling it \s loses its impact in other languages  But  
I think the underlying idea to seize on is a way to grab interpolated  
values so that there's a nice way to do tricks like that.  Preferably  
in a way that doesn't look symmetrical so you can point it before or  
behind.


say I've got $bid dollar\s, do I hear {$ + 1}?

Or using $ instead of \s:
say I'm bid $d dollar$ for @this[]$ $o @ox[]$

...except that I'm not crazy about calling it $.  (If that would  
even work.)  But something like that.  Perhaps strings should build an  
array of their interpolations?


say $a $b $c, this string contains [EMAIL PROTECTED] interpolations

(Then again, maybe there's a time to break down and use (s)printf.)


-David



Re: pluralization idea that keeps bugging me

2008-01-31 Thread Mark Overmeer
* David Green ([EMAIL PROTECTED]) [080131 08:48]:
 I've always wanted a magic-S (and I don't think the anglocentrism  
 matters, because Perl is already pretty anglocentric -- more so than  
 plural S's, which apply to some other languages anyway).

In the good old days all computer OSes were anglo-centric.  They are
not like that anymore.  But Perl still is.

 use Locale::Lingua::EN;
 say There was\s {3} ox\s;# There were 3 oxen
 
 use Locale::Lingua::Romana::Perligata;
 say {3} bos\s erat\s;# 3 boves erant
 
 Although calling it \s loses its impact in other languages  But  
 I think the underlying idea to seize on is a way to grab interpolated  
 values so that there's a nice way to do tricks like that.  Preferably  
 in a way that doesn't look symmetrical so you can point it before or  
 behind.

As I suggested in a previous mail, we can do it by making say/print
a bit smarter.  Instead of interpolating before they are called,
we let them interpolate themselves, and optionally translate.

 say I've got $bid dollar\s, do I hear {$ + 1}?

pre-parse standard call to (s)print(f)/say from

  say I've got $bid dollar, do I hear , $bid+1, ?

into

  print I've got \Ibid\E dollar, do I hear \I__ANON1__\E?\n,
  bid = $bid, __ANON1 = $bid+1, __LINE = __LINE__;

(introducting \I \E as interpolation indicators)
Isn't the (usual, existing) translation syntax a lot simpler than
you suggest?
(the rewrite will take place as first step within the print/say.
Translations must be implemented in the output layers, because only there
we know enough about character-set and end-user.  Within the program,
you do not want to be bothered with translated strings)

The default interpolation implementation for print() can be very simple.
However, now we can also make translation modules which use external
tables or databases to do the optional intelligent work.

I do not think that your
   use Locale::Lingua::Romana::Perligata;
is usable, because the translation (in general) adapts to the language
of the user of the module, not the likings of the author.  A more
general use is:
   setlocale('lat')

   open OUT, :language('lat'):encoding('latin1'), $f

-- 
   MarkOv


   Mark Overmeer MScMARKOV Solutions
   [EMAIL PROTECTED]  [EMAIL PROTECTED]
http://Mark.Overmeer.net   http://solutions.overmeer.net



Re: pluralization idea that keeps bugging me

2008-01-31 Thread David Green

On 2008-Jan-31, at 2:38 am, Mark Overmeer wrote:

* David Green ([EMAIL PROTECTED]) [080131 08:48]:
I've always wanted a magic-S (and I don't think the anglocentrism  
matters



In the good old days all computer OSes were anglo-centric.  They are
not like that anymore.  But Perl still is.


Well, they provide ways to localise text, which is good; and a lot of  
applications take advantage of it, which is better.  Most programming  
languages themselves are still English though, or at least their  
vocabulary is based on English and English-like words.  (Except for  
the ones that aren't.)  Fortunately, since Perl6 is ultimately  
mutable, it should be reasonably straightforward to translate it all  
so that you could start programs with use Dutch or use Japanese.


use Lingua::FR;
mes @valeurs=(1,2,3);
dis $_ pour @valeurs;#pardon my French

Of course, while some languages might need only to translate all the  
function and variable names, others would arguably want to rearrange  
the grammar and syntax too, so reasonably straightforward is a  
relative term


The brute force way would be to redefine every function with a new  
name for the new language; but perhaps what we really want is a more  
elegant way to do that:

sub foo :trans(fr=fue, de=fu) {...}


I do not think that your  use Locale::Lingua::Romana::Perligata;
is usable, because the translation (in general) adapts to the language
of the user of the module, not the likings of the author.


That depends on the circumstances; the author(s) still have to provide  
translations in the first place.  I wasn't thinking of ways to handle  
multiple languages, just ways to let the author more easily use his  
own language (which is what the majority of perl programs do, since  
most of them are written for private use).



As I suggested in a previous mail, we can do it by making say/print
a bit smarter.  Instead of interpolating before they are called,
we let them interpolate themselves, and optionally translate.


I really like the idea of having text lazily interpolate/translate.   
And in P6, it will be possible to override quoting and concatenating  
so that the code doesn't even have to look any different.  Being able  
to refer to the interpolated values is a bit of a different matter, I  
think; although I guess the main reason for wanting to do so is  
translating (including singular-to-plural translations).


Flexible interpolation is good because it makes text look more  
natural, as opposed to a printf-like separation of parts.  On the  
other hand, the more natural the text looks in one language, the more  
work it can be to translate it automatically.  The magic-S is more of  
a shortcut when you're not doing real translations at all.



-David