Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| webserver: webserver.c libuv/uv.a http-parser/http_parser.o | |
| gcc -I libuv/include \ | |
| -lrt -lm -lpthread -o \ | |
| webserver webserver.c \ | |
| libuv/uv.a http-parser/http_parser.o | |
| libuv/uv.a: | |
| $(MAKE) -C libuv | |
| http-parser/http_parser.o: |
| <!-- This file goes in ~/Library/LaunchAgents --> | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| <plist version="1.0"> | |
| <dict> | |
| <key>Disabled</key> | |
| <false/> | |
| <key>KeepAlive</key> | |
| <true/> |
| #lang racket | |
| (provide (struct-out subscription) | |
| (struct-out message-handler) | |
| (struct-out kernel-mode-transition) | |
| make-vm | |
| vm? | |
| run-vm | |
| nested-vm) |
| class Lisp | |
| Fs = { | |
| :label => lambda {|name,value| Fs[name] = lambda { value } }, | |
| :car => lambda {|sexp| sexp.first }, | |
| :cdr => lambda {|sexp| sexp.slice(1, sexp.size) }, | |
| :cons => lambda {|head,tail| [head] + tail }, | |
| :atom => lambda {|sexp| !sexp.is_a?(Array) }, | |
| :eq => lambda {|a,b| a == b }, | |
| :if => lambda {|cnd,thn,els| cnd ? thn : els } | |
| } |
| // Version 1. Simple recursive function. Blows the stack for large nodes. | |
| function replace(node, from, to) { | |
| switch (node.type) { | |
| case IF: | |
| return { | |
| type: IF, | |
| test: replace(node.test, from, to), | |
| then: replace(node.then, from, to), | |
| else: replace(node.else, from, to) | |
| }; |
| ;; Requires Outlet to run: https://github.com/jlongster/outlet | |
| ;; | |
| ;; Run with: `ol main.ol <input-file>` | |
| ;; | |
| ;; This is a meta-circular evaluator for a basic Lisp. It is | |
| ;; mostly taken from SICP 4.1*. I wanted to see if I could write a | |
| ;; debugger with it. Turns out if I want control over control flow I | |
| ;; need a register-based interpreter. | |
| ;; | |
| ;; * http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1 |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
This article is now published on my website: Prefer Subshells for Context.
| The bridge is now located at https://github.com/fjolnir/TLC |
| (extend-type js/RegExp | |
| cljs.core/IFn | |
| (-invoke ([this s] (re-matches this s)))) | |
| (#"foo.*" "foobar") ;=> "foobar" | |
| (#"zoo.*" "foobar") ;=> nil | |
| (filter #".*foo.*" ["foobar" "goobar" "foobaz"]) ;=> ("foobar" "foobaz") |