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
# union of immutable types not to freeze/unfreeze | |
typealias NoFreeze Union(Number, String) | |
type Frozen{T,COUNT} | |
item::T | |
watchers::Set{WeakRef} | |
end | |
typealias FrozenArray{T,N,COUNT} Frozen{Array{T,N},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
# ---- ObjNode: capture of an object's output to show() ----------------------- | |
type ObjNode | |
# actual capture | |
obj | |
reused::Bool | |
items::Vector # ObjNode:s and strings/chars | |
# scratch space for recshow etc | |
strlen::Integer |
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
require("recshow.jl") | |
type T | |
x | |
y | |
end | |
type Unshowable; end | |
show(io::IO, x::Unshowable) = error("Tried to show Unshowable()") |
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
code = quote | |
function show_body_lines(io::IO, ex) | |
args = is_expr(ex, :block) ? ex.args : {ex} | |
for arg in args | |
if !is_linenumber(arg); print(io, '\n'); end | |
show(io, arg) | |
end | |
end | |
end |
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
macro expect(pred) | |
:( ($esc(pred)) ? nothing : error($"error: expected $pred == true") ) | |
end | |
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
function split_fdef(fdef::Expr) | |
@expect (fdef.head == :function) || (fdef.head == :(=)) | |
@expect length(fdef.args) == 2 | |
signature, body = tuple(fdef.args...) |
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
show_sexpr(ex) = show_sexpr(OUTPUT_STREAM, ex) | |
show_sexpr(io::IO, ex) = show_sexpr(io, ex, 0) | |
show_sexpr(io::IO, ex, indent::Int) = show(io, ex) | |
const sexpr_indent_width = 2 | |
function show_sexpr(io::IO, ex::Expr, indent::Int) | |
inner = indent + sexpr_indent_width | |
if (ex.head === :block) inter, post = ("\n"*" "^inner, "\n"*" "^indent) | |
else inter, post = (" ", "") |
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
# ---- @sexpr: S-expression to AST conversion ---- | |
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n | |
macro sexpr(ex) | |
esc(sexpr_to_expr(ex)) | |
end | |
sexpr_to_expr(ex) = expr(:quote, ex) |
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
is_expr(ex, head::Symbol) = (isa(ex, Expr) && (ex.head == head)) | |
is_expr(ex, head::Symbol, n::Int) = is_expr(ex, head) && length(ex.args) == n | |
# simple syntax version | |
macro get!(d, k, default) | |
quote | |
d, k = $(esc(d)), $(esc(k)) | |
has(d, k) ? d[k] : (d[k] = $(esc(default))) | |
end | |
end |
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
_ _ _(_)_ | A fresh approach to technical computing | |
(_) | (_) (_) | Documentation: http://docs.julialang.org | |
_ _ _| |_ __ _ | Type "help()" to list help topics | |
| | | | | | |/ _` | | | |
| | |_| | | | (_| | | Version 0.0.0+105549818.rb65f | |
_/ |\__'_|_|_|\__'_| | Commit b65f0478b4 (2012-12-26 20:02:44) | |
|__/ | | |
julia> include("test_show_dispatch.jl") | |
type error: subtype: expected Type{T<:Top}, got (CompositeKind,{:i0, Int64, #undef, #undef, #undef … :vals, Array{Any,1}, :#s176, Int64}) |
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
# Copyright (c) 2014: Toivo Henningsson | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WIT |
OlderNewer