Skip to content

Instantly share code, notes, and snippets.

@eccstartup
Created January 14, 2015 13:46
Show Gist options
  • Save eccstartup/36637d96355bd5ca8188 to your computer and use it in GitHub Desktop.
Save eccstartup/36637d96355bd5ca8188 to your computer and use it in GitHub Desktop.
module MyMacros
export @map, @apply, @filter, @foldr, @foldr1, @foldl, @foldl1, @nobrace, @nobrace1
macro map(f, args...)
quote
map($f,$(args...))
end
end
macro apply(f, args...)
quote
apply($f, $(args...))
end
end
macro filter(f, args...)
quote
filter($f, $(args...))
end
end
macro foldr(op, v0, itr...)
quote
foldr($op, $v0, $(itr...))
end
end
macro foldr1(op, itr...)
quote
foldr($op, $(itr...))
end
end
macro foldl(op, v0, itr...)
quote
foldl($op, $v0, $(itr...))
end
end
macro foldl1(op, itr...)
quote
foldl($op, $(itr...))
end
end
macro nobrace(f, args...)
quote
$f($(args...))
end
end
macro nobrace1(args...)
quote
begin
$(args...)
end
end
end
end
@eccstartup
Copy link
Author

julia> @nobrace versioninfo
Julia Version 0.3.5
Commit a05f87b* (2015-01-08 22:33 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.4.0)
  CPU: Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

@eccstartup
Copy link
Author

julia> @nobrace map x->x+1 1:10
10-element Array{Int64,1}:
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11

julia> @nobrace map (+) 1:10 11:20
10-element Array{Int64,1}:
 12
 14
 16
 18
 20
 22
 24
 26
 28
 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment