Ren-C's eloquence in the face of FizzBuzz

It's turned out that loop variables need to be quoted after all.

Whether this is a setback or not depends on your perspective. But not the end of the world

count-up 'n 100 [
    print [
        if n mod 3 = 0 [#Fizz]
        if n mod 5 = 0 [#Buzz]
    ] else [
       print [n]
    ]
]

As we further chase down essentialism, I think the definition of FOR is going to be arity-3, and INTEGER! semantics would be COUNT-UP. Plus @ lets us print any value, so you could write:

for 'n 100 [
    print [
        if n mod 3 = 0 '#Fizz
        if n mod 5 = 0 '#Buzz
    ] else [
       print @n
    ]
]

But if I were making the poster today, it would probably say:

for 'n 100 [
    print [
        if n mod 3 = 0 [#Fizz]
        if n mod 5 = 0 [#Buzz]
    ] else [
        print [n]
    ]
]

Or even clearer:

for 'n [1 thru 100] [
    print [
        if n mod 3 = 0 [#Fizz]
        if n mod 5 = 0 [#Buzz]
    ] else [
        print [n]
    ]
]

This helps you know precisely whether it goes up-to-and-including a hundred (1 thru 100) or up-to-but-not-including a hundred (1 to 100), and that it starts at 1 and not 0.

1 Like