This file contains 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-syntax-parameter yield | |
(lambda (stx) | |
(syntax-violation 'yield "~yield~ is undefined outside of a generator" stx))) | |
(define-syntax-rule (generator body ...) | |
(let () | |
(define yield-tag (make-prompt-tag)) | |
(define (yield% . returns) | |
(apply abort-to-prompt yield-tag returns)) | |
(define (thunk) |
This file contains 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 yield (prompt-tag)) | |
(define (count-helper) | |
(let loop ((n 0)) | |
(abort-to-prompt yield n) | |
(loop (1+ n)))) | |
(define this-step count-helper) | |
(define (count) |
This file contains 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
(defprotocol WEIGHTED_GRAPH | |
(nodes [graph]) | |
(neighbors [graph node]) | |
(weight [graph from to])) | |
(defn dijkstra | |
[start goal graph] | |
(let [nodes (nodes graph) | |
neighbors #(neighbors graph %) | |
weight #(weight graph %1 %2)] |
This file contains 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
var tinyurl = "http://tinyurl.com/" | |
var urls = [] | |
var encode = function(longUrl){ | |
urls.push(longUrl) | |
return tinyurl+(urls.length-1) | |
}; | |
var decode = function(shortUrl){ | |
var index = Number(shortUrl.substring(tinyurl.length)) |
This file contains 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 WM_GENSYM(name) GENSYM_##name##__COUNTER__ | |
#define WM_WITH(initializer,body) {auto WM_GENSYM() = initializer; body} |
This file contains 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
#include <iostream> | |
int main() | |
{ | |
std::cout << "hello world\n"; | |
std::getchar(); | |
return 0; | |
} |
This file contains 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
#include <utility> | |
template <class F> | |
struct Y{ | |
F f; | |
Y(F _f) : f{_f} {} | |
template<class...arg_t> | |
auto operator()(arg_t&&...arg) {return f(*this,std::forward<arg_t>(arg)...);} | |
}; |
NewerOlder