TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

μLithp - a Lisp in 27 lines of Ruby

137 pointsby Peterisover 12 years ago

17 comments

mahmudover 12 years ago
Before this devolves into another farcical, Lisp arm-chair punditry: at 9 operators it's pretty much a kernel untyped lambda-calculus with pairs. And <i>just</i> that.<p>The implementation is as trivial as the concept is profound. The discussion should be about the lambda-calculus, not Lisp, which is a far more complex beast. And much less about Lisp dialects, Greenspun's, or the usual BS topics that invariably appear on any L-word thread.
评论 #5010975 未加载
评论 #5010916 未加载
mericover 12 years ago
<i>plug</i><p>Once upon a time I wrote a lisp to lua <i>compiler</i> in 100 lines. <a href="https://github.com/meric/l2l/commit/a530f0133e002c3981937d21b24d552041008181" rel="nofollow">https://github.com/meric/l2l/commit/a530f0133e002c3981937d21...</a><p>It's now over a thousand. <a href="https://github.com/meric/l2l/" rel="nofollow">https://github.com/meric/l2l/</a>
bitopsover 12 years ago
I think this is a neat project and a nice demonstration of how Lisp-influenced Ruby is.<p>However, whenever people post "Lisp in Ruby" stories, I always hope that it'll be a "Clojure in Ruby" implementation. I am surprised no-one has done it yet.
评论 #5010437 未加载
评论 #5010388 未加载
评论 #5010408 未加载
dschiptsovover 12 years ago
Don't call it Lisp.<p>Lisp <i>begins</i> with something like this:<p><pre><code> (defmacro when (test &#38;body forms) `(cond (,test nil ,@forms))) </code></pre> Without using underlying list structure, environments, lexical scoping and reader function it is just a lisp-like syntax.<p>Lisp without lists at its core is nothing but another clumsy language. Look at Clojure - what a mess.
评论 #5012153 未加载
quartertoover 12 years ago
Yeah, 27 lines. Unless you count the ~120 lines of sexpistol.<p><a href="https://github.com/aarongough/sexpistol" rel="nofollow">https://github.com/aarongough/sexpistol</a>
评论 #5010668 未加载
评论 #5010922 未加载
draegtunover 12 years ago
Related: <a href="http://news.ycombinator.com/item?id=3511100" rel="nofollow">http://news.ycombinator.com/item?id=3511100</a><p>Above was HN submission from early last year, <i>Lisp in 32 lines of Ruby</i>, which was the original blog post of this code by Fogus.
joethephishover 12 years ago
Not sure what this proves exactly. For fun, here's a Javascript equivalent in 27, err, "lines":<p><pre><code> module.exports = function() { var atom = function(val) { return val instanceof Array ? false : true; }; var env = { label: function(sexpr, senv) { senv[sexpr[1]] = evaluate( sexpr[2] ); }, quote: function(sexpr, senv) { return sexpr[1]; }, "==": function(sexpr, senv) { return evaluate(sexpr[1], senv) == evaluate(sexpr[2], senv); }, head: function(sexpr, senv) { return evaluate(sexpr[1], senv)[0]; }, tail: function(sexpr, senv) { return evaluate(sexpr[1], senv).slice(1); }, conc: function(sexpr, senv) { return [evaluate(sexpr[1])].concat(evaluate(sexpr[2])); }, "if": function(sexpr, senv) { return evaluate(sexpr[1], senv) ? evaluate(sexpr[2], senv) : evaluate(sexpr[3], senv); }, atom: function(sexpr, senv) { return atom(sexpr[1]); }, lambda: function(sexpr, senv) { return function(lexpr, lenv) { for(var i=0; i&#60;sexpr[1].length; ++i) lenv[sexpr[1][i]] = evaluate(lexpr[i+1], lenv); return evaluate(sexpr[2], lenv); }; } }; var evaluate = function(sexpr, senv) { senv = senv || env; if( atom(sexpr) ) return senv[sexpr] !== undefined ? senv[sexpr] : sexpr; else return senv[sexpr[0]](sexpr, senv); }; this.evaluate = evaluate; }; </code></pre> Example:<p><pre><code> var notlisp = require("./notlisp.js"); var l = new notlisp(); l.evaluate( ["label", "second", ["lambda", ["x"], ["head", ["tail", "x"]]]] ); l.evaluate( ["second", ["quote", [1, 2, 3]] ] );</code></pre>
评论 #5015045 未加载
sejjeover 12 years ago
I want to learn a lisp variant. I'm okay in several scripting languages--Python, Ruby, PHP.<p>Any obvious choice? (If not, I imagine I'd like to learn the most widely-used)
评论 #5011290 未加载
评论 #5011384 未加载
评论 #5012321 未加载
krosaenover 12 years ago
related: Norvig's implementation of lisp in python:<p><a href="http://norvig.com/lispy.html" rel="nofollow">http://norvig.com/lispy.html</a>
评论 #5011090 未加载
nine_kover 12 years ago
1993: «Any sufficiently complicated C or Fortran program contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.» [1]<p>20 years later: for Ruby users, situation improves! :)<p>[1] <a href="http://en.wikipedia.org/wiki/Greenspuns_tenth_rule" rel="nofollow">http://en.wikipedia.org/wiki/Greenspuns_tenth_rule</a>
评论 #5010417 未加载
评论 #5010560 未加载
tzamanover 12 years ago
Is it normal that I don't have the slightest idea what I'm reading here, or is it just me?
评论 #5010396 未加载
评论 #5010565 未加载
评论 #5010402 未加载
hk__2over 12 years ago
You should use Docco for your page, I find it much more readable: <a href="http://jashkenas.github.com/docco/" rel="nofollow">http://jashkenas.github.com/docco/</a>
评论 #5010640 未加载
评论 #5011191 未加载
评论 #5010428 未加载
dbyrdover 12 years ago
Cool project, but I think it's been done before in less lines: <a href="https://gist.github.com/4176087" rel="nofollow">https://gist.github.com/4176087</a>
评论 #5010432 未加载
评论 #5010423 未加载
评论 #5010420 未加载
asimjalisover 12 years ago
Who’s up for implementing a μRuby on top of this μLisp?
rrmmover 12 years ago
I love the economy of lisp implementations in dynamic languages. It's especially nice because you don't have to worry about the memory management.<p>On the otherhand, I've been interested in doing a lisp in low memory environments (uC's, etc). I've done a dialect in C using a semi-space garbage collector. But I'm curious if anyone's done any work on lisps in resource constrained environments.
lopatinover 12 years ago
Really? Lithp? Not that I'm offended, but the pun seems unnecessary.
评论 #5013245 未加载
dmcdougall_over 12 years ago
My one question is: Why?
评论 #5010780 未加载
评论 #5010911 未加载
评论 #5010825 未加载
评论 #5010954 未加载