Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

%DCL-MEM-BAD, bad memory VMS-F-PDGERS, pudding between the ears


devel / comp.lang.lisp / .Re: #'reduce

SubjectAuthor
o .Re: #'reduceRobert L.

1
.Re: #'reduce

<t1o2ur$6i0$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=17001&group=comp.lang.lisp#17001

  copy link   Newsgroups: comp.lang.lisp
Path: i2pn2.org!i2pn.org!aioe.org!OqeOGrcX7oT7c14m3RGjKw.user.46.165.242.75.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (Robert L.)
Newsgroups: comp.lang.lisp
Subject: .Re: #'reduce
Date: Sat, 26 Mar 2022 22:09:32 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <t1o2ur$6i0$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Info: gioia.aioe.org; logging-data="6720"; posting-host="OqeOGrcX7oT7c14m3RGjKw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: XanaNews/1.18.1.6
X-Notice: Filtered by postfilter v. 0.9.2
 by: Robert L. - Sat, 26 Mar 2022 22:09 UTC

> >> (reduce #'max '("This" "is" "a" "test" ".") :key #'length)
> >>
> >
> >Reduce doesn't accept :KEY according to CLtL2. In fact, if you
> >look at REDUCE more closely, you'll see that :KEY wouldn't make sense.
> >
> >Instead of REDUCE, try the following:
> >
> >(APPLY #'MAX (MAPCAR #'LENGTH '("This" "is" "a" "test" ".")))
> >
> >Even more efficient would be:
> >
> >(LET ((max 0))
> > (DOLIST (elt '("This" "is" "a" "test" "."))
> > (SETF max (MAX max (LENGTH elt))))
> > max)
> >
>
> Macintosh Common Lisp (MCL) accepts the :key keyword parameter:
> ? (reduce #'max '("This" "is" "a" "test" ".") :key #'length)
> 4
>
> You can also use loop to make it clearer:
> ? (loop for el in '("This" "is" "a" "test" ".")
> maximizing (length el))
> 4

Gauche Scheme:

(use gauche.lazy) ;; For lmap.

(fold max 0 (lmap string-length '("is" "a" "test")))

===>
4

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor