Create a gist now

Instantly share code, notes, and snippets.

@michaelbartnett /mylang.txt Secret
Last active Oct 12, 2017

Embed
What would you like to do?
ranked code size creating a lambda counter, incrementing once, and assigning result to a local
I'm not saying terseness is an inherent virtue, I'm just saying it be like it is.
-- Lua
local counter_once = (function() local x = 41; return function() x = x + 1; return x; end end)()()
// Old JavaScript
var counterOnce = (function () { var x = 41; return (function () { x++; return x; })})()()
;; Emacs Lisp
(let ((counter-once (funcall (lexical-let ((x 41)) (lambda () (setq x (1+ x)) x))))))
// C#
var counterOnce = new Func<Func<int>>(() => { var x = 41; return (() => ++x);})()();
// C++14
auto counterOnce = []() {auto x = 41; return [&x]() { ++x; return x; };}()();
;; Racket Scheme
(let [(counter-once ((let [(x 41)] (lambda () (set! x (+ 1 x)) x))))])
// Modern Javascript
let counterOnce = (() => { let x = 41; return (() => ++x)})()()
// MichaelScript
let counter_once = fn () { let x = 41; fn() do x += 1 }()()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment