Hacker News new | ask | show | jobs
by AdieuToLogic 427 days ago
> Good article. Funnily enough the throw away line "I don't see parentheses anymore". Is my greatest deterrent with lisp. It's not the parens persay, it's the fact that I'm used to reading up to down and left to right.

  Language shapes the way we think, and determines what we can think about.
  - Benjamin Lee Whorf[0]
From the comments in the post:

  Ask a C programmer to write factorial and you will likely
  get something like this (excuse the underbars, they are
  there because blogger doesn't format code in comments):

  int factorial (int x) {
      if (x == 0)
          return 1;
      else
          return x * factorial (x - 1);
  }

  And the Lisp programmer will give you:

  (defun factorial (x)
    (if (zerop x)
        1
        (* x (factorial (- x 1)))))
Let's see how we can get from the LISP version to something akin to the C version.

First, let's "modernize" the LISP version by replacing parentheses with "curly braces" and add some commas and newlines just for fun:

  {
    defun factorial { x },
    {
    if { zerop x },
      1 {
        *,
        x {
          factorial {
            - { x, 1 }
          }
        }
      }
    }
  }
This kinda looks like a JSON object. Let's make it into one and add some assumed labels while we're at it.

  {
    "defun" : {
      "factorial" : { "argument" : "x" },
      "body" : {
        "if" : { "zerop" : "x" },
        "then" : "1",
        "else" : {
          "*" : {
            "lhs" : "x",
            "rhs" : {
              "factorial" : {
                "-" : {
                  "lhs" : "x",
                  "rhs" : "1"
                }
              }
            }
          }
        }
      }
    }
  }
Now, if we replace "defun" with the return type, replace some of the curlies with parentheses, get rid of the labels we added, use infix operator notation, and not worry about it being a valid JSON object, we get:

    int
      factorial ( x )
        {
          if ( zerop ( x )  )
            1
          else
            x * factorial ( x - 1 )
        }
Reformat this a bit, add some C keywords and statement delimiters, and Bob's your uncle.

0 - https://www.goodreads.com/quotes/573737-language-shapes-the-...

1 comments

Whorf was an idiot. It’s not worth quoting him.
> Whorf was an idiot. It’s not worth quoting him.

The citation is relevant to this topic, therefore use and attribution warranted.

It’s relevant, but it’s also wrong. It doesn’t help him make the case. But sure, make sure you attribute it to the correct idiot.