Live data from Hacker News

Try Clojure

tryclojure.org

41–50 of 404 posts

Re: Try Clojure

#42
I found the red over gray combination a bit hard to read, so I checked it with a color contrast calculator:

The contrast ratio here is 3.9:1 (text #DC2626, background #E5E7EB), and the minimum recommended for small text is 4.5:1.

Sorry to be that guy :) I am enjoying the tutorial.

Re: Try Clojure

#44
post #8

Cool site, I've never tried Clojure before. My first reaction though is that (+ 1 1) is a highly unconventional and possibly confusing way of writing 1+1, and I'm not sure why that design choice came about.

When McCarthy was first working on Lisp he intended to migrate to an infix syntax (called m-expressions), but abandoned the effort because everyone came to really like the current syntax (s-expressions) after they got used to it.

I know it's really hard to see how. (And honestly it's sometimes a little hard for me to see what the big deal is, but one of my first programming languages was a dialect of lisp so I can barely even remember not being comfortable with them.) But many people find that, once they get used to them, and especially if they learn to use an editor with a paredit mode, they can start to feel even easier to work with than infix syntax.

Re: Try Clojure

#45
post #8

Cool site, I've never tried Clojure before. My first reaction though is that (+ 1 1) is a highly unconventional and possibly confusing way of writing 1+1, and I'm not sure why that design choice came about.

Using the same notation for function calls and math operators has many benefits that may not be immediately obvious, and which may (depending on preference) outweigh the unfamiliarity. For example: No operator precedence rules to remember. Use math operators in higher order functions: (reduce [1 2 3] +) (compose + \*) Simpler parser in the language. Use kebab-case variable names. Use most symbols in variable names. T…

> Use math operators in higher order functions:

To be fair, there just needs to be syntax for passing infix functions as a "normal" function, like parens in Haskell

  (reduce [1 2 3] +)
  foldl' (+) 0 [1, 2, 3]

And to allow `?` in names, it "just" shall not be used elsewhere.

Re: Try Clojure

#47
post #8

Cool site, I've never tried Clojure before. My first reaction though is that (+ 1 1) is a highly unconventional and possibly confusing way of writing 1+1, and I'm not sure why that design choice came about.

It resembles command language: + is the command, and 1 and 1 are arguments.

  mv foo.txt bar.txt  # rename a file in the Unix shell
Except there are parentheses to delimit the command because commands can be nested in each other.

(Some Lisps have interactive modes where you can drop the outermost parentheses, allowing you to type like this:

  prompt> + 1 1
  2
but usually the parentheses are part of the formal syntax; where this is just a hack in the interactive listener.)

The design choice came about because the syntax started as an internal representation for a symbolic processing (formula manipulation) system that was being designed by John MacCarthy. The internal representation where the operator is first followed by its arguments was convenient because you don't have to parse around to identify them. You know immediately that by accessing the first position of the formula, there is going to be a symbol there which identifies its operator.

The internal form, and its written notation came to be used directly, while the symbol manipulation system came to be programmed in itself, so that its own "formulas" (source code) ended up in that form.

Re: Try Clojure

#49
post #8

Cool site, I've never tried Clojure before. My first reaction though is that (+ 1 1) is a highly unconventional and possibly confusing way of writing 1+1, and I'm not sure why that design choice came about.

On the contrary - I think it's much easier! The real advantage of this notation is that it's much, much easier to stack calculations. Example: (/ (+ 34 68 12 9 20) 140) You can imagine how the first part of that could come about: (+ 34 68 12 9 20) And then the second part (pseudocode): (/ sum 140) In Clojure it's easy to mash them together, or for example to paste the first calculation in the second. (/ (+ 34 68 12 9…

A programming language should be first and foremost precise and readable, not concise. I can barely understand the clojure version but when I read the "traditional" one I don't even need to think.

If you work with clojure a lot, does it become natural?

Re: Try Clojure

#50
I still remember Professor Brian Harvey rolling out his terminal on a cart in Berkeley's CS61A and typing out commands in a scheme repl. Learning what a y-combinator was with Structure and Interpretation of Computer Programs, and building my own scheme compiler with scheme.
Post reply on HN