Skip to content

Instantly share code, notes, and snippets.

@simenge
Last active August 9, 2017 20:51
Show Gist options
  • Save simenge/55f5f9fd72e67e07e359bb06aa73b702 to your computer and use it in GitHub Desktop.
Save simenge/55f5f9fd72e67e07e359bb06aa73b702 to your computer and use it in GitHub Desktop.
ylisp compiler stuff
Input:
(begin
(def (inc-by x) (+ x 1))
(inc-by 1)
('a' | gsub 'a' 'b' | gsub 'b' ('a' | upcase))
(if (eq? 1 1 (+ 0 (- 2 1))) (puts (+ 1 2 3)))
(-> (a 1 *b **c d: e: 1 &d) a)
(-> () (set! inc-by 1))
)
Output: (ruby)
lambda do
__add__ = lambda do |*args|
args.reduce(:+)
end
__sub__ = lambda do |*args|
args.reduce(:-)
end
__div__ = lambda do |*args|
args.reduce(:/)
end
__mul__ = lambda do |*args|
args.reduce(:*)
end
__mod__ = lambda do |*args|
args.reduce(:%)
end
__lt__ = lambda do |*args|
args.reduce(:<)
end
__gt__ = lambda do |*args|
args.reduce(:>)
end
eq_p = lambda do |*args|
if (args.size == 1)
raise(ArgumentError, "eq? requires 2+ arguments")
else
if (args[0] == args[1])
if (args.size == 2)
true
else
eq_p.call(*args[1..-1])
end
end
end
end
join = lambda do |*args|
args.map do |x|
x.to_s
end.join("")
end
puts = method(:puts)
inc_by = lambda do |x|
__add__.call(x, 1)
end
inc_by.call(1)
'a'.gsub('a', 'b').gsub('b', 'a'.upcase())
if eq_p.call(1, 1, __add__.call(0, __sub__.call(2, 1)))
puts.call(__add__.call(1, 2, 3))
end
lambda do |a = 1, *b, **c, d:, e: 1, &d|
a
end
__gensym1234 = binding.call
lambda do
ruby_eval.call(join.call(inc_by, "=", 1), __gensym1234)
end
end.call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment