11 ms·
Lisp in about 200 lines of Ruby
- Anon84 17y agoA upgrade to Ruby?
- tyrmored 17y agohttp://img43.imageshack.us/img43/2413/johnmccarthyposter1.jpg http://img43.imageshack.us/img43/2413/johnmccarthyposter1.jp...
- pjonesdotca 17y agoThanks for that. It's been my motivational poster for a while now.
- gaius 17y agoGreenspun's Law in action ;-)
- mmphosis 17y agoGreenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp." http://philip.greenspun.com/research/ http://philip.greenspun.com/research/
- smithjchris 17y agoIn which they will write Ruby in 200 lines of Lisp.
- gord 17y agoThis makes me vocalize something Ive wondered about... Whats the smallest subset of lisp which you need to implement in order to bootstrap the language? So, given this small subset, one can implement the rest of say scheme or common lisp or arc on top of. I vaguely recall Sussman or Ebelson implementing car and cadr in terms of lambdas, for example. It seems this should be quite modular, given so many implementations of lisp [ in javascript, PHP, etc now Ruby ]. So that new lisps might be easily brought up over this kernel.
- mdemare 17y agoAccording to pg, seven: (quote, atom, eq, car, cdr, cons, and cond) Eighth paragraph: http://www.paulgraham.com/ilc03.html http://www.paulgraham.com/ilc03.html
- onewland 17y agoQuote as a predefined macro could be important though, in a Lisp, if you expect to be doing a lot of macro magic, and I don't see it here. This is cool, though, and very readable; I know what all the code is doing with a quick glance. Cheers to the author.
- jmatt 17y agoYa that should be the minimum required to bootstrap. I always thought the definitive minimum code for lisp was here: http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp Or at least from a historic perspective.
- procrastitron 17y agoWell, lambda calculus is Turing complete, so you could just stick with a call-by-value version of that. However, you'd want to add macros if you wanted to extend the syntax of the language. Since you mentioned car and cdr in lambdas, they'd be defined like this: NIL = (lambda (x) (lambda (y) y)) CONS = (lambda (ar) (lambda (dr) (lambda (op) (op ar dr)))) CAR = (lambda (expr) (expr (lambda (ar dr) ar))) CDR = (lambda (expr) (expr (lambda (ar dr) dr)))
- twilightsentry 17y agoWell, you can define pairs like this (as long as you've got lexical scope): (setq cons (lambda (x xs) (lambda (msg) (if (eq msg 'car) x xs))) (setq car (lambda (xs) (xs 'car))) (setq cdr (lambda (xs) (xs 'cdr))) That only uses 'setq, 'lambda, 'if, 'eq, and quoted symbols. That pretty much gives you the untyped lambda calculus, plus some side effects. Throw in the appropriate macros and you've got the core of Scheme and Arc, without any I/O or efficient data representations. You can take this pretty far. Essentially, you just need 'lambda and application. You could use church numerals for numbers, monads for side effects, the y-combinator for recursion, etc.
- z8000 17y agoDoes lisp not support negative numbers? :)
- kidko 17y agoFixed in 1.4.2... Thanks for pointing that out!
- bodhi 17y agoI wonder if this says more about Ruby, or more about Lisp?
- lisper 17y agoLisp in about 100 lines of Python: http://www.flownet.com/ron/lisp/l.py http://www.flownet.com/ron/lisp/l.py
- mahmud 17y agoPlease instruct your httpd to serve *.py files as "text/plain". Right now it's forcing a download. Win32 FF.
- lisper 17y agoIt's being served as text/x-python, which I think is appropriate. So it's not the server that's "forcing" a download, it's your client. I suspect you're using FireFox, which seems AFAICT to be b0rken in this regard.
- statictype 17y agoI threw something like this together in python some time ago: http://bitbucket.org/statictype/code/src/tip/pylisp/ http://bitbucket.org/statictype/code/src/tip/pylisp/ Not as elegant though.
- MaysonL 17y agoA micro-Lisp compiler (to x86 executable) in about 100 lines of OMeta: http://www.vpri.org/pdf/m2009011_chns_mng.pdf http://www.vpri.org/pdf/m2009011_chns_mng.pdf examples given which run about 70% of the speed of equivalent C code.
- sb 17y agoThat's a nice one, albeit several simplifications are made in there (e.g. from a quick glance I could not find anything dealing with scopes [the prefixing with "_V_" for variables might probably hint at its non-existence]). Nevertheless, impressive work from one of the most interesting projects around.
- stcredzero 17y agoX in (some small number) of lines of Y This is generally an indicator that language_power(X) > language_power(Y)
- RiderOfGiraffes 17y agoI think you have that the wrong way round. Taking a specific example, "Lisp in 100 lines of Ruby" means that once you have Ruby, you have Lisp. That means that anything you can do in Lisp can be done in Ruby, and hence Ruby is at least as powerful. That means: X in (some small number) of lines of Y implies language_power(X) <= language_power(Y) Exactly the opposite of what you said.