[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: functional purity

William James

8/8/2015 8:35:00 AM

Tim Bradshaw wrote:

> It's not easy to do. Consider something like this:
>
> (defun grovel-list (fun l &optional (comparator nil comparatorp))
> (loop for e in l
> when (funcall fun e) collect e into results
> finally (return (if comparatorp
> (sort results comparator)
> results))))
>
> This is a side-effect-free function, but its implementation has one
> explicit call to a non-side-effect-free function (SORT) and the
> expansion of LOOP is probably a mass of side-effects.

Gauche Scheme:

(define (grovel-list fun l :optional comparator)
(let1 result (filter fun l)
(if (undefined? comparator)
result
(sort result comparator))))

--
They agitate for "equality" to facilitate the imposition of their own
immeasurable superiority, and for "economic justice" to mask their conviction
that all the property in the world justly belongs to them.... They denounce
"racism" and agitate for "human rights," with the secret reservation that they
are the only race that is human. --- R. P. Oliver