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

nothing about s-expressions is bad for using state and little nesting.

something about C/etc is bad for nesting heavily.

Edit: example. both lisp-style versions are nicer. if C has advantages, it isn't in making state work better.

  (def avg (numbers)
    (/ (sum numbers) (count numbers)))
  
  (def avg (numbers)
    (= total-number (sum numbers))
    (= total-count (count numbers))
    (= result (/ total-number total-count))
    result)
  
  function avg (numbers) {
    /(sum(numbers) count(numbers))
  }

  function avg(numbers) {
    =(total-number sum(numbers))
    =(total-count count(numbers))
    =(result /(total-number(total-count))
    result
  }


State in procedural languages has more to do with side effects than nice syntax for it. This article has a nice description of how why explicit state is good in procedural languages sometimes: http://prog21.dadgum.com/3.html


lisp can do side effects. as i demonstrated. what's the problem?


"... some people prefer not to commingle the functional, lambda-calculus part of a language with the parts that do side effects. It seems they believe in the separation of Church and state." --Guy Steele




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

Search: