Subject: [clisp-list] does LOOP cons less than MAP? [was: VECTOR-PUSH-EXTEND]

From: "Hoehle, Joerg-Cyril" <[email-masked]>
Date: Mon Sep 9 12:04:27 2002

Sam Stingold wrote:
>replacing 
>	(map nil #'(lambda (x) (vector-push-extend (char-code 
>x) byte-vector)) (subseq input-string start-pos pos))
>with
>        (loop for i from start-pos to pos do 
>(vector-push-extend (char-code (aref input-string i)) byte-vector))
>will save you consing SUBSEQ and LAMBDA.

I agree for SUBSEQ, but I thought CLISP would open-code MAPCAR and its friends?

Some believe this is important so programmers remain free to use either
form of looping and programming style they like and are not biased
towards a specific one only for performance reasons.

There's been a long history now of fighting against:
 o use macros over functions, because they produce better code
 o use LOOP over MAPCAR etc., because it produces better code(! - because it lambdas (=> GC) less)

If we can't say "the code will be identical in both cases, so prefer
what's more legible" then [some] people *will* bias their style towards
what they percieve - and can verify - is faster.

A tiny test seems to support the view that MAPCAR is inlined,
while MAP is not?

BTW, that argument is not far away from Erik Naggum's old argument
about why CLISP doesn't favour abstraction, which generated quite some heat.

Regards,
	Jorg Hohle.

---

From: Sam Steingold <[email-masked]>
Date: Mon Sep 9 12:32:02 2002

> * In message <[email-masked]>
> * On the subject of "[clisp-list] does LOOP cons less than MAP? [was: VECTOR-PUSH-EXTEND]"
> * Sent on Mon, 9 Sep 2002 15:08:23 +0200
> * Honorable "Hoehle, Joerg-Cyril" <[email-masked]> writes:
>
> Sam Stingold wrote:
> >replacing 

MAPCAR yes, MAP no.
MAP works transparently on lists and vectors, which is hard to
open-code.

> about why CLISP doesn't favour abstraction, which generated quite some

Actually, CLISP favors abstraction much more than some other lisps.

E.g. in most lisps it is faster to open-code by hand, while in CLISP it
is not.

E.g., (list* 1 2 3 4 5) is (probably) faster in CLISP than the
equivalent (cons 1 (cons 2 (cons 3 (cons 4 5)))) (which is probably
faster, in, say, ACL).

A simple way to estimate the speed of a compiled function is to look at
it's disassembly.  The longer the slower.  So if you can use a single
built-in function instead of a bunch of simpler built-ins, you probably
win.

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.3 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Whom computers would destroy, they must first drive mad.

---

From: Kaz Kylheku <[email-masked]>
Date: Mon Sep 9 12:38:04 2002

On Mon, 9 Sep 2002, Hoehle, Joerg-Cyril wrote:

> Date: Mon, 9 Sep 2002 15:08:23 +0200
> From: "Hoehle, Joerg-Cyril" <[email-masked]>
> To: [email-masked]
> Subject: [clisp-list] does LOOP cons less than MAP? [was:
>     VECTOR-PUSH-EXTEND]
> 
> Sam Stingold wrote:
> >replacing 

Even if map's basic loop is open coded, what's going to happen with
your lambda expression? You are asking for a map compiler macro
which is  smart enough to rip apart lambda expressions and inline their
body, so that no closure is actually generated?

Is it ANSI conforming to write compiler macros for standard Lisp
functions? If so, can just use define-compiler-macro to produce
alternate code for MAP. Conforming or not, It works in CLISP anyway, so
you can do:

#+CLISP (define-compiler-macro map (...) ...)

> towards a specific one only for performance reasons.

You are free to keep the same syntax and semantics, yet exercise
basic self-determination by writing your own compiler macro to
translate the form however you want.

-- 
Meta-CVS: directory structure versioning; versioned symbolic links;
versioned execute permission; versioned property lists; easy branching
and merging and third party code tracking; all implemented over the
standard CVS command line client -- http://freshmeat.net/projects/mcvs

---

From: Kaz Kylheku <[email-masked]>
Date: Mon Sep 9 12:44:02 2002

> MAP works transparently on lists and vectors, which is hard to

Not, I think, if you sacrifice to the gods of bloat. :) Simply generate
the code variants for both sequence types, and wrap then in an
open-coded switch to dynamically select the appropriate one based on
the type of the argument sequence.

