* 2010-02-16 09:33 (+1100), Ben Schmidt wrote:

> Vim is essentially an imperative procedural language. 

Quite true.

> Lisp is essentially a functional language.

People keep saying that but Emacs Lisp and Common Lisp are really
multi-paradigm languages (Common Lisp more so). You can write these
languages just like you write procedural languages. I started writing
Lisp like I had written other languages - and often still do, whatever
feels natural. The FAQ for comp.lang.functional newsgroup does not even
mention Emacs Lisp and Common Lisp as an example of functional
languages. There is Scheme, though.

For example, you can write procedurally:

    (defun sum-items-loop (list)
      "Sum LIST's items using a loop and store the sum to variable SUM."
      (setq sum 0)
      (dolist (i list)
        (setq sum (+ sum i))))

    (sum-items-loop '(1 2 3 4))
    ;; sum=10

But you can also write:

    (setq sum (let ((sum 0))
                (dolist (i '(1 2 3 4))
                  (setq sum (+ sum i)))
                sum))
    ;; sum=10 (no other effects)

Or use recursion:

    (defun sum-items-recursive (list)
      "Sum LIST's items using recursion."
      (if (not list)
          0
        (let ((i (car list)))
          (+ i (sum-items-recursive (cdr list))))))

    (sum-items-recursive '(1 2 3 4))
    ;; The return value is 10 and there are no side effects.

> Most people find imperative languages easier to understand because
> they're a bit more like recipes and a bit less like Mathematics! Some
> people find the reverse, though.

And some people like both and use Lisp. :-)

-- 
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

Reply via email to