by tjalfi · 9y ago · 0 comments
SETL2[2] and SETLX[3] interpreters are available.
Here is a sample program[4] by Keith S. Thompson. I have removed the comment header for brevity.
program Fizz_Buzz;
fizz := {3, 6..100};
buzz := {5, 10..100};
fizzbuzz := fizz * buzz;
fizz -:= fizzbuzz;
buzz -:= fizzbuzz;
num := {1..100} - fizz - buzz - fizzbuzz;
line_map := {[n, "Fizz"] : n in fizz} +
{[n, "Buzz"] : n in buzz} +
{[n, "FizzBuzz"] : n in fizzbuzz} +
{[n, n] : n in num};
loop for i in [1..100] do
print(line_map(i));
end loop;
end Fizz_Buzz;
[0] http://www.settheory.com[1] http://wiki.c2.com/?SetlLanguage
[3] https://randoom.org/Software/SetlX
[4] https://raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-...
Edited to fix formatting of footnotes and add newlines.
def setrange(first, next, last):
return set(range(first, last+1, next-first))
fizz = setrange(3, 6, 100)
buzz = setrange(5, 10, 100)
fizzbuzz = fizz & buzz
fizz -= fizzbuzz
buzz -= fizzbuzz
num = setrange(1, 2, 100) - fizz - buzz - fizzbuzz
line_map = dict({n: "Fizz" for n in fizz}.items() +
{n: "Buzz" for n in buzz}.items() +
{n: "FizzBuzz" for n in fizzbuzz}.items() +
{n: n for n in num}.items())
for i in range(1, 100+1):
print(line_map[i])
Some SETL features Python lacks:• No ellipsis notation for ranges; must use the "range" function and add one to the maximum value, or define a custom "setrange" function
• Can't concatenate dictionaries; must concatenate their "items" lists and convert back to a dictionary
• No consistent map-lookup notation; collections are indexed with brackets, but functions are called with parentheses
a = {* * b, * * c}
(Python 3.5!)
Unless this is doing something unintended?
> No consistent map-lookup notation;
You can use .get() in Python on a dictionary :)
Here is a fizzbuzz in Spitbol. Probably not the best way to do it.
var a = 0;
start
+a = a + 1;
break
+lt(a,101) :f(end);
x01
+x = (remdr(a,3) + remdr(a,5)); eq(x,0) :s(x06);
x02
+y = remdr(a,3); eq(y,0) :s(x04);
x03
+z = remdr(a,5); eq(z,0) :s(x05)f(x07);
x04
+output = 'fizz' :(start);
x05
+output = 'buzz' :(start);
x06
+output = 'fizzbuzz' :(start);
x07
+output = a :(start);
end
More: http://www.hakank.org/setl/fizzbuzz.setlHe also has pages on APL and k.