Skip to content

Instantly share code, notes, and snippets.

@WillNess
WillNess / corec.pl
Last active September 10, 2018 13:50
/**
* Lazy lists represented as Closure (like plus(1)) that gives
* NextElt, NextClosure on call to call(Closure, NextElt, NextClosure) -- remarks and edits by wn
* cf. unfold :: (b -> (a, b)) -> b -> [a] -- for my personal readability
*
* Copyright 2018, XLOG Technologies GmbH, Switzerland
* Jekejeke Prolog 1.3.0 (a fast and small prolog interpreter)
*/
%% source:
-- code from http://stackoverflow.com/a/21427171/849891 by András Kovács
combsOf :: Int -> [a] -> [[a]]
combsOf n _ | n < 1 = [[]]
combsOf n (x:xs) = combsOf n xs ++ map (x:) (combsOf (n - 1) xs)
combsOf _ _ = []
-- what I meant was this
change :: Int -> [Int] -> [[Int]]
change n xs
| n<0 || null xs = []
@WillNess
WillNess / rev.scm
Created November 13, 2013 20:56 — forked from roerd/rev.scm
(define (rev lst)
(if (or (null? lst)
(null? (cdr lst)))
lst
(apply (lambda (x . xs)
(apply (lambda (y . ys)
(cons y (rev (cons x (rev ys)))))
(rev xs)))
lst)))
(define (make-letter destination message)
(define (dispatch x)
(cond ((eq? x 'get-destination) destination)
((eq? x 'get-message) message)
(else "Invalid option.")))
dispatch)
(define (make-mailbox address)
(let ((T '()))
(define (add-post letter)
@WillNess
WillNess / example.txt
Created January 27, 2013 10:12 — forked from mndrix/example.txt
Lazy Fibonacci in Prolog
?- fibs(F), take(F, 20, _).
F = [0, 1, 1, 2, 3, 5, 8, 13, 21|...],
freeze(_G2395, zip_with(plus, [2584, 4181|_G2395], [4181|_G2395], _G2395)).