Newsgroups: comp.lang.lisp,comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!ix.netcom.com!netcom.com!NewsWatcher!user
From: hbaker@netcom.com (Henry Baker)
Subject: Re: curried vs. tupled
Message-ID: <hbaker-1103950901230001@192.0.2.1>
Sender: hbaker@netcom19.netcom.com
Organization: nil
References: <3jplaj$61k@cantaloupe.srv.cs.cmu.edu>
Date: Sat, 11 Mar 1995 16:59:22 GMT
Lines: 40
Xref: glinda.oz.cs.cmu.edu comp.lang.lisp:17032 comp.lang.scheme:12287

I can't comment on ml, but there are times when I wish certain functions
in Lisp were curried rather than tupled.  The reason is that I would like
the functions to be partially applied, and that the compiler would take
advantage of constant propagation for the partially applied arguments.

Yes, this can all be done by a clever compiler, but if the _usual_ usage
of a function nearly always wants to be partially applied, then perhaps
the primitive functions are not properly organized.

For example, two functions that come to mind are 'sort' and 'search'.
Sorting usually involves passing a comparison function, but very often
the comparison function is constant and large efficiency gains can be
made by specializing the sort function.  Wouldn't it be much better to
write sort like this:

Scheme: ((sort <) list)
Common Lisp:  (funcall (sort #'<) list)

rather than having the compiler try to figure all of this out?

Ditto for search.  The pattern to be searched for is often constant,
and major gains in efficiency can be obtained by preprocessing (compiling)
the pattern.

Scheme:  ((search "abc") string)
Common Lisp: (funcall (search "abc") string)

Notice that by explicitly currying, the compiler no longer needs painful
analyses to figure out when preprocessing is ok -- it is now _always_ ok.
It also is much better for the programmer who can then rest easy knowing
that the correct optimization will be done, without his having to come
up with a myriad of specialized search functions on his own.

However, unless substantial gains of this sort are to be expected from
such partial evaluation, the more traditional tupling approach is to
be preferred for strict languages with side-effects.

-- 
www/ftp directory:
ftp://ftp.netcom.com/pub/hb/hbaker/home.html
