#| #| #| #| #|
#|
| // LazySeq(head, tailthunk) -> more to go | |
| // LazySeq(head, new Empty) -> end of sequence | |
| function LazySeq(head, tailthunk) { | |
| this.head = head | |
| this.tail = tailthunk | |
| } | |
| function Empty() {} | |
| var empty = new Empty |
| abstract Object | |
| type Instance <: Object | |
| class::Object | |
| attrs::Dict | |
| get::Function | |
| call::Function | |
| self::Object |
| # copy pygmentized code to clipboard as rtf | |
| # | |
| # $ copyrtf code.py | |
| # $ copyrtf code.py monokai | |
| # $ copyrtf code.py monokai 24 | |
| copyrtf() { | |
| local STYLE | |
| local FONTSIZE | |
| if [[ -z $2 ]]; then | |
| STYLE="monokai" |
| # TODO: | |
| # | |
| # - figure out why you can't have two guards in a row | |
| # - see if the code can be simplified | |
| # - find a way to infer return Array type | |
| # @guarded (Int, Symbol)[(x, y) for x in 1:5, :when=iseven(x), y in [:a, :b, :c]] | |
| # => [(2, :a), (4, :a), (2, :b), (4, :b), (2, :c), (4, :c)] | |
| [(x, y) for x in 1:5, y in 1:5] |
| abstract BinaryTree | |
| immutable Node <: BinaryTree | |
| value | |
| left::BinaryTree | |
| right::BinaryTree | |
| end | |
| immutable Leaf <: BinaryTree | |
| end |
| module Unify | |
| using FunctionalCollections | |
| export unify, extended, lvar, Anything | |
| const _LogicVarKey = 0x1f75f6e80ac3828f | |
| immutable LogicVar | |
| name |
| remove_quote_block(val) = val | |
| remove_quote_block(ex::Expr) = | |
| ex.head == :block && length(ex.args) == 2 ? ex.args[2] : ex | |
| remove_quote_block(exs...) = map(remove_quote_block, exs) | |
| function syntax_bindings(ex, template::Symbol, collected::Dict) | |
| s = string(template) | |
| if s[1] == '_' && s[end] == '_' | |
| collected[template] = ex |
| # time | |
| # ==== | |
| macro time(ex) | |
| quote | |
| local t0 = time_ns() | |
| local val = $(esc(ex)) | |
| local t1 = time_ns() | |
| println("elapsed time: ", (t1-t0)/1e9, " seconds") | |
| val |
| # Using @async | |
| immutable Continuation | |
| args | |
| end | |
| cont(args...) = Continuation(args) | |
| immutable Actor | |
| ref::RemoteRef | |
| mailbox::RemoteRef |