| Deutsch English Français Italiano |
|
<1040tps$2tj5t$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: Why don't people like lisp?
Date: Tue, 1 Jul 2025 15:10:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <1040tps$2tj5t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Tue, 01 Jul 2025 17:10:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f0a476c038bf77ded6c9426ab8ea97af";
logging-data="3067069"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/q/aCqRAmgjvmfjwK0hAXG"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:Y93OzB7QKMcZHGQcX7ToTaVadyg=
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
(define (max-by func List)
(fold
(lambda (x best)
(let1 score (func x)
(cond ((or (not (car best)) (> score (car best)))
`(,score (,x)))
((= score (car best)) (push! (cadr best) x) best)
(#t best))))
'(#f ())
List))
(max-by (lambda(x) (modulo x 5)) '(22 23 24 25 26 27 28 29))
===>
(4 (29 24))