---

From: "mark" <[email-masked]>
Date: Mon Sep 9 14:07:03 2002

" but I thought CLISP would open-code MAPCAR and its friends?"

Ok - a bit a Lisp newbie question here (Ive been programming C++/C for
donkeys
years though so a complex answers ok :-)).

What does open-code mean?

cheers

mark

---

From: Sam Steingold <[email-masked]>
Date: Mon Sep 9 14:13:04 2002

> * In message <[email-masked]>
> * On the subject of "Re: "
> * Sent on Mon, 9 Sep 2002 12:43:30 -0700 (PDT)
> * Honorable Kaz Kylheku <[email-masked]> writes:
>
> Not, I think, if you sacrifice to the gods of bloat. :) Simply
> generate the code variants for both sequence types, and wrap then in
> an open-coded switch to dynamically select the appropriate one based
> on the type of the argument sequence.

what if MAP is given 5 arguments?
should we generate 32 versions of the code?

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.3 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
The world is coming to an end.  Please log off.

---

From: Sam Steingold <[email-masked]>
Date: Mon Sep 9 14:17:03 2002

> * In message <[email-masked]>
> * On the subject of "RE: [clisp-list] does LOOP cons less than MAP? [was: VECTOR-PUSH-EXTEND]"
> * Sent on Mon, 9 Sep 2002 22:05:09 +0100
> * Honorable "mark" <[email-masked]> writes:
>

replacing a funcall to MAPCAR with an explicit loop.
i.g.

(mapcar (lambda (x) BODY) foo)

==>

(dolist (x foo) BODY)

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat7.3 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Nostalgia isn't what it used to be.

---

From: Kaz Kylheku <[email-masked]>
Date: Mon Sep 9 14:19:03 2002

> What does open-code mean?

It means to put code in place, rather than to defer to a function call.

---

From: Randall R Schulz <[email-masked]>
Date: Mon Sep 9 15:34:02 2002

Mark,

A C++ programmer would call it "in-lining."

Specifically, it's expanding instructions from a called function at the 
point of call rather than emitting instructions to simply call that 
function. It's done for the usual reasons: to trade away the time cost of 
function invocation (subroutine call) for the space of placing equivalent 
instructions at the point of call. It also makes possible the compile-time 
resolution of certain alternatives (value-dependent if / then choices, type 
discrimination, iteration counts / loop termination conditions, etc.) that 
must appear in their most general form in the function.

Randall Schulz
Mountain View, CA USA

\At 14:05 2002-09-09, mark wrote:
>donkeys years though so a complex answers ok :-)).
>

---

From: Adam Warner <[email-masked]>
Date: Mon Sep 9 20:03:01 2002

> built-in function instead of a bunch of simpler built-ins, you probably

Absolutely. I learned this point quickly (and it's also founded on the
common sense that CLISP programs don't compile to native/machine code).
Moreover if what you are doing doesn't provide an opportunity to
precompile code CLISP appears to provide far better performance than
many other implementations (including those of other languages).

Until now I didn't realise Hell will freeze over before Erik will use
CLISP. It must pain Erik every time I mention CLISP in c.l.l ;-)

Thanks for the information about the extra Unicode support Bruno. It's
astonishing to see all the developments in just the short time I've been
using CLISP.

And thanks for the extra advice about optimising using LOOP Sam.

Regards,
Adam

---

From: Paolo Amoroso <[email-masked]>
Date: Wed Sep 11 02:09:03 2002

> CLISP. It must pain Erik every time I mention CLISP in c.l.l ;-)

Then Hell must be a pretty cold place. If you refer to Erik Naggum, some
time ago he mentioned using CLISP for a project. I seem to remember it was
Web-related.

Paolo
-- 
EncyCMUCLopedia * Extensive collection of CMU Common Lisp documentation
http://www.paoloamoroso.it/ency/README

---

From: Pascal Bourguignon <[email-masked]>
Date: Wed Sep 11 09:39:02 2002

> From: Paolo Amoroso <[email-masked]>
> Date: Wed, 11 Sep 2002 11:00:55 +0200
> 
> Then Hell must be a pretty cold place. 

Actually,  after the  Bible (and  current scientific  knowledge), it's
colder than Paradize. (Perhaps it would be better to say that Paradize
is hotter than Hell).  Whatever...

> If you refer to Erik Naggum, some

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
 The name is Baud,...... James Baud.