Skip to content

Instantly share code, notes, and snippets.

View lfranchi's full-sized avatar

Leo Franchi lfranchi

View GitHub Profile
@cqfd
cqfd / darius-for.el
Last active December 10, 2015 04:28
List comprehensions, @darius style.
;; An Emacs Lisp port of Darius Bacon's list comprehension macro.
(setq lexical-binding t)
(defmacro for (bindings body)
(declare (indent defun))
(expand-for bindings body '(lambda () ())))
(defun expand-for (bindings body rest-var)
(if (null bindings)
# A list is either () or (head, list).
# list = () | (head, list)
def make_list(xs): return (xs[0], make_list(xs[1:])) if xs else ()
L = make_list('abcd')
## L
#. ('a', ('b', ('c', ('d', ()))))
@andkerosine
andkerosine / raskell.rb
Created August 15, 2012 05:56
Haskell-like list comprehensions in Ruby
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@