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
| #lang racket | |
| ;;; a definition of Y(notice: it's not Y Combinator), | |
| ;;; which can run in a strict language | |
| ; (Y f) = (f (Y f)) = (f (lambda (x) ((Y f) x))) | |
| (define Y | |
| (lambda (f) | |
| (f (lambda (x) ((Y f) x))))) | |
| (define almost-factorial |
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
| def repeat(c: => Unit) = new { | |
| def until(p: => Boolean): Unit = { | |
| c | |
| if(p) () | |
| else until(p) | |
| } | |
| } |
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
| class Class | |
| def to_proc | |
| proc { |x, y| new x, y } | |
| end | |
| end | |
| p [[1, 'a'], [2, 'b'], [3, 'c']].map &Array |
NewerOlder