3 ms·
Set-based programming is a fairly old idea. Jack Schwartz[0] created SETL[1] in 1969. SETL2[2] and SETLX[3] interpreters are available. Here is a sample progr
by tjalfi 10y ago
Set-based programming is a fairly old idea. Jack Schwartz[0] created SETL[1] in 1969.
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 http://www.settheory.com
[1] http://wiki.c2.com/?SetlLanguage http://wiki.c2.com/?SetlLanguage
[2] http://www.setl.org/setl/ http://www.setl.org/setl/
[3] https://randoom.org/Software/SetlX https://randoom.org/Software/SetlX
[4] https://raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-polyglot/master/fizzbuzz.setl https://raw.githubusercontent.com/Keith-S-Thompson/fizzbuzz-...
Edited to fix formatting of footnotes and add newlines.
- nickpsecurity 10y agoIt was used in a 2000 era web app. Neat. http://cs.nyu.edu/~bacon/phd-thesis/diss/node35.html http://cs.nyu.edu/~bacon/phd-thesis/diss/node35.html
- bbcbasic 10y agoYou're hired!
- Rangi42 10y agoThat translates fairly well into Python, with its set type and list/set/dict comprehensions. 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
- odonnellryan 10y agoYou can concatenate dictionaries in Python: 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 :)
- gwu78 10y agoFirst time I learned about SETL at NYU was when I was learning about Spitbol. 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.setl http://www.hakank.org/setl/fizzbuzz.setl He also has pages on APL and k.