Sunday, February 14
Pixy, the Language
Well, sort of. Kind of sort of.*
Okay, quick, tell me what language this is (without Googling the source code):
Hint the second: It's the same language as this (believe it or not):
Hint the third: You'll be able to script your mee.nu blog like this soon.
* Good language designers borrow. Great language designers swipe someone else's metaprogramming project.
Comments are disabled.
Post is locked.
Well, sort of. Kind of sort of.*
Okay, quick, tell me what language this is (without Googling the source code):
print "Eratosthenes' Sieve, in some funny language"
function print_sieve (limit):
local sieve, j = { }, 2
while j<limit:
while sieve[j]:
j=j+1
print(j)
for k = j*j, limit, j:
sieve[k] = true
j=j+1
print_sieve(100)
Hint: That's not it. And I don't understand the first line of print_sieve at all. Oh, right. Logically, (sieve, j) = ({}, 2), so the local variables sieve and j are initialised as an empty dict and 2, respectively.Hint the second: It's the same language as this (believe it or not):
map = |f,x| x ? %{ hd=f(x.hd), tl=map(f,x.tl) }
filter = |p,x| x ? p(x.hd) ? %{ hd=x.hd, tl=filter(p, x.tl) }, filter(p, x.tl)
take = |n,s| n<=0 ? { }, { s.hd, unpack(take(n-1, s.tl)) }
ints = %{ hd=1; tl=map (|x| x+1, ints) }
f = |seq| %{ hd=seq.hd; tl=f(filter (|x| x%seq.hd~=0, seq.tl)) }
primes = f (ints.tl)
table.print(take (100, primes))
Which implements the exact same function.Hint the third: You'll be able to script your mee.nu blog like this soon.
* Good language designers borrow. Great language designers swipe someone else's metaprogramming project.
Posted by: Pixy Misa at
01:48 AM
| No Comments
| Add Comment
| Trackbacks (Suck)
Post contains 199 words, total size 2 kb.
45kb generated in CPU 0.0136, elapsed 0.2592 seconds.
54 queries taking 0.2511 seconds, 336 records returned.
Powered by Minx 1.1.6c-pink.
54 queries taking 0.2511 seconds, 336 records returned.
Powered by Minx 1.1.6c-pink.