From: Chris Barker Date: Wed, 8 Jun 2011 18:16:31 +0000 (-0400) Subject: Merge branch 'master' of ssh://server.philosophy.fas.nyu.edu/Users/lambda/lambda X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=commitdiff_plain;h=700ff894efd420fcad75b9215ab8c54e8fc14a3f;hp=1e593fe87c53f0f023e26f9c82665808b42640d4 Merge branch 'master' of ssh://server.philosophy.fas.nyu.edu/Users/lambda/lambda --- diff --git a/code/same-fringe.rkt b/code/same-fringe.rkt new file mode 100644 index 00000000..8a8a7ba1 --- /dev/null +++ b/code/same-fringe.rkt @@ -0,0 +1,193 @@ +#lang racket +(require racket/control) ; this tells Scheme to let us use shift and reset + +(define (visit yield t) + (cond [(pair? t) (visit yield (car t)) (visit yield (cdr t))] + [else (yield t)])) + + +; delimcc-based implementation of coroutines, following http://okmij.org/ftp/continuations/implementations.html#caml-shift +(define (coroutine2 main start thread) + (letrec ([yield (lambda (x) (shift0 k (cons x k)))] + [loop (lambda (curk data) + (let ([x (car data)] [k (cdr data)]) + (cond + [(eq? k 'finished) (loop curk (curk x))] + [(eq? k 'exit) x] + [else (loop k (curk x))])))]) + (loop (lambda (x) (reset0 (cons (thread yield x) 'finished))) (reset0 (cons (main yield start) 'exit))))) + +; call/cc-based, following Xavier Leroy's ocaml-callcc +(define (coroutine2^ main start thread) + (let/cc initk (let* ([curk initk] + [yield (lambda (x) (let/cc k (let ([oldk curk]) (set! curk k) (oldk x))))]) + (main yield (begin (thread yield (let/cc k2 (set! curk k2) start))))))) + +(define (proc coroutine2 max1 max2) + (letrec ([proc1 (lambda (yield n) (if (>= n max1) (begin (displayln "1: exit") 100) (begin (display "1: received ") (displayln n) (proc1 yield (yield (+ 1 n))))))] + [proc2 (lambda (yield n) (if (>= n max2) (begin (displayln "2: finished") -2) (begin (display "2: received ") (displayln n) (proc2 yield (yield (+ 1 n))))))]) + (coroutine2 proc1 0 proc2))) + +; the following is meant to be a general-purpose handler with the following behavior: +; 1. call main with start +; 2. first yield to proc1, which yields back to main, +; 3. then main yields to proc2, which yields back to main; and so on +; 4. when either proc finishes, subsequent yields from main which would have gone to that procedure instead always return #f +; 5. we stop looping only when main finishes +(define (coroutine3 main start proc1 proc2) + (letrec ([yield (lambda (x) (shift0 k (cons x k)))] + [false (lambda (x) (reset0 (false (shift0 k (cons #f k)))))] + [loop (lambda (inmain curk otherk data) + (let ([x (car data)] [k (cdr data)]) + (cond + [(eq? k 'finished) (loop #t otherk false (curk x))] + [(eq? k 'exit) x] + [inmain (loop #f k otherk (curk x))] + [else (loop #t otherk k (curk x))])))]) + (loop #t (lambda (x) (reset0 (cons (proc1 yield x) 'finished))) + (lambda (x) (reset0 (cons (proc2 yield x) 'finished))) + (reset0 (cons (main yield start) 'exit))))) + +; the same-fringe application doesn't make use of the 'start or 'restart parameters +; the 'blah values yielded to the leaf-iterators are ignored too +(define (same-fringe1 tree1 tree2) + (letrec ([next1 (lambda (yield x) (visit yield tree1))] + [next2 (lambda (yield x) (visit yield tree2))] + [main (lambda (yield x) + (let* ([leaf1 (yield 'blah)] + [leaf2 (yield 'blah)]) + (cond [(and leaf1 leaf2) (and (equal? leaf1 leaf2) (main yield 'blah))] + [(or leaf1 leaf2) #f] + [else #t])))]) + (coroutine3 main 'restart next1 next2))) + + +; another delimcc solution, based on Biernacki, Danvy and Shan "On the static and dynamic extents of delimited continuations" 2006, section 4.1.4 +; here, next1 = '(leaf1 . thunk_for_more_leaves); final thunk => '(finished . #f) +(define (make-enumerator2 tree) + (define (yield x) (shift k (cons x k))) + (reset (visit yield tree) '(finished . #f))) + +(define (same-fringe2 tree1 tree2) + (define next1 (make-enumerator2 tree1)) + (define next2 (make-enumerator2 tree2)) + (letrec ([loop (lambda (res1 res2) + (let* ([leaf1 (car res1)] + [leaf2 (car res2)] + [next1 (cdr res1)] + [next2 (cdr res2)]) + (cond + [(and next1 next2) (and (equal? leaf1 leaf2) (loop (next1) (next2)))] + [(or next1 next2) #f] + [else #t])))]) + (loop next1 next2))) + + +; call/cc solution, from http://c2.com/cgi/wiki?SameFringeProblem ("Scheme Language, using CoRoutines") +; here, (next1) => '(1 . #t); (next1) => '(2 . #t); (next1) => '(finished . #f) +(define (make-enumerator3 t) + (letrec ([resk #f] + [yieldk #f] + [resume (lambda () (let/cc k + (set! yieldk k) + (cond [(eq? resk #f) + (visit yield t) + (set! resk 'finished) + (yieldk (cons 'finished #f))] + [(eq? resk 'finished) + #;(error "End of generator") + (yieldk (cons 'finished #f)) + ] + [else (resk)])))] + [yield (lambda (x) (let/cc k + (set! resk k) + (yieldk (cons x #t))))]) + resume)) + +(define (same-fringe3 tree1 tree2) + (define next1 (make-enumerator3 tree1)) + (define next2 (make-enumerator3 tree2)) + (letrec ([loop (lambda (res1 res2) + (let* ([leaf1 (car res1)] + [leaf2 (car res2)] + [isleaf1 (cdr res1)] + [isleaf2 (cdr res2)]) + (cond + [(and isleaf1 isleaf2) (and (equal? leaf1 leaf2) (loop (next1) (next2)))] + [(or isleaf1 isleaf2) #f] + [else #t])))]) + (loop (next1) (next2)))) + + + +(define (test same-fringe) + (define tree1 '(((1 . 2) . (3 . 4)) . (5 . 6))) + (define tree2 '(1 . (((2 . 3) . (4 . 5)) . 6))) + (define tree3 '(1 . (((2 . 3) . (4 . 5)) . 7))) + (define tree4 '(((1 . 2) . (4 . 5)) . 7)) + (define tree5 '(((1 . 2) . (3 . 4)) . 5)) + (define tree6 '(((10 . 2) . (3 . 4)) . 5)) + (define tree7 8) + (and (same-fringe tree1 tree2) + (same-fringe tree7 tree7) + (not (or + (same-fringe tree1 tree3) + (same-fringe tree1 tree4) + (same-fringe tree4 tree1) + (same-fringe tree5 tree1) + (same-fringe tree1 tree5) + (same-fringe tree1 tree6) + (same-fringe tree6 tree1) + (same-fringe tree6 tree7) + )))) + +#| + +In Lua, using CoRoutines: + function tree_leaves(tree) + if tree.leaf then + coroutine.yield(tree.leaf) + else + tree_leaves(tree.left) + tree_leaves(tree.right) + end + end + function same_fringe(tree1, tree2) + local iter1 = coroutine.wrap(tree_leaves) + local iter2 = coroutine.wrap(tree_leaves) + for node in iter1, tree1 do + if node ~= iter2(tree2) then + return false + end + end + return iter2() == nil + end + +In OCaml: +# #require "delimcc";; +# open Delimcc;; +# type seq = End | Next of int * seq computation + and 'a computation = unit -> 'a;; +# type 'a tree = Leaf of 'a | Node of 'a tree * 'a tree;; +# let rec visit p = function Leaf i -> shift p (fun a -> Next (i, a)) | Node (t1,t2) -> let () = visit p t1 in visit p t2;; +# let prompt mid = let p = new_prompt() in push_prompt p (mid p);; +val prompt : ('a Delimcc.prompt -> unit -> 'a) -> 'a = +# let make_seq t = prompt (fun p () -> let () = visit p t in End);; +val make_seq : int tree -> seq = +# let tree1 = Node (Node (Node(Leaf 1,Leaf 2), Node(Leaf 3,Leaf 4)), Node(Leaf 5,Leaf 6));; +# let next1 = make_seq tree1;; +val next1 : seq = Next (1, ) +# let next2 = match next1 with Next(_,f) -> f ();; +val next2 : seq = Next (2, ) +# let next3 = match next2 with Next(_,f) -> f ();; +val next3 : seq = Next (3, ) +# let next4 = match next3 with Next(_,f) -> f ();; +val next4 : seq = Next (4, ) +# let next5 = match next4 with Next(_,f) -> f ();; +val next5 : seq = Next (5, ) +# let next6 = match next5 with Next(_,f) -> f ();; +val next6 : seq = Next (6, ) +# let next7 = match next6 with Next(_,f) -> f ();; +val next7 : seq = End + +|# diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 00000000..0512e9d3 Binary files /dev/null and b/favicon.ico differ diff --git a/gitweb.css b/gitweb.css new file mode 100644 index 00000000..79d7eebb --- /dev/null +++ b/gitweb.css @@ -0,0 +1,598 @@ +body { + font-family: sans-serif; + font-size: small; + border: solid #d9d8d1; + border-width: 1px; + margin: 10px; + background-color: #ffffff; + color: #000000; +} + +a { + color: #0000cc; +} + +a:hover, a:visited, a:active { + color: #880000; +} + +span.cntrl { + border: dashed #aaaaaa; + border-width: 1px; + padding: 0px 2px 0px 2px; + margin: 0px 2px 0px 2px; +} + +img.logo { + float: right; + border-width: 0px; +} + +img.avatar { + vertical-align: middle; +} + +a.list img.avatar { + border-style: none; +} + +div.page_header { + height: 25px; + padding: 8px; + font-size: 150%; + font-weight: bold; + background-color: #d9d8d1; +} + +div.page_header a:visited, a.header { + color: #0000cc; +} + +div.page_header a:hover { + color: #880000; +} + +div.page_nav { + padding: 8px; +} + +div.page_nav a:visited { + color: #0000cc; +} + +div.page_path { + padding: 8px; + font-weight: bold; + border: solid #d9d8d1; + border-width: 0px 0px 1px; +} + +div.page_footer { + height: 17px; + padding: 4px 8px; + background-color: #d9d8d1; +} + +div.page_footer_text { + float: left; + color: #555555; + font-style: italic; +} + +div#generating_info { + margin: 4px; + font-size: smaller; + text-align: center; + color: #505050; +} + +div.page_body { + padding: 8px; + font-family: monospace; +} + +div.title, a.title { + display: block; + padding: 6px 8px; + font-weight: bold; + background-color: #edece6; + text-decoration: none; + color: #000000; +} + +div.readme { + padding: 8px; +} + +a.title:hover { + background-color: #d9d8d1; +} + +div.title_text { + padding: 6px 0px; + border: solid #d9d8d1; + border-width: 0px 0px 1px; + font-family: monospace; +} + +div.log_body { + padding: 8px 8px 8px 150px; +} + +span.age { + position: relative; + float: left; + width: 142px; + font-style: italic; +} + +span.signoff { + color: #888888; +} + +div.log_link { + padding: 0px 8px; + font-size: 70%; + font-family: sans-serif; + font-style: normal; + position: relative; + float: left; + width: 136px; +} + +div.list_head { + padding: 6px 8px 4px; + border: solid #d9d8d1; + border-width: 1px 0px 0px; + font-style: italic; +} + +.author_date, .author { + font-style: italic; +} + +div.author_date { + padding: 8px; + border: solid #d9d8d1; + border-width: 0px 0px 1px 0px; +} + +a.list { + text-decoration: none; + color: #000000; +} + +a.subject, a.name { + font-weight: bold; +} + +table.tags a.subject { + font-weight: normal; +} + +a.list:hover { + text-decoration: underline; + color: #880000; +} + +a.text { + text-decoration: none; + color: #0000cc; +} + +a.text:visited { + text-decoration: none; + color: #880000; +} + +a.text:hover { + text-decoration: underline; + color: #880000; +} + +table { + padding: 8px 4px; + border-spacing: 0; +} + +table.diff_tree { + font-family: monospace; +} + +table.combined.diff_tree th { + text-align: center; +} + +table.combined.diff_tree td { + padding-right: 24px; +} + +table.combined.diff_tree th.link, +table.combined.diff_tree td.link { + padding: 0px 2px; +} + +table.combined.diff_tree td.nochange a { + color: #6666ff; +} + +table.combined.diff_tree td.nochange a:hover, +table.combined.diff_tree td.nochange a:visited { + color: #d06666; +} + +table.blame { + border-collapse: collapse; +} + +table.blame td { + padding: 0px 5px; + font-size: 100%; + vertical-align: top; +} + +th { + padding: 2px 5px; + font-size: 100%; + text-align: left; +} + +/* do not change row style on hover for 'blame' view */ +tr.light, +table.blame .light:hover { + background-color: #ffffff; +} + +tr.dark, +table.blame .dark:hover { + background-color: #f6f6f0; +} + +/* currently both use the same, but it can change */ +tr.light:hover, +tr.dark:hover { + background-color: #edece6; +} + +/* boundary commits in 'blame' view */ +/* and commits without "previous" */ +tr.boundary td.sha1, +tr.no-previous td.linenr { + font-weight: bold; +} + +/* for 'blame_incremental', during processing */ +tr.color1 { background-color: #f6fff6; } +tr.color2 { background-color: #f6f6ff; } +tr.color3 { background-color: #fff6f6; } + +td { + padding: 2px 5px; + font-size: 100%; + vertical-align: top; +} + +td.link, td.selflink { + padding: 2px 5px; + font-family: sans-serif; + font-size: 70%; +} + +td.selflink { + padding-right: 0px; +} + +td.sha1 { + font-family: monospace; +} + +.error { + color: red; + background-color: yellow; +} + +td.current_head { + text-decoration: underline; +} + +table.diff_tree span.file_status.new { + color: #008000; +} + +table.diff_tree span.file_status.deleted { + color: #c00000; +} + +table.diff_tree span.file_status.moved, +table.diff_tree span.file_status.mode_chnge { + color: #777777; +} + +table.diff_tree span.file_status.copied { + color: #70a070; +} + +/* noage: "No commits" */ +table.project_list td.noage { + color: #808080; + font-style: italic; +} + +/* age2: 60*60*24*2 <= age */ +table.project_list td.age2, table.blame td.age2 { + font-style: italic; +} + +/* age1: 60*60*2 <= age < 60*60*24*2 */ +table.project_list td.age1 { + color: #009900; + font-style: italic; +} + +table.blame td.age1 { + color: #009900; + background: transparent; +} + +/* age0: age < 60*60*2 */ +table.project_list td.age0 { + color: #009900; + font-style: italic; + font-weight: bold; +} + +table.blame td.age0 { + color: #009900; + background: transparent; + font-weight: bold; +} + +td.pre, div.pre, div.diff { + font-family: monospace; + font-size: 12px; + white-space: pre; +} + +td.mode { + font-family: monospace; +} + +/* progress of blame_interactive */ +div#progress_bar { + height: 2px; + margin-bottom: -2px; + background-color: #d8d9d0; +} +div#progress_info { + float: right; + text-align: right; +} + +/* format of (optional) objects size in 'tree' view */ +td.size { + font-family: monospace; + text-align: right; +} + +/* styling of diffs (patchsets): commitdiff and blobdiff views */ +div.diff.header, +div.diff.extended_header { + white-space: normal; +} + +div.diff.header { + font-weight: bold; + + background-color: #edece6; + + margin-top: 4px; + padding: 4px 0px 2px 0px; + border: solid #d9d8d1; + border-width: 1px 0px 1px 0px; +} + +div.diff.header a.path { + text-decoration: underline; +} + +div.diff.extended_header, +div.diff.extended_header a.path, +div.diff.extended_header a.hash { + color: #777777; +} + +div.diff.extended_header .info { + color: #b0b0b0; +} + +div.diff.extended_header { + background-color: #f6f5ee; + padding: 2px 0px 2px 0px; +} + +div.diff a.list, +div.diff a.path, +div.diff a.hash { + text-decoration: none; +} + +div.diff a.list:hover, +div.diff a.path:hover, +div.diff a.hash:hover { + text-decoration: underline; +} + +div.diff.to_file a.path, +div.diff.to_file { + color: #007000; +} + +div.diff.add { + color: #008800; +} + +div.diff.from_file a.path, +div.diff.from_file { + color: #aa0000; +} + +div.diff.rem { + color: #cc0000; +} + +div.diff.chunk_header a, +div.diff.chunk_header { + color: #990099; +} + +div.diff.chunk_header { + border: dotted #ffe0ff; + border-width: 1px 0px 0px 0px; + margin-top: 2px; +} + +div.diff.chunk_header span.chunk_info { + background-color: #ffeeff; +} + +div.diff.chunk_header span.section { + color: #aa22aa; +} + +div.diff.incomplete { + color: #cccccc; +} + +div.diff.nodifferences { + font-weight: bold; + color: #600000; +} + +div.index_include { + border: solid #d9d8d1; + border-width: 0px 0px 1px; + padding: 12px 8px; +} + +div.search { + font-size: 100%; + font-weight: normal; + margin: 4px 8px; + float: right; + top: 56px; + right: 12px +} + +p.projsearch { + text-align: center; +} + +td.linenr { + text-align: right; +} + +a.linenr { + color: #999999; + text-decoration: none +} + +a.rss_logo { + float: right; + padding: 3px 0px; + width: 35px; + line-height: 10px; + border: 1px solid; + border-color: #fcc7a5 #7d3302 #3e1a01 #ff954e; + color: #ffffff; + background-color: #ff6600; + font-weight: bold; + font-family: sans-serif; + font-size: 70%; + text-align: center; + text-decoration: none; +} + +a.rss_logo:hover { + background-color: #ee5500; +} + +a.rss_logo.generic { + background-color: #ff8800; +} + +a.rss_logo.generic:hover { + background-color: #ee7700; +} + +span.refs span { + padding: 0px 4px; + font-size: 70%; + font-weight: normal; + border: 1px solid; + background-color: #ffaaff; + border-color: #ffccff #ff00ee #ff00ee #ffccff; +} + +span.refs span a { + text-decoration: none; + color: inherit; +} + +span.refs span a:hover { + text-decoration: underline; +} + +span.refs span.indirect { + font-style: italic; +} + +span.refs span.ref { + background-color: #aaaaff; + border-color: #ccccff #0033cc #0033cc #ccccff; +} + +span.refs span.tag { + background-color: #ffffaa; + border-color: #ffffcc #ffee00 #ffee00 #ffffcc; +} + +span.refs span.head { + background-color: #aaffaa; + border-color: #ccffcc #00cc33 #00cc33 #ccffcc; +} + +span.atnight { + color: #cc0000; +} + +span.match { + color: #e00000; +} + +div.binary { + font-style: italic; +} + +div.remote { + margin: .5em; + border: 1px solid #d9d8d1; + display: inline-block; +} + +/* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */ + +/* Highlighting theme definition: */ + +.num { color:#2928ff; } +.esc { color:#ff00ff; } +.str { color:#ff0000; } +.dstr { color:#818100; } +.slc { color:#838183; font-style:italic; } +.com { color:#838183; font-style:italic; } +.dir { color:#008200; } +.sym { color:#000000; } +.line { color:#555555; } +.kwa { color:#000000; font-weight:bold; } +.kwb { color:#830000; } +.kwc { color:#000000; font-weight:bold; } +.kwd { color:#010181; } diff --git a/index.iki b/index.iki index decd706f..cdcf1321 100644 --- a/index.iki +++ b/index.iki @@ -8,21 +8,6 @@ the Linguistics building at 10 Washington Place, in room 104 (back of the first One student session will be held every Wednesday from 3-4 on the fourth floor at 10 Washington Place. -Here is $some^2 x^{e \pi} + 3y$ math, and $$here_{is} some + more$$ End of math. -Except I want to add this: $\frac{-b\pm\sqrt{b^2-4ac}}{2a\pi^i}$ Okay now I'm finished. - -Here is a test: - - -> [[!format python """ -def f(x): - if x: - print "hello, world\n" - else: - return False -"""]] - -End of test. ## Announcements ## diff --git a/sandbox.mdwn b/sandbox.mdwn index 4a289750..a8bf5f4f 100644 --- a/sandbox.mdwn +++ b/sandbox.mdwn @@ -5,6 +5,13 @@ Here is [[!img y-combinator.jpg size="200x200" alt="clouds"]]. And rest of parag Try some math: . Okay, that's it! +Testing: + + What happens in [[Translating between OCaml Scheme and Haskell]] code block? + +End of code block. + + ---- [[!inline pages="tagged(foo)" show=0 archive=yes]]