[HN Gopher] Learn Lisp the Hard Way
___________________________________________________________________
Learn Lisp the Hard Way
Author : Tomte
Score : 197 points
Date : 2023-01-10 15:31 UTC (7 hours ago)
(HTM) web link (llthw.common-lisp.dev)
(TXT) w3m dump (llthw.common-lisp.dev)
| JLCarveth wrote:
| A question I have that's not answered by the link is _why_ would
| I want to learn lisp? If you were starting a project today, what
| are some of the features Lisp offers that make it a better choice
| than any other (more popular) language? And do those features
| outweigh the lack of community the larger languages have?
| lordgroff wrote:
| There are macros in other languages but nowhere will they merge
| with the language as effortlessly as in the case of Lisp's
| syntax.
|
| The way Lisp is structured means that almost certainly if
| you're missing language feature X you can bolt it on, stacking
| the new features on top of each other to make whatever
| abstraction you see fit.
|
| It's the kind of thing that makes a Lisp head amused when
| someone talks about the genius of C# and LINQ (as an example).
| If you need an abstraction in Lisp, you can almost certainly
| build it in an ergonomic fashion that just doesn't have a
| parallel in other languages.
|
| It's one of those powers you don't fully appreciate until you
| have it and then every other language seems hilariously
| inadequate in comparison. With great power cones great
| responsibility and it can all crumble with a lack of discipline
| (hence why I'm also a fan of ridiculously restrictive languages
| like Go), but honestly the sort of meta programming possible in
| Lisp has no equal I know of.
| michaelsbradley wrote:
| Maybe try Nim. It's a statically typed compiled language
| _and_ sports a macro system that allows for direct
| manipulation of the AST. If you don 't need to write full
| blown macros, Nim also offers templates, which are a simpler
| form of Nim's macros: simpler to write, but not quite as
| expressive.
|
| https://nim-lang.org/docs/manual.html#macros
|
| https://nim-lang.org/docs/manual.html#templates
| dmux wrote:
| For me, I've always been fascinated with "live programming
| environments" and that's been the driving force behind me
| diving into Common Lisp. I've really come to appreciate this
| way of working: I was recently working on a web-app that talks
| to a PostgreSQL database. Normally when developing an app that
| talks to a database, I'll likely poke around and test out some
| queries using pgAdmin, the command line, etc. In my Common Lisp
| app however, once I've got a connection-object to the database,
| I can just write my queries _within_ the running Lisp system
| and completely remove the need for those other tools. The plus
| side is that the data I get back is already in a format that
| Lisp can deal with. The liveness of the Lisp system really
| allows for "exploratory" programming.
| rjsw wrote:
| I use Common Lisp because applications run faster than those
| written in Python or Ruby and are easier for me to write than
| if I was using C++.
| julianeon wrote:
| A good use case is Emacs.
|
| Haven't you ever thought "hmm, I could do this job faster if I
| had my own plugin/extension here?"
|
| Lisp is really good for that, when used within Emacs.
| Extensions are very very simple, basically just the simplest
| functions inserted into your .emacs file.
| mikelevins wrote:
| If the Lisp way of thinking about and solving problems is a
| good fit for you, then you should learn it because it will make
| you happier and more productive. If not, then don't bother.
|
| That's a Catch-22, of course. How will you know if it's a good
| fit for you unless you learn it?
|
| So that reduces the decision to: if you are curious whether
| Lisp is a good fit for you, learn enough of it to find out. If
| you're not curious about that, don't bother.
|
| But you might want a preview of what things make it a good fit
| for some people. Lisp in general, and Common Lisp in
| particular, is a good fit for me because its default mode of
| operation is to start the Lisp running and teach it by
| interacting with it expression-by-expression how to be the
| program I want to build. Common Lisp is consciously designed to
| work this way, and provides a host of well-designed
| conveniences for it. It turns out that working that way makes
| me happier and more productive than working any other way, so
| it's my favorite programming language.
|
| Not very many other programming languages work that way, but to
| be fair, some do. Examples of some that do are Smalltalk,
| FORTH, and Factor.
|
| Some languages and implementations provide more support than
| others for that style of work. The most comprehensive support
| for it is to be found in Common Lisp and Smalltalk
| implementations.
|
| If that sounds interesting, then it's probably worth your time
| to learn Lisp (or one of the other languages I mentioned). If
| not, then I wouldn't worry about it.
| [deleted]
| FatActor wrote:
| Do you speak multiple human languages? I speak English and
| French. There are subjective future tenses in French that can
| be transliterated, but don't really capture the spirit of the
| writer: one needs to elaborate in English with such verbosity
| that it takes a page in English to explain a sentence in
| French. I'm sure the reverse is true were I a native French
| speaker. My theory as to why so many existentialists were
| french was because the language was made for it. :)
|
| Same goes for computer languages. I use LISP when I have
| computer science-y things I want to explore. For example, I was
| working on a path finding algorithm for fun years ago and I
| went to LISP because it is much more natural at conceptual
| programming. But I wouldn't use LISP to create a GUI, even
| though it can, nor would I try to write performant 3D graphics.
| But I would use it to craft a game engine (I wrote a frame
| language in the early 2000's as part of a game engine that I
| never finished because once i got the agents decision making
| working I felt satisfied enough).
|
| The right tool for the right job...
|
| Need to munge a file? PERL
|
| Need to write an embedded application? C
|
| Need to write a GUI? A JS framework (or Qt, or Motif/X if I'm
| feeling nostalgic)
|
| Need to write a fast loop? ASM
|
| Need to write a something stats-related? Python, R, JMP
|
| Need to explore a computer science problem? LISP, SmallTalk (I
| don't know Haskell)
|
| Need to work on a project that you're forced to? C++ :)
| satvikpendem wrote:
| Read this: An Intuition for Lisp Syntax
| (https://stopa.io/post/265)
|
| Lisp is simply a different way of thinking, in S-expressions.
| It's hard to explain but easier to show you, via the above
| link.
| ekidd wrote:
| I haven't actively used Common Lisp in years. But for a long
| time, I used it professionally.
|
| Common Lisp's greatest strength is that it's "the programmable
| programming language." You can customize everything from the
| lexer to the syntax, and you can extensively customize or even
| replace the object model. It's trivial to write code that
| writes code.
|
| There are some limitations. Haskell, for example, is less
| customizable but it works very well at high levels of
| _mathematical_ abstraction.
|
| Now, in practice, I don't often need the specific kinds of
| power that Lisp offers. Or rather, when I do need it, I don't
| need that power instantly at my fingertips. Completely
| customizing your programming language is something you should
| think long and hard before doing, and the median team will do
| it very badly. So I'm happy with the tradeoff offered by Rust
| macros, for example: They're harder to use than Common Lisp
| macros, so you only use them when you need them badly enough.
| Even for most above-average teams, I think it's a net win for
| macros to be a bit obnoxious to use.
|
| But if you ever find yourself on a small team of incredibly
| talented programming language designers, and you're working in
| a problem space where no off-the-shelf language can do what you
| need, then Common Lisp is well worth a hard look.
|
| Paul Graham's "On Lisp" is actually an excellent overview of
| the kinds of things you can do with Lisp. Norvig's first AI
| book is also a good demonstration of Lisp, even if the "AI"
| part is hopelessly obsolete at this point.
| JLCarveth wrote:
| Just downloaded "On Lisp", thank you for the suggestion!
| srcreigh wrote:
| Lisp shines with macros. I like to use macros to add new static
| checks to the code
|
| For ex I wrote about one such check here
| https://tech.perpetua.io/2022/01/generating-sqlite-bindings-...
|
| This macro checks SQLite table/column references. Aka, if you
| try to access user_id when the table doesn't have that column,
| the "user_id" text in your code will appear as a syntax error
| in your IDE and when you run the code.
|
| The typed racket project is a bigger example. They added a
| typechecking system to the language, including a new typescript
| like variant.
|
| I'm not aware of any other language where 10 lines of idiomatic
| code right in your codebase can add a new IDE warning.
| ravi-delia wrote:
| Honestly I just really like the ergonomics of CL. A lot of the
| features totally exist elsewhere, but weirdly you don't see
| things like implicit return or a total focus on expressions in
| dynamic languages too often. Also, I'm a weirdo that genuinely
| finds parentheses pretty. It's the language I use for all my
| personal projects because it's the language I enjoy using the
| most. I don't think I'd use it for work though- the benefits
| are pretty individual, and people in general seem to like C
| over CL.
| weaksauce wrote:
| > but weirdly you don't see things like implicit return
|
| that's been a thing in ruby since probably forever and it's
| one of the defining things about it
| tmtvl wrote:
| Ruby might have taken that from Perl, which also implicitly
| returns the last evaluated statement in a subroutine.
| weaksauce wrote:
| probably did... ruby took a lot from perl... also took a
| lot from many other languages but perl probably the most
| lilith_of_debts wrote:
| Fun fact: Matz was a lisper prior to creating ruby. He
| even wrote an email client entirely in Emacs lisp.
|
| Not wrong that ruby took a lot from perl, but it was
| heavily influenced by lisp and smalltalk and I'd
| personally argue those are the two largest influences.
|
| It does seem that ruby was specifically designed to grab
| Perl programmers though. Several features match exactly.
| EFreethought wrote:
| And maybe Perl got it from Lisp.
|
| It seems like the longer I am in software development, I
| find out that more and more things came from Lisp.
| mtlmtlmtlmtl wrote:
| Lisp is perfect for one man projects, personal tooling,
| templating for languages you prefer not to write, etc.
|
| To me it's more of a programmer's swiss army knife than a
| language I'd use in a big project that needs to be accessible
| to a larger team.
| [deleted]
| submeta wrote:
| Individuals who are particularly passionate about LISP may
| attempt to persuade others that it is superior to other
| languages, despite the fact that many have moved on to more
| practical programming languages.
|
| I can get it, Lisp has some value. Acquiring proficiency in it
| can be likened to studying Latin. Though it may be considered an
| obsolete language, it has a significant historical impact as it
| has served as a foundational influence for many modern languages.
| However, ultimately, it may not be considered as practical of a
| choice compared to more widely-used contemporary languages.
|
| Edit: I am tempted to compare Lispers to religious zealots.
| Especially Emacs lovers. I was in that camp as well. In the end I
| realized there was a tradeoff between tinkering and doing.
| Emacsers love to tinker.
| dang wrote:
| Please don't start programming language flamewars. We (and
| Lisp!) had enough of those a long time ago, and part of the
| idea of HN is to avoid this kind of thing.
|
| https://news.ycombinator.com/newsguidelines.html
| [deleted]
| stassats wrote:
| What drives people to attempt to persuade others that Lisp is
| not practical?
| kaveh808 wrote:
| Regarding the question of "Why [Common] Lisp?"...
|
| I did early Lisp development on Symbolics Lisp Machines back in
| the day. Wrote 3D graphics on them. I didn't realize how special
| the development environment was until I got my first job, writing
| 3D graphics in Fortran on VAX/VMS. Spent the rest of my career
| (Fortran, C, C++, IRIX, Linux) bemoaning all the stuff I missed
| from my Lisp days.
|
| I did venture back into Common Lisp development (MCL/CCL on
| MacOS) for my personal projects. Even did my masters thesis in CL
| by writing a socket connection to Maya and using it as a graphics
| engine from CCL.
|
| It took me a long time (decades) to get over the "everyone should
| be using CL" mentality.
|
| Thinking back on things, I have come to realize that Lisp is not
| a magic bullet: it won't necessarily make you a better
| programmer, and it won't necessarily make your project more
| successful.
|
| What Lisp will do is give your developers more power at their
| fingertips. For better or worse.
|
| The philosophy behind Lisp (and Smalltalk) back in the 70's and
| 80's was that programmers should be given as much expressive
| power as possible so they can develop better, faster, etc. The
| reason why CL allows you to define macros, redefine classes and
| methods on the fly, use generic functions and multiple
| inheritance, and recover from errors, is simply that the language
| designers considered these import enough to do the hard work to
| make them happen.
|
| I feel that philosophy, backed by the economics of software
| development, fell out of favor over time. Performance, safety
| (preventing developers from shooting themselves in the foot),
| code maintenance by large teams, cost, etc became more important.
|
| Today, the main factors in language choice are (1) the
| availability of developers, and (2) the availability of
| libraries/tooling. Going against these currents requires
| awareness and a strong commitment. To paraphrase an old computer
| industry saying: no one got fired for choosing Java.
|
| On a personal note, I continue to use CL for my own projects,
| where the pleasure of development is more important to me than
| commercial considerations. I have done so for kons-9, my 3D
| graphics system, and am happy that I did so. I simply would not
| have been interested in doing the project in C++. I find that CL
| is a language which supports me in my development, rather than
| fighting back.
|
| As an added bonus, the features of CL have encouraged me to think
| differently about the architecture and design of the system. A
| system built in C++ would simply have converged towards being
| another Maya/Houdini/Blender (at best, after many years of
| development). This way, I have a chance to do something
| different, which is a big part of the fun.
| robomartin wrote:
| I used LISP and APL professionally for, in the aggregate, over
| ten years. My current opinion on these languages is that software
| engineers would benefit greatly from learning and understanding
| them, yet it would be a mistake to use them for any modern work.
|
| When I say "learning" I mean in-depth application over, perhaps,
| a year, not something superficial. The question is how. I don't
| really have an answer for that. You have to find reasonably
| complex projects to be able to spend that much time with a
| language. That's the problem. I was getting paid to use these
| languages back then. Who wants to do non-trivial work in these
| languages today. Not many.
| mark_l_watson wrote:
| From just reading the TOC, and the first bit, this looks great.
| Like the author, I have been into Common Lisp "forever." I do
| sometimes feel conflicted when I can get something done in Python
| much faster because I can find a library that solves the problem
| I am working on. Probably my most honest advice to people is that
| Common Lisp is very good for research programming, but for many
| use cases other programming languages are better.
| yourapostasy wrote:
| _> ...because I can find a library that solves the problem I am
| working on._
|
| I couldn't find it, but is there a "Rosetta Stone" of language
| ecosystems, where in a "libraries" section it lists
| Python/Go/Rust/Ruby/Perl/Lisp/ _etc._ library near-equivalents?
| tmtvl wrote:
| I don't recall ever coming across one of those, it may be a
| neat idea to set that up.
| tombert wrote:
| This is why I've found myself doing Clojure for everything.
| Clojure has its own pretty-ok ecosystem, but also benefits from
| the Java ecosystem, while still giving me some lispey goodness.
|
| Granted, sometimes the mixing of paradigms can kind of clash,
| and that's its own can of worms, but at least I never get that
| "ugh I could have done this with a library in <language X>"
| mmcdermott wrote:
| When I reference Java from Clojure, I usually wind up with a
| thin layer of wrappers around the part of the library I need
| to make the main codebase feel more properly Lispy. It isn't
| perfect with the different mental models between the
| languages, but it helps.
| tombert wrote:
| Yeah, and I think wrapper functions are fine and normal.
|
| The part that I do find annoying is when I have to break
| out macros to make my wrapper usable. When I was using the
| Java bindings for Apache Spark a few years ago, I felt like
| I was constantly reaching for macros to do some clever
| stuff, which is no fun.
| martinflack wrote:
| > I can get something done in Python much faster
|
| Take a look at the CL libraries PY4CL, PY4CL2, and CL4PY. I use
| the first one for some things. It can be useful to bridge over
| to Python for something and come back with the answer.
| mark_l_watson wrote:
| Thanks, I have been using py4cl for a year or two. I have an
| example in my Common Lisp book that you can read online:
| https://markwatson-com-website.pages.dev/books/lovinglisp-
| si...
| seanw444 wrote:
| Yeah I haven't found any project I've wanted to implement in
| CL. I usually end up using Python or Go at that level of
| abstraction. If I want lower-level, C or Rust. However, I
| interact with Lisp almost daily through Emacs. And I enjoy it
| quite a bit. Configuring my editor through Lisp is unusually
| satisfying, and feels sleek.
| tromp wrote:
| > The biggest secret to Lisp is that it is actually the simplest
| programming language ever created---and that, coupled with its
| expressiveness and elegance, is why it is favored exclusively by
| the best programmers in the world.
|
| This is clearly a very opinionated book. Personally I find
| Haskell, while perhaps not as simple, both more expressive and
| more elegant. But I don't imagine it is favored by the worlds
| best programmers.
| [deleted]
| dang wrote:
| Related:
|
| _Learn Lisp the Hard Way_ -
| https://news.ycombinator.com/item?id=8573389 - Nov 2014 (32
| comments)
|
| _Learn Lisp the Hard Way_ -
| https://news.ycombinator.com/item?id=8016950 - July 2014 (141
| comments)
| revskill wrote:
| The problem with almost all LISP tutorials, books,... is there's
| no guide on how to install toolings at the beginning. Instead,
| there's just praise and praise.
|
| Such a missed opportunity.
| rjsw wrote:
| There is a section of the Preface on "Configuring Your
| Development Environment", seems pretty complete to me.
| revskill wrote:
| Preface section as i see is applied for whom who already get
| used to LISP.
|
| If audience is whom who doesn't know anything about LISP,
| you've lost time to go around to find things you want.
|
| Other languages have playground, or at least INSTALLING at
| the chapter 1. It should answer some IMPORTANT questions:
|
| - How to install the compiler
|
| - Which IDE best to use, or which extension.
|
| - How to install packages, how to build it.
| lilith_of_debts wrote:
| https://llthw.common-lisp.dev/configuration.html
|
| Literally everything you're asking for is in that link. The
| author has the opinion that you don't need fancy IDE
| features which is an arguable point but they do list what
| editors for each OS work in their experience.
| Mikeb85 wrote:
| Nowadays it's pretty much as simple as installing SBCL and then
| Emacs-Slime.
| nerdponx wrote:
| Unless you don't want to use Emacs, which is completely
| understandable. I know SLIME is great but we really shouldn't
| force Emacs on people.
| nequo wrote:
| Emacs is also great though. For all intents and purposes,
| with evil mode it can act as just another implementation of
| Vim.[1]
|
| But for those who like neither Emacs nor Vim ... I don't
| know.
|
| [1] https://github.com/emacs-evil/evil
| ratzkewatzke wrote:
| I'm an Emacs partisan, but the VSCode support for Common
| Lisp has come along way. Interested parties might look at h
| ttps://marketplace.visualstudio.com/items?itemName=rheller.
| ... .
| [deleted]
| beepbooptheory wrote:
| Curious to know how big the cross section of people is that
| are ready/eager for CL, but don't want to touch Emacs. I
| think its rather nice this might act as a screen, they are
| both tied together, even if mostly spiritually now.
|
| In general though, I'd say switch your focus to Scheme, and
| use Dr.Racket, if you really really don't want to use
| Emacs.
| tmtvl wrote:
| Or use SLIMA (https://github.com/neil-lindquist/SLIMA)
| with Atom... oh, right, moment of silence...
|
| ...SLIMA may work with Pulsar, or if you prefer Eclipse
| there's Dandelion
| (https://github.com/Ragnaroek/dandelion).
|
| VSCodium may be able to use Alive, but as it can't fully
| turn off MS's spyware I can't in good faith recommend it.
| nerdponx wrote:
| There's Slyblime for the Sublime Text users:
| https://github.com/s-clerc/slyblime. Worked pretty well
| when I tried it.
| franknstein wrote:
| "Clojure for brave and true" has in my opinion an excellent
| section on Clojure tooling in emacs (which I wish i read when I
| was starting out with emacs).
| WillPostForFood wrote:
| It is a strength (they do cover tooling), but also a
| weakness. Throwing beginners into learning emacs, as well as
| a new language, and likely a new programming paradigm, is a
| massive ask. I think it is mistake for Clojure that Brave and
| True is the most recommended book to start out.
| dockleaves wrote:
| That is interesting. I am wondering though, in what areas does
| Lisp get used these days?
|
| What would be a good project to showcase the strengths of Lisp,
| versus other well-known languages?
|
| How/why do people end up learning Lisp, what is the usual route
| to entry?
|
| Genuine questions, not trying to start a language battle here.
| I've never used Lisp before so am curious about all of this. To
| me it feels like one of those exotic old-school languages like
| Erlang or Perl.
| tmtvl wrote:
| So I've been using Scheme for a couple of years now and really
| enjoying proper interactive development (why would I recompile
| my entire program to run the tests when I can just run the
| tests whenever I feel like?) and I was fairly happy with it,
| though I'm always very aware that using less power/time
| efficient languages is harmful to the environment. So I decided
| to give Common Lisp a try after repeatedly hearing that it's
| faster than Scheme and I wound up falling in love with its
| support for type checking (well, with SBCL's support for type
| checking).
|
| Now I have my interactive programming with the nicety of having
| SBCL warn me when I'm passing an integer to a function that
| expects a string or something like that. Not only does it help
| me make fewer mistakes while programming, the type declarations
| also help SBCL generate more efficient code. It's a win-win all
| around.
| fm2606 wrote:
| >> How/why do people end up learning Lisp, what is the usual
| route to entry?
|
| I started learning CL starting around July/Aug 2022. How I got
| here is close to 2 years ago I read a blog post (I think) that
| said learning a niche language can help land a high paying
| part-time job, or, if applying to a position where said niche
| language is used you don't have to jump through all the Leet
| code, typical interview circus. Just knowing the language and
| having an interest was a huge factor in getting hired. It
| seemed fairly plausible to me.
|
| Initially I started learning Clojure but kept reading stuff
| about how awesome CL was/is. The JVM kind of turned me off and
| I like compiled, stand alone applications which can be had in
| CL.
|
| So here I am really enjoying learning CL. I am in a
| job/organization that does not use CL and probably never will.
| The benefits are awesome so I have no plans on leaving anytime
| soon. Maybe one day I may try to land a part time job using CL
| but I'm no where ready for that (both in my lack of CL
| knowledge and lack of time to commit to a part time job).
| gleenn wrote:
| We use Clojure for large data processing where it shines. It's
| also good at doing concurrency with it's solid concurrency
| tools and immutability by default. So a lot of people use it
| for financial data, fraud, and big data stuff. I think it's
| less common, but using Re-frame both in a front-end web app and
| also in a React Native mobile app was a charm. Some of the
| environments were a little hard to get going but were a dream
| to poke around and add lots of features quick. For example, the
| whole Urban Dictionary native app for iOS and Android are in
| Clojure as well as most of the site.
| wwfn wrote:
| I'm also very curious for hear from expert lispers. I've tried
| to find the sweat spot where lisp would fit better than what I
| already know: shell for glue and file ops, R for data munging
| and vis, python to not reinvent things, perl/core-utils for one
| liners. But before I can find the niche, I get turned off by
| the amount of ceremony -- or maybe just how different the state
| and edit/evaluate loop is.
|
| I'm holding onto some things that make common lisp look
| exciting and useful (static typing[0], APL DSL[1], speed
| [2,3,4]) and really want to get familiar with structural
| editing [5]
|
| [0] https://github.com/phantomics/april [1]
| https://github.com/coalton-lang/coalton/ [2]
| https://renato.athaydes.com/posts/revisiting-prechelt-paper-...
| [3] https://github.com/fukamachi/woo/blob/master/benchmark.md
| [4] https://tapoueh.org/blog/2014/05/why-is-pgloader-so-much-
| fas... [5] https://github.com/drym-org/symex.el
| TacticalCoder wrote:
| > I am wondering though, in what areas does Lisp get used these
| days?
|
| If you consider Clojure a Lisp then I think before the tech
| stocks crashed there were seven unicorns built with Clojure.
| Banking, healthcare, analytics, ...
|
| I'd say Clojure can be used anywhere Java can for sure. And
| Clojure runs on top of ClojureScript too.
|
| Then Clojure is only one of the Lisp dialects and there are
| "lispier lisps" out there which also their success stories.
| jimbokun wrote:
| Interesting 5 of those unicorns are listed here:
|
| https://clojure.org/news/2021/08/13/deref
| srejk wrote:
| I read the little LISPer (now the little SCHEMEr) years ago, I
| found that was a great way to teach recursion.
___________________________________________________________________
(page generated 2023-01-10 23:00 UTC)