Skip to content

Instantly share code, notes, and snippets.

View fcard's full-sized avatar

fcard

View GitHub Profile
@fcard
fcard / curried.jl
Last active August 29, 2015 14:22
Simple curried functions in Julia
# Definition
immutable Curried{N}
func::Function
end
Base.call(cf::Curried{1}, arg) = cf.func(arg)
Base.call(cf::Curried{1}, arg, args...) = error("Wrong numbers of arguments in curried function.")
Base.call{N}(cf::Curried{N}, arg) = Curried{N-1}(cf.func(arg))
@fcard
fcard / shortcircuiting-any-all-test.jl
Last active August 29, 2015 14:23
Testing performance of new short-circuiting any and all
#============================================================#
# detailed()
# prints expanded tests with average time,
# minimum time, maximum time, and result.
#
#------------------------------------------------------------
# summarized()
# prints average times.
#
#============================================================#
@fcard
fcard / sc-any-all-perf-detailed.jl
Last active August 29, 2015 14:23
Detailed results of performance tests on short-circuiting `any` and `all`
any([false for x = 1:100000])
#----------------------------------------------------------------
# old any
#----------------------------------------------------------------
result = false
average time = 279.591 microseconds
maximum time = 6.349 milliseconds
minimum time = 167.085 microseconds
@fcard
fcard / sc-any-all-perf-summary.jl
Last active August 29, 2015 14:23
Average times of the new short-circuiting `any` and `all`
#----------------------------------------------------------------
# any([false for x = 1:100000])
#----------------------------------------------------------------
old any = 274.780 microseconds
new any V1 = 400.905 microseconds
new any V2 = 329.738 microseconds
new any V3 = 358.323 microseconds
new any V4 = 289.087 microseconds
#----------------------------------------------------------------
@fcard
fcard / macromethod-examples.jl
Last active August 29, 2015 14:24
ExpressionPatterns Examples
ematch(:(a+b = c), :(a+b = c))
ematch(:(a+b = c), :(1+2 = 3), variable=:?)
ematch(:(a+b = c), :(1+2 = 3))
ematch(:(a,b), :(b,a))
ematch(:(a::!,b), :(b,a))
ematch(:(a::!,b), :(a,a))
ematch(:(a::?+b = c::?), :(1+b = 3), variable=:?)
ematch(:(a::?+b = c::?), :(1+d = 3), variable=:?)
ematch(:(x,x), :(1,2))
ematch(:((x::&),x), :(1,2), consistency=true)
@fcard
fcard / error_test.jl
Last active August 29, 2015 14:27
Julia Kaleidoscope Error
module ErrorTest
# VectorStream
type VectorStream{T}
vector :: Vector{T}
current :: Integer
VectorStream(vector) = new(vector, 0)
end
@fcard
fcard / lemmini_replay_translator.jl
Last active June 4, 2016 21:23
Lemmini to SuperLemmini replay translator
#!julia
include("version_check.jl")
"""
Translate between replays of Lemmini and SuperLemmini (when possible).
Interactive Usage:
LemmingReplayTranslator.translate("input.rpl", "output.rpl") # or:
LemmingReplayTranslator.main() #then write out the filenames as requested
CommandLine Usage:
@fcard
fcard / partial_underscore_generated.jl
Last active June 20, 2016 19:36
Evil hack to implement partial application in Julia
# julia 0.5 only!
module GeneratedPartial
export @partialize, partialize, ?
const MAX_UNDERSCORE = 10
macro times(n,action)
:(Any[$action for _ in 1:$n])
end
mapquote(f, l) = quote $((map(f,l))...); end
@fcard
fcard / selffunctions.jl
Last active July 28, 2016 15:11
SelfFunction: Function with an implicit argument and namespace (Example at the bottom)
## Note: This code is outdated and unmantained!
## Go here for the new version: https://github.com/fcard/SelfFunctions.jl
module SelfFunctions
export @selftype
immutable SelfFunction{F <: Function}
name::Symbol
typ::DataType
f::F
@fcard
fcard / MethodDispatchWoesFtGlobals.ipynb
Last active July 26, 2016 15:32
Notebook showing how global variables affect dispatch and inlining in Julia
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.