Live data from Hacker News

Ask HN: I want to start learning Lisp. Where do I begin?

news.ycombinator.com

141–150 of 211 posts

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#141
post #138

Is there a full featured editor that's hosted in the SBCL image itself? I vaguely recall CMUCL had something of the sort. It used to be you had to actually specify GNU Emacs, but nowadays it's pretty much the only Emacs anyone means.

Yes, there's the Lem editor (unrelated to CMUCL or the SBCL project itself): https://github.com/cxxxr/lem/ (also works for more programming languages) (and also, rather ipython-like, cl-repl: https://github.com/koji-kojiro/cl-repl/)

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#142
The very reason I find Lisps enjoyable is all the things an editor can do for you with a Lisp. Smartparens, rainbow parens, easy eval of forms (+ pprinting, macroexpand, inline replace etc), jump to definition, for Clojure - contextual awareness of the namespace and REPL session you're in. Probably forgetting a number of things. Without these there wouldn't be much for me left to like about programming in a Lisp. As far as I'm concerned, learning to use the editor well is as important as learning the language itself.

I only know Emacs well. Checked out VS code for Clojure a while ago and it wasn't even close. Clojure IDE "Cursive" is supposed to be good, but never tried and not sure if you want to invest time in an ad hoc IDE. It seems to me lispers don't want to discourage people by recommending Emacs, but at the end of the day, most people who stick with it tend to be Emacs users.

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#143

I remember wanting to learn lisp. I got stuck and reached out to the community for help. And found them to be very hostile. I decided I had better things to do with my time.

As a counter-anecdote (giving us anecdata), I did not have this issue when I got started. r/lisp and comp.lang.lisp were pretty welcoming. I don't do much on IRC, but my limited time there was productive and friendly. There were (probably still are) a few assholes and zealots on comp.lang.lisp, but they were easy enough to ignore (killfiles are your friends). I think some people also got a bit testy and short there b…

I’m glad you had a better experience than I.

I tried learning CL back in 2006 and read a quickstart guide from the #lisp IRC channel. It had sentences in it like:

“ Using a plain text editor without any runtime connection to your Lisp implementation just because you think you prefer its keybindings is stupid and self-defeating.”

And

“Follow these directions or risk our wrath, or at least unsympathetic attitudes!”

The document, mercifully, doesn’t appear to exist any more. Maybe when I called them on it at the time they realized that maybe there’s a better way and changed it. But it definitely made a poor first impression.

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#144

Earlier quoted context omitted.

I tried Clojure a bit and, compared to CL, I find it bloated :S Installing a library takes ages, a lot of memory, and I can't do it from the REPL (so I must quit my development environment, and start it again). CL feels very snappy. I can even install a new library to a running web app. I know it's dangerous, but it works and it helped me already :)

yes but clojure can get you a job

Probably more than CL yes, but thank you I create my own job.

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#145
If you're on Arch Linux, you can install the `lisp` package from AUR, then type `lispi` and then `(+ 1 2)` for adding 1 and 2. Don't type in the backtick quotes. Press `ctrl-c` to quit.

If you install `clojure` you can start the interpreter with `clj` and also type in similar expressions, like:

  (* 3 7)
There are a couple of differences to Common Lisp, though.

The fun thing about Lisp is that you can pass any number of parameters to functions, like "+", so that expressions like this also works fine:

  (* 1 2 3 4 5 6 7)
The next thing to know is that the first element within () is interpreted as the function, while the rest are interpreted as parameters. Then how do you represent a list like (1 2 3) without Lisp thinking that "1" is the function, you surely ask? You prefix it with ', like this: '(1 2 3). If you type '(1 2 3) into the `lispi` or `clj` prompt, they will print (1 2 3) right back at you.

A fundamental concept in Lisp is to get the first element of a list (the head) or the rest of the elements (the tail). For historical reasons the head is called CAR and the tail is called CDR in lisp. Everyone has just accepted that this is the way of Common Lisp by now. In Clojure, "first" and "rest" are used instead of CAR and CDR, as the heathens they are.

Since regular for loops are for wimps and snowflakes, iterating in traditional Lisp mainly centers around how to do the same thing using CAR, CDR and recursion.

Before we can do that, let's define a function that adds 2 to the given number:

  (defun addtwo (x) (+ x 2))
Note that "defun" is the function for creating functions that takes, roughly speaking, three parameters: the function name, the function parameters and the function expression.

If you type it into "lispi" you can use the function afterwards, and get the result 42:

  (addtwo 40)
Also, all lists in lisp are really just the head and the rest, so creating lists can be done by combining a head with the rest of a list, using cons, like this:

  (cons 1 ())
