News for hackers. Stuff that matters.
Re:The Roots of Lisp (2001) by jecel on Thursday January 16, 2020 @08:57AM (#22064511)
One small detail - though COND and IF/ELSE are very closely related, they aren't quite the same thing. Early Smalltalk also started out with COND (a right arrow which made code look like modern switch/case) and later evolved to #ifTrue:ifFalse: which is still postfix, so feels backwards compared to other languages. Lisp and Scheme got more conventional if/else eventually.
Re:The Roots of Lisp (2001) by LandR on Thursday January 16, 2020 @09:53AM (#22065009)
Something I discovered about Clojure's cond recently.

It usually looks likethis:

    (cond (< a b) (println "a < b")
          (> a b) (println "a > b")
          :else   (println "a = b"))
I thought the :else had to be :else, but it only needs to be truthy, so it can be anything that isn't false or nil (which makes sense as you want it to always execute that form if no others match).

So this is just the same:

   (cond (< a b) (println "a < b")
         (> a b) (println "a > b")
         :hotdog (println "a = b"))
Probably obvious to everyone else but it was a bit of a "duh, of course!" moment for me.
Re:The Roots of Lisp (2001) by kazinator on Thursday January 16, 2020 @01:08PM (#22067160)
In traditional Lisp and common Lisp, and similar dialects, the symbol t is customarily used as the catch all last case.

There is an interesting situation is in the case family of constructs which match an input value against keys, in Common Lisp.

Inspired by cond, the t symbol also serves as the fallback in case when the key doesn't match the other cases. So that is to say:

   (case (expr)
     (a ...)
     (b ...)
     (42 ...)
     (t ...))  ;; <-- this isn't matching on the t symbol!
Common Lisp also supports the symbol otherwise in place of t.

But the programmer may also sometimes have the t symbol as a specific key value; or likewise the otherwise symbol. That requirement is handled by putting the key into a list:

   (case (expr)
     (a ...)
     ...
     ((t) ...))  ;; <- match on t
Re:The Roots of Lisp (2001) by wostusername on Thursday January 16, 2020 @06:01PM (#22070016)
In Haskell you usually use `otherwise` for the last guard clause, like so:

     f x | x < 0     = ...
         | otherwise = ...
It took me a while to realize that `otherwise` isn't a keyword or bit of syntax. It's just a variable bound to True: https://hackage.haskell.org/package/base-4.12.0.0/docs/src/G...
Re:The Roots of Lisp (2001) by lispm on Thursday January 16, 2020 @12:31PM (#22066739)
In Lisp usually all non-nil values mean true.

  CL-USER 13 > (let ((a 1) (b 2))
                 (cond ((> a b) 'foo)
                       (:hello :there)))
  :THERE
In some early Lisp dialects not all objects (other than lists and symbols) would be self-evaluating, so one would have to quote them.
Re:The Roots of Lisp (2001) by sparkie on Thursday January 16, 2020 @10:27AM (#22065360)
It's conventional in Scheme and Lisp to just use `#t` directly to match anything.
Re:The Roots of Lisp (2001) by lispm on Thursday January 16, 2020 @05:14PM (#22069594)
> COND and IF/ELSE are very closely related

In earlier Lisp COND was the primitive and IF was a macro expanding into COND. In newer Lisp it's IF which is the primitive and COND which is the macro.