Re: Why don't people like lisp?

Liste des GroupesRevenir à lang 
Sujet : Re: Why don't people like lisp?
De : HenHanna (at) *nospam* devnull.tb (HenHanna)
Groupes : comp.lang.lisp sci.lang
Date : 30. Jun 2024, 09:31:44
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5r1l0$dpvt$2@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 6/28/2024 8:11 PM, Jeff Barnett wrote:
On 6/28/2024 8:48 PM, HenHanna wrote:
On 6/28/2024 2:54 PM, B. Pym wrote:
Pascal Costanza wrote:
>
Indentation in Lisp is not clear enough. Let's look at an example from
http://www-users.cs.umn.edu/~gini/aiprog/graham/onlisp.lisp:
>
(defun mostn (fn lst)
   (if (null lst)
       (values nil nil)
       (let ((result (list (car lst)))
             (max (funcall fn (car lst))))
         (dolist (obj (cdr lst))
           (let ((score (funcall fn obj)))
             (cond ((> score max)
                    (setq max    score
                          result (list obj)))
                   ((= score max)
                    (push obj result)))))
         (values (nreverse result) max))))
>
Note that only one pair of adjacent lines is indented by the same amount.
Other alignments are in the middle of lines.
>
Here is a straightforward translation into my dream language; note that
there aren't a lot of parens despite insignificant indentation and despite
using braces (like C) instead of bracketing keywords (like Pascal):
>
def mostn Fun [] = [], null;
def mostn Fun (First\List) {
    var Result = [First];
    var Max = Fun First;
    each List ?Obj {
       let Score = Fun Obj;
       if Score >  Max {Max = Score; Result = [Obj]}
       if Score == Max {Result = Obj\Result}
    };
    reversed Result, Max
};
>
Apparently, Paul Graham doesn't like CLOS nor the LOOP macro. Here is
another verson in Common Lisp (and this is not a dream language ;):
>
(defmethod mostn (fn (list (eql nil)))
    (declare (ignore fn list))
    (values nil nil))
>
(defmethod mostn (fn list)
    (loop with result = (list (car list))
          with max = (funcall fn (car list))
          for object in (cdr list)
          for score = (funcall fn object)
          when (> score max) do (setq max score
                                      result (list object))
          when (= score max) do (push object result)
          finally return (values (nreverse result) max)))
>
Gauche Scheme
>
(use gauche.collection) ;; fold2
>
(define (max-by fn lst)
   (if (null? lst)
     (values '() #f)
     (fold2
       (lambda (x best worth)
         (let ((score (fn x)))
           (cond ((> score worth) (values (list x) score))
                 ((= score worth) (values (cons x best) worth))
                 (#t (values best worth)))))
       (take lst 1) (fn (car lst))
       (cdr lst))))
>
(max-by (lambda(x) (modulo x 5)) '(22 23 24 25 26 27 28 29))
>
   ===>
(29 24)
4
>
>
>
How do i avoid using   -99999   ???
>
>
(define (print x) (newline) (write x) (newline))
>
(define (max-by fn Lis)    (maxBy fn Lis '() -99999))
>
(define (maxBy fn x cLis cMax)
  (cond
   ((null? x)             (cons (reverse x) cMax))
   ((= (fn (car x)) cMax) (maxBy fn (cdr x) (cons (car x) cLis) cMax))
   ((> (fn (car x)) cMax) (maxBy fn (cdr x) (list (car x)) (fn (car x))))
   (else                  (maxBy fn (cdr x) cLis cMax))))
>
(print (max-by (lambda(x) (modulo x 5)) '(4 5 6 7 8 9 3 44)))
(print (max-by (lambda(x) (modulo x 5)) '(24 25 26 27 28 29 33 44)))
 In Common Lisp, symbolic constants were defined for the IEEE plus and minus infinities. I don't recall the syntax at the moment but do remember they were quite useful in making certain codes easier to read and understand.
Thanks!!!
Yes, some Scheme implementations support negative infinity, often denoted as -inf.0.
Here's a breakdown:
Concept:     Negative infinity represents a value on the number line that is infinitely far in the negative direction.
Representation:      The specific notation for negative infinity can vary depending on the Scheme implementation. However, -inf.0 is a common representation, where:
-inf signifies negative infinity.
.0 indicates that it's an inexact number (as opposed to an exact mathematical concept of negative infinity).
Not all Scheme implementations  are guaranteed to support negative infinity.
The latest Scheme standard, R7RS-small, recommends the use of +inf.0, -inf.0, and +nan.0 for positive infinity, negative infinity, and Not-a-Number, respectively.

Date Sujet#  Auteur
30 Jun 24 o Re: Why don't people like lisp?1HenHanna

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal