Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's no tedium of writing everything out with parentheses, so you don't need to worry about that. You aren't writing everything "as a procedure call," or at least I wouldn't put it that way. For example, if you write babby's first recursive function in Scheme,

    (define (factorial n)
      (if (= n 0)
          1
          (* n (factorial (- n 1)))))
There, the procedure calls are (= n 0), (* n (factorial (- n 1))), (factorial (- n 1)), and (- n 1). You are not writing "(define ...)" as if it were a procedure call. You are writing it as if it were a special form (because it is one). That's a description of how it psychologically feels. Writing the (if ...) special form feels no different than writing if (...) { } else { } in Java.

Lisp and Scheme are not tedious at all. I'd say Common Lisp is one of the least tedious languages.



Thanks for the reply, Sam.

To provide some small examples, I often use Perl, and it gives me some syntax that saves me typing, such as:

* `my @other_list = @a_list[3, 1, 4]` to return just those items from a list (item 3, item 1, and item 4)

* `$str =~ s/$foo/BAR/g` to do string replacements (in string $str, replace all ocurrences of contents of variable $foo with "BAR")

* `my $thing = $colored_objects{red}->[2]` to get item 2 in the list of red-colored objects ($colored_objects is a mapping of color names to lists of items of that color)

* `my $error_msg = "Sorry, but $thing1 doesn't work with $thing2."` to interpolate the values of those 2 variables into the string

* `for (reverse(1 .. 10)) { say "Counting down: $_"; }` (counts down from 10 to 1)

I suppose I've always just guessed that operations like those in a Lisp language would require multiple lines and procedure calls, which would become tedious to write after a while. Is that the case?


Oh, Perl. In some cases, Lisp would certainly be more verbose. It's probably more tedious than Perl for some things. It also depends on which language you use. Scheme is more tedious than Common Lisp, which is sometimes more tedious than Clojure.

Here are the Clojure equivalents, omitting the act of assigning stuff to variables.

    (map #(a-list %) '(3 1 4))

    ; I'm not modifying x in-place because unfortunately Clojure
    ; doesn't like that.  Common Lisp is more imperative.
     (.replaceAll x foo "BAR")

    ((colored-objects :red) 2)

    (str "Sorry, but " thing1 " doesn't work with " thing2 ".")

    (doseq [i (reverse (range 1 11))]
      (println "Counting down: " i))
If you took the first example and assigned it to a variable other-list, it would typically be in a let expression, with a body.

    (let [other-list (map #(a-list %) '(3 1 4))]
      (subsequent statements that use other-list))


Thanks for those equivalents, Sam! Informative.

That first `(map #...)` is particularly interesting. Looks like you're applying the item lookup operation across the list of indices. Neat.


The first example could actually have been

    (map a-list [3 1 4])




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: