Skip to content

Instantly share code, notes, and snippets.

Three example Raven programs:

  • malloc.rv, which is the memory allocator currently used in Raven's standard library and invoked by the compiler where needed.
    • It may well be the worst allocator ever written, but it gives an idea of what low-level pointer-programming looks like (bearing in mind this is not the language's design priority).
  • complex.rv is also taken from the standard library and shows how you can define a new numeric type and various operations on it, using dispatch and pattern matching.
    • There's no Number type or any other abstract traits yet, interfaces are still informal, though tools for formal interfaces are planned.
  • brainfuck.rv is the most complete and realistic program to date, showing parsing to a recursive AST and the core interpreter loop.
  • In future I expect programs to mostly look a bit more Python- or Clojure-like, centred around generic dictionaries and lists rather than custom types, but those data structures don't yet exist. This gives an unfinished bu

Keybase proof

I hereby claim:

  • I am MikeInnes on github.
  • I am onemoreminute (https://keybase.io/onemoreminute) on keybase.
  • I have a public key whose fingerprint is DBF9 C2D0 9AEA 16E5 6A95 FAEF DFD3 2796 D8FD 8A25

To claim this, I am signing this object:

isexpr(x::Expr, ts...) = x.head in ts
isexpr{T}(x::T, ts...) = T in ts
macro with(exprs...)
exprs = collect(exprs)
target = nothing
if length(exprs) > 1 && !isexpr(exprs[end], :(::))
target = esc(exprs[end])
pop!(exprs)
end
[
;; The app tag is kind of like global scope. You assign behaviors that affect
;; all of Light Table to it.
[:app :lt.objs.style/set-skin "dark"]
[:app :lt.objs.plugins/load-js "user_compiled.js"]
[:app :lt.objs.langs.julia/julia-path "C:\\Users\\Mike\\Julia 0.3.0-prerelease\\bin\\julia.exe"]
;; The editor tag is applied to all editors
[:editor :lt.objs.editor/no-wrap]
[:editor :lt.objs.style/set-theme "june"]
function rand_first_index(n, k)
r = rand()
p = k/n
i = 1
while p < r
i += 1
p += (1-p)k/(n-(i-1))
end
return i
end
SetAttributes[Dictionary, Orderless];
Dictionary[key_ -> val_, ___][key_] := val;
Dictionary[___][key_] := key;
d_Dictionary.key_ ^:= d[key];
x_ /. Dictionary[rs___] ^:= x /. {rs};
Dictionary[{rs___}] := Dictionary[rs];
Assoc[Dictionary[key_ -> _, rs___], key_ -> val_] :=
Dictionary[key -> val, rs];
Assoc[Dictionary[rs___], key_ -> val_] := Dictionary[key -> val, rs];
@MikeInnes
MikeInnes / startup.jl
Last active February 5, 2023 12:54
Some useful macros for Julia
# Repeat an operation n times, e.g.
# @dotimes 100 println("hi")
macro dotimes(n, body)
quote
for i = 1:$(esc(n))
$(esc(body))
end
end
end
;; Paredit's features (http://www.youtube.com/watch?v=D6h5dFyyUX0)
;; in clojure/clarity.
;; All examples can be done quickly with the keyboard in e.g.
;; Sublime Text - no plugins required.
defn my-command []
(interactive)
save-excursion
(do-some-things)
(ns cueball
(:use [cljs.compiler :exclude [munge macroexpand-1]]
clojure.walk))
;; Implementation of `quote` with unquoting
(defn seqable? [e]
(if-not (string? e)
(try (seq e)
(catch Exception e false))))