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

Not necessarily. Purely functional languages, like Lisp, do not have loops. Instead they have recursion. Any iterative algorithm (I.e. one with loops) can provably be converted to a recursive algorithm with out iteration.


Lisp has loops:

For instance, the do operator:

  (do ((i 0 (+ i 1))) ((> i 10)) (print i))
Or the loop macro:

  (loop for x below 5 and y in '(a b c d e)
        collecting (list x y))
The 1965 manual for Lisp 1.5 describes the prog construct, which persists into ANSI CL. Inside prog we can have labeled statements to which we can branch unconditionally with go in any direction. Lisp also has mutable variables. The following example from the Lisp 1.5 Programmer's Manual is still valid code today:

  (LAMBDA (A)
    (PROG (B)
  S   (SETQ B A)
      (COND ((NULL B) (RETURN C)))
      (SETQ C (CONS (CAR A) C))
      (GO S)))


While another commenter has mentioned that this is technically not correct with Lisp, it holds for the lambda calculus. You don't need loops to be TC if you have recursion. And for that you don't even need named functions-- note the URL of this site!


However, lambda calculus doesn't have code made of data, QUOTE or any of that. Lambda calculus isn't Lisp; it captures the gist of some of the evaluation semantics of Lisp only.


Lisp is more multi-paradigm than pure functional. And we like it that way. It can be functional, object oriented, aspect oriented, etc.




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

Search: