BuK/IIm14/Studenten/s3damues/Hilbertbus
Aus ProgrammingWiki
Wiki-Quelltext dieser Seite.
<language>Javascript</language>
<code id="5534a192d19fd">function empty() {
// An empty list is a stream that does not call the continuation
return function (continuation) { };
}
function cons(head, tail) {
return function (continuation) { // To construct a new list, we return a stream
continuation(head); // That first continues with the head
tail(continuation); // and continues the tail
};
}
function print(stream) {
stream(function (v) { // For each value of the stream
console.log(v); // Print it
});
}
function natStreamMaker(start) {
cons(start, natStreamMaker(start + 1));
}
</code>
<run id="5534a192d1a91">print(natStreamMaker(0))</run>