Adding an and into a list

Good evening. Having recovered from my animal conundrum I have, Hopefully, a simple one. I am trying to get a list of items that does not repeat but that has an and in . I want to end up with something like you see cows, horses and sheep.
Is this possible and if so how the heck do I do it.

Comments

  • Ah, here's one I can sink my teeth into! Near as I could tell, it's not all that simple; at least, there's no elegant way to do it. That said, you can use this decidedly un-elegant trick:
    Table: Animals
    1- [@Andify with beasts, 1, @, and]
    2- [@Andify with beasts, 2, @, and]
    3- [@Andify with beasts, 3, @, and]
    4- [@Andify with beasts, 3, @, or]
    5- [@Andify with beasts, 3, !, and, Y]
    6- [@Andify with beasts, 3]
    
    Table: beasts
    a bear
    a big cat
    a wolf
    a pack of {1d6+2} wolves
    
    table: Andify
    set: destTable={$1}
    set: numRolls={$2}
    set: rollType={$3}
    set: andOr={$4}
    set: oxfordComma=[{$5} >> lower]
    [when]{oxfordComma}=y[do]{oxfordComma==','}[else]{oxfordComma==''}[end]&
    [when not]{rollType}[do]{rollType=='@'}&;#91;end]&
    [when not]{andOr}[do]{andOr=='and'}[end]&
    [when]{numRolls}=1[do][@RollOnTable&;#93;[end]&
    [when]{numRolls}=2[do][@RollOnTable&;#93; {andOr} [@RollOnTable&;#93;[end]&
    [when]{numRolls}>2[do]{numRolls=={{numRolls}-1}}[@{numRolls} RollOnTable >> implode]{oxfordComma} {andOr} [@RollOnTable&;#93;[end]&
    {rollType==''}{andOr==''}{oxfordComma==''}
    
    table: RollOnTable
    [when]{rollType}=@&;#91;do][@{destTable}&;#93;[else][!{destTable}][end]
    
    (the "1-" in Animals is just so that you can see which call to Andify is being performed)

    The table "Andify" takes the following parameters:
    • destination table
    • number of rolls
    • roll type ("@ or !", defaults to "@)
    • and/or (for the word that separates the last item of the group; expects "and" or "or", defaults to "and")
    • oxfordComma (if this is "Y" or "y", groups of three or more will have a comma before the "and", defaults to "no oxford comma")

    Hope this helps!
  • Whoa...that's huge :) really appreciate you taking the time...when I say huge in my mind it was a couple of brackets a colon and a squiggle ;)
    I wouldn't know where to start with that :)

Leave a Comment