Hacker News new | past | comments | ask | show | jobs | submit login
Lisp in a Weekend (github.com/fragglet)
173 points by kelseyfrog on Oct 10, 2021 | hide | past | favorite | 38 comments



> There are lots of standard functions still missing, but rather than implement them as built-ins, they can be implemented from the primitives already available.

I'd be interested in reading more about this. For example, how was that set of primitives chosen? How does the author know that the set of primitives is sufficient?

A couple relevant (and interesting) links:

What is the "minimal" set of primitives needed for a Lisp interpreter? https://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part1/f...

What is the smallest definition of Lisp? https://www.reddit.com/r/lisp/comments/aklz0x/what_is_the_sm...


You'll need car, cdr, cons, atom, and eq. You'll also need ratom and patom for input and output. That's 7 primitive functions.

To be able to define recursive functions, you'll also need cond, lambda, setq (or define), quote, and function. That's five special forms.

Then you have to write read, eval, apply, and print in your implementation language. That gives you a minimal interpreter. These four functions aren't primitives, but you have to write them and you might as well expose them to the user. Eval and apply call a few other functions which are generally useful, such as assoc, evlis and pairlis.

This excludes arithmetic functions and a whole lot of other stuff you'd need for your interpreter to be useful.


Technically I think you could implement arithmetic as recursive functions operating on lists of different lengths.....


Interestingly, this was more or less the way that Lenat's program AM discovered numbers, and later arithmetic.


Hah, I actually used to work for Lenat but I didn't know this :)


you just inspired me to re-read GEB part 1 :-)


"Structure and interpretation of computer programs" (SICP) by Sussman and Abelson contains a recipe for scheme interpreter that can be implemented in any language and answers this as well (well, for scheme).


This site reckons there are 10: http://hyperpolyglot.wikidot.com/lisp#ten-primitives

Steve Yegge said there were seven (or five):

McCarthy had five.

On an x86 architecture - you can do it with one.

https://stackoverflow.com/questions/3482389/how-many-primiti...


I had imagined this was merely theoretical, but learned that there are computers implemented with a single instruction.

https://en.wikipedia.org/wiki/One-instruction_set_computer#M...

https://esolangs.org/wiki/OISC


In the functional realm which LISP inhabits, two combinators suffice: S and K.

https://en.wikipedia.org/wiki/SKI_combinator_calculus


in the context of S and K, lisp is not functional


I don't think movfuscator proves you only need one lisp primitive. Just that any language can be evaluated using mov's many variant forms.


I would consider Lisp 1.5 manual as the minimal set.


Consider alternatively: https://github.com/jart/sectorlisp/blob/main/sectorlisp.S https://github.com/jart/sectorlisp/blob/main/lisp.lisp

This does give me an idea to do it in even less, though. I'll have to spend a weekend on it.

It's also worth noting that the 1.5 metacircular interpreter is incomplete: https://github.com/kragen/stoneknifeforth#why--to-know-what-...


An old go of mine at filling in that incompleteness in a minimal way: https://github.com/darius/ichbins

It went a little too minimal in having no comments.


One of these days I'm gonna sit down and properly learn Lisp. My career as a programmer is still relatively young ( < 5 years), and learning lisp won't provide any value in my day-to-day work. But understand the concepts and paradigms of Lisp certainly has to have some value.


In some strange ways I wish I never had. And I'm truly not being overly hyperbolic when I say I struggle to enjoy programming in other languages.

I can do it but I can just never quite make the other languages fit how I want to think about the problems.

I think one major barrier is that nearly every language I have to use is lumbered with truly horrible data handling with the pervasive OO model that is so bad. I've used CLOS too much to never look at OO the same again.

And then if I'd rather just think of things as name/value collections, Clojure is just so easy.


I think you're just stuck with the wrong languages. I too like to structure nearly everything as plain data (name/value collections, lists, etc) these days, but I do it in TypeScript or Python or Rust. It doesn't require a lisp.


Lisps make it much, much easier though. My dayjob is python, but my heart yearns for clojure


Different strokes I guess. I played with Clojure a bit and it didn't really hook me; TypeScript is the language that I feel lets me beam my thoughts directly into code.


Fwiw, clojure is an acquired taste. It took me months to rewire my brain and get comfortable with it. Enjoy your time with TS and remember clojure if it ever doesn’t satisfy you anymore


Except for the macros you can use JS the same as you use Clojure.


I'd also recommend the Nand2Tetris course / book if you haven't done it already.


people have accumulated a lot of lisp impl on Make A Lisp repo

https://github.com/kanaka/mal


Although it's Scheme, I recommend "The Little Schemer". It's quite short, but fun, and by the end of it you should have the idea and be able to pick up other texts with ease.


Been leering at lisp in the corner for 23 years. Been doing c/c++/delphi/go/objC/swift all this time. I finally have had it with OO and static typing.

Javascript was my first intro to the liberation dynamic types and functional programming can bring when I built a project in Vue. I kinda loved it.

I started writing code in emacs lisp to help me write and navigate xml and it's been wonderful. now im deciding on whether to use Common Lisp or guile to build some projects. I'm sold.


Nitpick, but there's no need to lump OO and static typing together. IMO, both static typing and non-OO data structures are at their best when used together.


Indeed. go is an example. I much prefer interfaces and structural inheritance.


There's also SICP and Lisp in Small Pieces, maybe also Artificial Intelligence: A Modern Approach, that contain very interesting stuff with Lisp and in general.


Paip is a good and useful one to learn

https://github.com/norvig/paip-lisp


Oh man, that's the one I meant, not AIMA+Lisp. But AIMA is great in general.


have you read L.i.S.P cover to cover ? I still have to finish it

also do you know other books of the same kind ?


No, I read chapters from time to time, I'd love to have time to read all of it.

Maybe, I'll think about it.


It depends, if you switch to Emacs you could get proficient with Emacs Lisp. If you are used to think with objects, thinking with data + functions will change the way you solve problems. Finally you could use a modern Lisp like Clojure for a small project at work or your next job.

Besides that, the history of Lisps is fascinating, specially Lisp machines.


Decades ago I enjoyed working with XLisp [1] for a while. It seemed like well-done and simple Lisp that would be good as an extension language. I'm wondering if this Lisp took any inspiration from XLisp or has a similar goal.

[1] https://github.com/dbetz/xlisp


Someone also thought so in the 1980's at AutoDesk; they based AutoCAD's AutoLisp on an early version of XLisp.


Thanks for sharing this. It's easy to forget what can be achieved in a weekend. Very cool project!


Scheme is not that interesting …

Even using js to do cl like is hard.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: