Live data from Hacker News

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

news.ycombinator.com

31–40 of 211 posts

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

#31
post #8

Earlier quoted context omitted.

One argument I can think of is that if your problem is not shaped in a functional way, then a functional programming language might be a poor fit for the job. Common Lisp is multi-paradigm language that is pretty bendy with regard to absorbing new ways of doing programming. It gets actual work done as well.

How is it that you think Clojure has trouble doing things in a non-functional way? I'm just curious, as I work in Clojure primarily and may have a huge blind spot I'd love to clear out!

For starters you'd need to have imperative control structures like `while`, `continue`, `break` and a `return` that basically returns from anywhere. That can probably be built with macros.

Then you would need to have ways to mutate variables, so you'd need to stop using Clojure's persistent collections and instead use the ones provided by the JVM.

Overall, you can do it if you want to, it is just somewhat painful to do so and the language will fight you. This is like my who tried to write functional Python which is possible but then it is just a much worse Clojure.

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

#32
I’d start with Clojure if I were you. Then the leap to a more traditional lisp will be much easier.

That being said you might have no desire to leap at all - Clojure is a powerful language with a great ecosystem (especially if you rope in Java interop)

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

#33

Earlier quoted context omitted.

How is it that you think Clojure has trouble doing things in a non-functional way? I'm just curious, as I work in Clojure primarily and may have a huge blind spot I'd love to clear out!

I don't have much of experience with Clojure myself - the above might be my first impressions from the little bit where I've tried it. Well, let me try to fix them then, and ask some questions. In Clojure, how do you usually approach problems that are shaped in an object-oriented way? In object-oriented languages, this usually includes either some sort of method calls (and therefore mutable state) or message passing…

https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

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

#34
post #33

Earlier quoted context omitted.

I don't have much of experience with Clojure myself - the above might be my first impressions from the little bit where I've tried it. Well, let me try to fix them then, and ask some questions. In Clojure, how do you usually approach problems that are shaped in an object-oriented way? In object-oriented languages, this usually includes either some sort of method calls (and therefore mutable state) or message passing…

https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

I'm aware of this. How do you achieve setters if the state you close over is immutable? Isn't that the default in Clojure, since it seems to aim for immutability by default?

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

#36
The Lisp Tutor Jr was amazing. It gave you problems and "watched" as you type the solutions in Lisp. It seems to be down![0]

Does anyone know if there's a mirror somewhere? I'd gladly host this in a droplet and make it public if someone has the source.

[0]http://reed.cs.depaul.edu/peterh/Tools/lisptutor.html

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

#37
There are obviously many possible paths, so I can only really tell you what I've done. I can't say it's necessarily the best approach.

For me, I decided to start with Common Lisp. I installed SBCL, Slime for Emacs, and started working through the book Practical Common Lisp. By and large this seems to be a workable approach, but I will offer up this caveat. The PCL book is very much "project based" in that the author walks you through building a couple of actual applications. This is a Good Thing™ for the most part, but it does mean that you don't necessarily get things in the order you might expect.

There's a part of me that almost wishes I'd started with a book that takes more of an approach of "programming is ultimately sequence, selection and iteration. Here's how you do sequence in Lisp. Here's how you do selection. Here's how you do iteration. Now here's all the Fancy Lisp Stuff™".

The reason I say that, is because if you have at least the primitives for sequence, selection, and iteration (and maybe some I/O) in your mental toolbox, you can start building more or less arbitrary programs. With the PCL book structure you don't get to, for example, iteration, until moderately deep into the book. You do get there of course, but the early parts left me with an uneasy feeling like "geez, I don't even know how to write a loop in this language yet, when am I ever going to be able to just start coding in Lisp on my own?" if that makes sense.

Possibly one could complement PCL with another book, or online materials, but so far I've mostly just been grinding through PCL and haven't looked at any other Lisp books.

HTH.

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

#38
post #33

Earlier quoted context omitted.

https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

I'm aware of this. How do you achieve setters if the state you close over is immutable? Isn't that the default in Clojure, since it seems to aim for immutability by default?

Through an atom (https://clojuredocs.org/clojure.core/atom). The idea of accesing a closure that is mutable is as follows:

  (let [temp (atom 0)]
    (defn getter [] @temp)
    (defn setter [val] (reset! temp val)))
To implement an object, you would do something more like:

  (defn new-object [init-val]
    (let [temp (atom init-val)]
       {:getter (fn [] @temp)
        :setter (fn [val] (reset! temp val))}))

  (def obj (new-object 0))
  ((:setter obj) 12)
To define interfaces, you could check whether the map/object conforms to a spec, etc.

But obviously all this is not very idiomatic; in clojure you would keep those functions first-class through defn instead of tying them to the object / map, and would pass state as an argument. Something like:

  (defn getter [obj] @obj)
  (defn setter [obj val] (reset! obj val))

  (def obj (atom 0)) ; This gives you the ability (and need) 
                     ; to explicitly track the list of 
                     ; existing objects in use lest they are garbage collected.

  (setter obj 12)
If obj has structure (e.g. it is a map such as {:type :my.personal/type :val 12}) you can identify its type through the type keyval and can check conformance to a spec, etc.

As it was said in the previous post, it's equivalent. It's a matter of how to organize code.

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

#39

If you mean Common Lisp, I'd say install SBCL and start playing with with the repl. Choose the editor you know best; even notepad is useful to copy and paste expressions to/from the repl. Any editor that's suited for programming will have a way to send expressions to the repl with a keystroke, which is much more comfortable. So basically, just pick VSCode. With that, you're ready to go. Take just one book and work th…

I'm doing Clojure for the Brave and True right now and it has been an amazing resource. It even incentivized me to get into Emacs as well, which has been a blast. I'm not a fan of the humor, but it does not get in the way at all.

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

#40
post #33

Earlier quoted context omitted.

https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

I'm aware of this. How do you achieve setters if the state you close over is immutable? Isn't that the default in Clojure, since it seems to aim for immutability by default?

You could have an atom that holds the state and a function which can update that atom. You might do something like the elm architecture where you pass a message to a reducer which produces the new state that the atom is set to. All the logic is contained in the reducer and is pure and immutable and the state change happens at a single controlled point.
Post reply on HN