Which is equivalent to this (but signifies that quoting was intended):

  (cons 1 '())
And this:

  (cons 1 nil)
All three of the above expressions returns a list with one element (1), which means a head of 1 combined with an empty tail. Lists are constructed by appending heads to existing (or empty) tails.

Creating a function that takes apart a list into a head and a tail and then combines them again can be done like this:

  (defun combine (xs) (cons (car xs) (cdr xs)))
"xs" is the name of the function parameter, which is a list.

The combine function can be called like this:

  (combine '(1 2 3))
And will return:

  (1 2 3)
If you wish to edit code in a file instead of interactively, where the arrow keys may not always work, try putting this in a file named "main.lsp":

  (defun hello ()
    (write-line "Hello, World!"))
Then run the desired function with:

lisp main.lsp hello

Now to create a for-loop replacement in Common Lisp, for people with hair under their arms, using CAR and CDR and recursion. This program will print each number in the given list, with an axe emoji after each number (HN removed it, please insert an appropriate unicode emoji instead of the x):

  (defun lumberprint (n)
    (write n)
    (write-line "x"))
  
  (defun f (xs)
    (unless (null xs)
      (lumberprint (car xs))
      (f (cdr xs))))
  
  (defun main ()
    (f '(1 2 3)))
Save as "main.lsp" and run with "lisp main.lsp".

"unless" takes a condition and a list of statements. "null" checks if a list is empty. "write" outputs the given argument, but not a newline. "write-line" outputs the given argument and also a newline.

This should be enough to get you started. Then read SICP and draw the rest of the owl.

Best of luck!

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#147
post #73

This is a bit tangential but what helped me most in picking up Lisp was writing my own. Until I worked through Make A Lisp [0] I don't think I really "got" Lisp. You can work in whatever language you're familiar with. You build a Lisp similar to Clojure and learn a lot of important concepts by implementing them. [0] https://github.com/kanaka/mal

I'm doing the same thing right now. I have tried to get into lisp a couple of times, but this time it's the first time I "get it".

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#148

Earlier quoted context omitted.

As a counter-anecdote (giving us anecdata), I did not have this issue when I got started. r/lisp and comp.lang.lisp were pretty welcoming. I don't do much on IRC, but my limited time there was productive and friendly. There were (probably still are) a few assholes and zealots on comp.lang.lisp, but they were easy enough to ignore (killfiles are your friends). I think some people also got a bit testy and short there b…

I’m glad you had a better experience than I. I tried learning CL back in 2006 and read a quickstart guide from the #lisp IRC channel. It had sentences in it like: “ Using a plain text editor without any runtime connection to your Lisp implementation just because you think you prefer its keybindings is stupid and self-defeating.” And “Follow these directions or risk our wrath, or at least unsympathetic attitudes!” The…

Yeah. I think you were looking at it near the end of the "smug lisp weenie" era. Looking at some content from the early 00s does not give a favorable impression of the CL community or its attitudes. I came into it about the same time, but started paying attention to the community proper circa 2008. By then, I think the efforts to popularize the language and grow the community had tempered it quite a bit.

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#149

Racket Scheme & SICP is a fun way to start playing, especially if you are into theoretical concepts of CS and programming, like higher order programming and abstraction. The documentation for Racket is excellent, see e.g. https://docs.racket-lang.org/quick/index.html ... and many people have created online resources to adapt SICP to Racket, as well as other learning texts. I like Beautiful Racket, e.g. https://beauti…

ClojureScript which targets JavaScript as the host language (https://clojurescript.org/) is a good option on the Clojure side.

ClojureScript is great if you're drawn towards the "production use" side as pixelmonkey said and already have knowledge of the Javascript / Node ecosystem.

Re: Ask HN: I want to start learning Lisp. Where do I begin?

#150

Earlier quoted context omitted.

As a counter-anecdote (giving us anecdata), I did not have this issue when I got started. r/lisp and comp.lang.lisp were pretty welcoming. I don't do much on IRC, but my limited time there was productive and friendly. There were (probably still are) a few assholes and zealots on comp.lang.lisp, but they were easy enough to ignore (killfiles are your friends). I think some people also got a bit testy and short there b…

I’m glad you had a better experience than I. I tried learning CL back in 2006 and read a quickstart guide from the #lisp IRC channel. It had sentences in it like: “ Using a plain text editor without any runtime connection to your Lisp implementation just because you think you prefer its keybindings is stupid and self-defeating.” And “Follow these directions or risk our wrath, or at least unsympathetic attitudes!” The…

You could mention that it was almost 15 years ago in your previous post. That's more than enough time for the whole community attitudes to change, and they did.
Post reply on HN