Generic function
julia> const fib_cache = Dict()
Dict{Any,Any} with 0 entries
julia> _fib(n) = n < 3 ? 1 : fib(n-1) + fib(n-2)
_fib (generic function with 1 method)| ((* extends 'article.tplx' *)) | |
| ((* block commands *)) | |
| ((( super() ))) | |
| % define custom margins | |
| \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} | |
| \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}} | |
| ((* endblock commands *)) | |
| ((* block predoc *)) |
| #!/bin/sh | |
| # | |
| # Generate PDF file from ipynb notebook. | |
| # Several tricks are done to post-process the latex files. | |
| if [ $# -ne 1 ]; then | |
| echo "Usage: `basename $0` filename" | |
| exit 1 | |
| fi |
| julia> import Base: promote_rule, convert | |
| julia> struct USD | |
| value | |
| end | |
| julia> struct Painting | |
| rating | |
| end |
| a | |
| x | |
| x | |
| x | |
| x | |
| x | |
| x | |
| x | |
| x | |
| x |
Functors are types that can be mapped over.
Two laws (https://wiki.haskell.org/Functor#Functor_Laws):
g then f is equivalent to mapping the composed function (f ∘ g)fmap is a mapping function that operates on functors. It can be defined for
specific objects so that the provided mapping function can be applied in the
julia> macro name(ex)
ex.head === :function ||
error("can be used for function defintions only")
name = ex.args[1].args[1]
assignment = :(local __NAME__ = $name)
pushfirst!(ex.args[2].args, assignment)
return ex
end
@name (macro with 1 method)From Mason Protter in Slack:
struct FullyCurried end
macro curried(fdef)
f = fdef.args[1].args[1]
fargs = fdef.args[1].args[2:end]
arity = length(fargs)
body = fdef.args[2]| using Plots | |
| function batman(; lw = 4) | |
| let sqrt = x -> x > 0 ? Base.sqrt(x) : NaN | |
| v1(x) = 2*sqrt(-abs(abs(x)-1)*abs(3-abs(x))/((abs(x)-1)*(3-abs(x)))) * (1+abs(abs(x)-3)/(abs(x)-3)) * sqrt(1-(x/7)^2)+(5+0.97(abs(x-.5)+abs(x+.5))-3(abs(x-.75)+abs(x+.75))) * (1+abs(1-abs(x))/(1-abs(x))) | |
| v2(x) = (2.71052 + 1.5 - 0.5 * abs(x) - 1.35526 * sqrt(4-(abs(x)-1)^2)) * sqrt(abs(abs(x)-1)/(abs(x)-1)) + 0.9 | |
| v3(x) = (-3)*sqrt(1-(x/7)^2)*sqrt(abs(abs(x)-4)/(abs(x)-4)) | |
| v4(x) = abs(x/2)-0.0913722*x^2-3+sqrt(1-(abs(abs(x)-2)-1)^2) | |
| x = -8:0.0005:8 |