• Algol 68 - pluralizing text parts

    From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Sat Aug 23 18:49:16 2025
    From Newsgroup: comp.lang.misc

    Often we stumble across text output from software, like

    Copy 42 items (12 minutes left).
    ...
    Copy 1 items (1 minutes left).

    Since I'm also doing a lot of text oriented processing
    I'm usually using some pluralization, e.g. in "C" like

    printf ("Copy %d item%s ...", n, (n>1 ? "s" : "") );

    In some (roguelike) game packages that also use a lot
    text output (partly synthesized) they use sophisticated
    functions, e.g. like makeplural (body_part (FOOT)));

    I like that; it produces readable output and the software
    induce confidence that the programmers have spent some
    more precision in their code than sloppier programmers
    would have done - or (to make it sound less offensive)
    programmers who have other priorities than such details.

    In some of my recent Algol 68 toys this "requirement"
    appeared again. But (unlike as with "C") I noticed that
    using operators instead of functions creates IMO better
    legible code. So instead of inline-ternary operators ?:
    or procedures these Algol 68 operator variants emerged:

    PRIO PLURAL = 6;

    OP PLURAL = (INT amount, STRING word) STRING :
    whole (amount, 0) + word + ( amount > 1 | "s" | "" );

    and

    OP PLURAL = (INT amount, STRING word) STRING :
    ( amount | "one", "two", "three", "four", "five",
    "six", "seven", "eight", "nine", "ten"
    | whole (amount, 0) )
    + word + ( amount > 1 | "s" | "" );


    alleviating the application text from "stringifying"
    with an explicit whole(n,0) or conditionals. Producing
    output (depending on the variant) like

    Get 1 horse or 2 dogs or 3 cats or 12 fleas to get happy.

    Get one horse or two dogs or three cats or 12 fleas to get happy.

    for string elements like
    1 PLURAL " horse"
    2 PLURAL " dog"
    3 PLURAL " cat"
    12 PLURAL " flea"

    If we'd have postfix operators available it could have
    also been (with an operator named 'S') even more tersely
    (yet legible)
    1 " horse" S
    2 " dog" S
    3 " cat" S
    12 " flea" S


    Janis
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Keith Thompson@Keith.S.Thompson+u@gmail.com to comp.lang.misc on Sat Aug 23 15:08:44 2025
    From Newsgroup: comp.lang.misc

    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    Since I'm also doing a lot of text oriented processing
    I'm usually using some pluralization, e.g. in "C" like

    printf ("Copy %d item%s ...", n, (n>1 ? "s" : "") );
    [...]

    I'd probably write :

    printf("Copy %d item%s ...", n, n==1 ? "" : "s");

    "Copy 0 items" seems more correct than "Copy 0 item".
    --
    Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
    void Void(void) { Void(); } /* The recursive call of the void */
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Andy Walker@anw@cuboid.co.uk to comp.lang.misc on Sun Aug 24 00:01:30 2025
    From Newsgroup: comp.lang.misc

    On 23/08/2025 17:49, Janis Papanagnou wrote:
    Often we stumble across text output from software, like
    Copy 42 items (12 minutes left).
    ...
    Copy 1 items (1 minutes left).
    Since I'm also doing a lot of text oriented processing
    I'm usually using some pluralization, e.g. in "C" like
    printf ("Copy %d item%s ...", n, (n>1 ? "s" : "") );

    Firstly, I agree with Keith that English uses the
    plural in the case n = 0; n < 0 is, I suppose, unlikely to
    occur in real examples.

    [...]. So instead of inline-ternary operators ?:
    or procedures these Algol 68 operator variants emerged:
    PRIO PLURAL = 6;
    OP PLURAL = (INT amount, STRING word) STRING :
    whole (amount, 0) + word + ( amount > 1 | "s" | "" );

    Secondly, if you're generalising, then you "should" look
    at the end of "word": eg "flies" rather than "flys". I accept,
    of course, that there are limits to how much should be done; you
    can spend years tweaking stuff like that.

    alleviating the application text from "stringifying"
    with an explicit whole(n,0) or conditionals. Producing
    output (depending on the variant) like
    Get 1 horse or 2 dogs or 3 cats or 12 fleas to get happy.

    Not really relevant, but I recall David Crystal grumbling
    about the calls for phonetic spelling, and pointing out that we
    usually get plurals by adding "s", but phonetically we would have
    "cats", "dogz" and "horsiz", and a mess!
    --
    Andy Walker, Nottingham.
    Andy's music pages: www.cuboid.me.uk/andy/Music
    Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Grieg
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Mon Aug 25 01:21:16 2025
    From Newsgroup: comp.lang.misc

    On 24.08.2025 00:08, Keith Thompson wrote:
    Janis Papanagnou <janis_papanagnou+ng@hotmail.com> writes:
    [...]
    Since I'm also doing a lot of text oriented processing
    I'm usually using some pluralization, e.g. in "C" like

    printf ("Copy %d item%s ...", n, (n>1 ? "s" : "") );
    [...]

    I'd probably write :

    Yes, sure. That was just an ad hoc typed sample to show
    what I'm basically doing when considering more accurate
    formulations in software.


    printf("Copy %d item%s ...", n, n==1 ? "" : "s");

    For legibility I prefer using parenthesis, though.

    (And not only because of precedence rules in case of C++
    where you typically cout << ... items.)


    "Copy 0 items" seems more correct than "Copy 0 item".

    Well, *that* can't happen in this application case. ;-)
    (I would also not "add -2 items", BTW, to indicate any
    removal.)

    But in the cases that you're obviously referring to I'd
    typically also avoid numbers and use "no items" (or "zero
    items", depending on context).

    Janis

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Janis Papanagnou@janis_papanagnou+ng@hotmail.com to comp.lang.misc on Mon Aug 25 01:31:15 2025
    From Newsgroup: comp.lang.misc

    On 24.08.2025 01:01, Andy Walker wrote:
    On 23/08/2025 17:49, Janis Papanagnou wrote:
    Often we stumble across text output from software, like
    Copy 42 items (12 minutes left).
    ...
    Copy 1 items (1 minutes left).
    Since I'm also doing a lot of text oriented processing
    I'm usually using some pluralization, e.g. in "C" like
    printf ("Copy %d item%s ...", n, (n>1 ? "s" : "") );

    Firstly, I agree with Keith that English uses the
    plural in the case n = 0; n < 0 is, I suppose, unlikely to
    occur in real examples.

    As said in my reply to Keith's post this makes no sense in
    an application case where I illustrated a copying progress.

    (I agree of course about the plural of 0; how could I not.)


    [...]. So instead of inline-ternary operators ?:
    or procedures these Algol 68 operator variants emerged:
    PRIO PLURAL = 6;
    OP PLURAL = (INT amount, STRING word) STRING :
    whole (amount, 0) + word + ( amount > 1 | "s" | "" );

    Secondly, if you're generalising, then you "should" look
    at the end of "word": eg "flies" rather than "flys". I accept,
    of course, that there are limits to how much should be done; you
    can spend years tweaking stuff like that.

    The context where I use that is a very primitive application
    case; I'm not doing text generation or anything complex like
    that. - In my post I had mentioned roguelikes, like Nethack.
    If you want to see a much more sophisticated algorithm have a
    look into the respective source code; they have spent really
    a lot effort for pluralizing rules (much more than just the
    example you added!), dozens or even hundreds of lines (IIRC).
    To give an example; most stuff (items) are fixed in Nethack,
    but there's one thing where you can externally define a fruit;
    without thinking I defined "cactus", and was surprised when I
    played a game and found "two cacti" lying on the ground. :-)

    Janis

    [...]


    --- Synchronet 3.21a-Linux NewsLink 1.2