Skip to content

Instantly share code, notes, and snippets.

View rubber-duck's full-sized avatar

Rafael Munitić rubber-duck

  • atena.tech
  • Zagreb, Croatia
  • 15:52 (UTC +02:00)
View GitHub Profile
module gl.gl;
enum : uint
{
MAX_TESS_CONTROL_OUTPUT_COMPONENTS = 0x8E83,
ONE_MINUS_SRC_ALPHA = 0x0303,
STENCIL_BACK_FUNC = 0x8800,
AND_REVERSE = 0x1502,
....
import std.stdio;
class Foo
{
void foo() { writeln("foo1"); }
void foo() { writeln("foo2"); }
void bar() { writeln("bar"); }
};
int main()
(defmacro matchfn
"Compiles a pattern match to a lambda that matches against it's parameters.
Patterns are analyzed and if no pattern contains varargs (&) then patterns will be split in to
different fn aritity overloads. If & is present in one or more patterns all arguments are captured
in to args seq and matching is done on it as ([pattern] :seq)."
[& body]
(let [fname (if (symbol? (first body)) (first body) nil)
cases (if fname (rest body) body)
pattern-expression (partition 2 cases)
pattern-varargs (some (fn [[pattern _]] (when-not (= :else pattern) (some (partial = '&) pattern))) pattern-expression)]
(ns test)
(defn foo [a]
{:pre [(> a 2)]}
(println a))
(binding [*assert* false]
(println *assert*)
(foo 2))
=> (defmacro locking-read
"Utility to lock a readLock from the read-write lock provided and put body part in a try expression body where
finally unlocks the lock."
[rwlock & body]
`(let [readlock (.readLock ~rwlock)]
(.lock readlock)
(try
(do ~body)
(finally (.unlock rwlock)))))