• Re: Why don't people like lisp?

    From B. Pym@21:1/5 to Raffael Cavallaro on Fri Sep 13 01:34:06 2024
    Raffael Cavallaro wrote:

    How about loop for greater clarity than either do or Python?

    (loop
    for a = 1 then b
    and b = 1 then (+ a b)
    do (print a))

    Which neatly demonstrates the power of macros as well. If there's a

    In CL (COBOL-Like), in order to print an endless sequence of fibonacci
    numbers, one has to use a macro whose source code is over 60 kilobytes
    in size.

    In Scheme, he can simply use recursion.
    (This is actually shorter than the "loop" version.)

    (let fib ((a 1) (b 1))
    (print a)
    (fib b (+ a b)))

    Since CL (COBOL-Like) is not a Lispy language, it does not have
    much support for recursion.

    A "do" loop is shorter than the "loop" loop.

    (do ((a 1 b)
    (b 1 (+ a b)))
    (#f)
    (write (list a)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to All on Fri Sep 13 01:31:52 2024
    XPost: comp.lang.scheme

    Here's a more realistic example that illustrates exactly the
    opposite point. Take the task of finding the sum of the square of a
    bunch of numbers.
    Do people really think to themselves when they do this task:
    Umm first make a variable called sum
    then set that variable sum to zero.
    Then get the next number in the list,
    square it,
    add it to the old value of sum,
    store the resulting value into sum,
    then get the next variable,etc....

    No they they think: sum up the square of a bunch of numbers.
    This has an almost direct translation to the lisp style:
    (apply '+ (mapcar #'(lambda(x)(* x x)) numlist)).
    Well..
    sum (map (\x -> x ** 2) [1..10])
    in Haskell, or
    sum (map ((lambda x: x ** 2), range(1,11)))

    Too much line noise ;-)

    sum([x*x for x in range(1,11)])



    It's shorter in Gauche Scheme.

    (use srfi-42) ;; sum-ec

    (sum-ec (: n 11) (* n n))
    ===>
    385

    Less condensed:

    (sum-ec (:range n 1 11) (* n n))





    Then I would say that a clearer way to express what a person think is:
    (loop for number in numberlist sum (expt number power))


    Gauche Scheme

    (use srfi-42) ;; sum-ec

    (sum-ec (:list n '(3 4 5 6)) (* n n))
    ===>
    86

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)