This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?- 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)). |