You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some gradual typing papers use the following benchmark with the naive prime sieve using lazy streams. Now that we have closures in Pallene, it might be interesting to add it to the benchmark list
I don't remember why the stream_take function is there. Maybe I added it for debugging?
-- Simple streams library for building infinite lists.-- A stream is a cons of a value and a thunk that computes the next value-- when applied.-- (any, any->any) -> anylocalfunctionmake_stream(v, f)
return {v=v, f=f}
endlocalfunctionstream_head(st)
returnst.vendlocalfunctionstream_tail(st)
returnst.f(st.v)
endlocalfunctionstream_get(st, n)
for_=1, n-1dost=stream_tail(st)
endreturnstream_head(st)
endlocalfunctionstream_take(st, n)
localelems= {}
fori=1, ndoelems[i] =stream_head(st)
st=stream_tail(st)
endreturnelemsend------------------------------------------------ Build a stream of integers starting from 1localfunctioncount_from(n)
returnmake_stream(n, function(i) returncount_from(i+1) end)
end-- Filter all multiples of nlocalfunctionsift(n, st)
localhd=stream_head(st)
localtl=stream_tail(st)
ifhd%n==0thenreturnsift(n, tl)
elsereturnmake_stream(hd, function() returnsift(n, tl) end)
endend-- Naive sieve of Erasthosteneslocalfunctionsieve(st)
localhd=stream_head(st)
localtl=stream_tail(st)
returnmake_stream(hd, function() returnsieve(sift(hd, tl)) end)
end--localprime_stream=sieve(count_from(2))
localfunctionget_prime(n)
returnstream_get(prime_stream, n)
endreturn {
get_prime=get_prime
}
The text was updated successfully, but these errors were encountered:
Some gradual typing papers use the following benchmark with the naive prime sieve using lazy streams. Now that we have closures in Pallene, it might be interesting to add it to the benchmark list
I don't remember why the
stream_take
function is there. Maybe I added it for debugging?The text was updated successfully, but these errors were encountered: