In article <868z9c5y1m....@gondolin.local.net>, Alain Picard wrote: > Erik Naggum <e...@naggum.net> writes:
>> I think using #'(lambda ...) is a notational grossity.
> Why do you say that? Is that because you think (function (lambda ..)) > looks worse, or because that's what the (lambda ..) macro is there for?
> I'm curious, because I never thought of #'(lambda ..) as ugly. I just > get used to seeing that #' everywhere I expect a function argument.
I remember that I disliked #'(lambda ...) from the very first time I saw it. To me, (lambda ...) looks like something that evaluates to a /function/, not to a symbol whose value slot would be taken if I left out the #'. I took me a long time, too, to find out that it can actually be omitted (I think it was Erik who told me) because lambda is also a macro. I was very happy about that. I had written a curry macro, and didn't understand why #'(curry ...) wouldn't work but (curry ...) would :-)
Regards, -- Nils Goesche "Don't ask for whom the <CTRL-G> tolls."
> I think using #'(lambda ...) is a notational grossity.
* Alain Picard | Why do you say that? Is that because you think (function (lambda ..)) | looks worse, or because that's what the (lambda ..) macro is there for?
It is because I consider #' a notational grossity in general, but it is a _functional_ notational grossity. (Is "grossity" even a word? Hm, no, but it should have been, because of "curiosity".) (Also pardon the pun.)
I think (function car) is notationally better than #'car, but I think 'car is notationally better than (quote car). Why? I have no idea. Some twisted sense of aesthetics or something, I guess, or maybe I am just used to ', maybe it is so small it is innocuous, whereas #' looks like Laurel and Hardy or something. Therefore, (function (lambda ...)) is better than #'(lambda ...), but since that is such a redundancy, I much prefer (lambda ...) by itself.
| I'm curious, because I never thought of #'(lambda ..) as ugly. I just | get used to seeing that #' everywhere I expect a function argument.
But that would obviously make it problematic to use a function that returns a function. I think of lambda as a function-constructor, whereas function is a function-getter. (function (lambda ...)) would therefore get at the function that lambda constructs. (Yes, I do know that it is function that makes the lambda form into a function.) Another function or look-alike that returns a function would be similarly unquoted.
/// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.
Nils Goesche <car...@cartan.de> writes: > In article <868z9c5y1m....@gondolin.local.net>, Alain Picard wrote: > > Erik Naggum <e...@naggum.net> writes:
> >> I think using #'(lambda ...) is a notational grossity.
> > Why do you say that? Is that because you think (function (lambda ..)) > > looks worse, or because that's what the (lambda ..) macro is there for?
> > I'm curious, because I never thought of #'(lambda ..) as ugly. I just > > get used to seeing that #' everywhere I expect a function argument.
> I remember that I disliked #'(lambda ...) from the very first time I > saw it. To me, (lambda ...) looks like something that evaluates > to a /function/, not to a symbol whose value slot would be taken > if I left out the #'.
It's probably a matter of historical effect, but I find #'foo and #'(lambda ...) to be more aesthetic, not less.
First, it makes it easier to find the head of the function.
Second, it is more consistent to me because it means functions as data are all case-marked by #'. I was taught that #' was followed by a function name, and that (lambda ...) was the name of a function.
Third, I was raised to not think of LAMBDA as a primitive special form, so I look at LAMBDA as something that will not evaluate at all, and #' as something that rescues it. ;) It used to be that you could use either (quote (lambda ...)) or (function (lambda ...)), with the main difference being that the former didn't get the lexical environment (but then, mostly we had only specials back then, so that wasn't very different). #' was a modified form of quote in its early casting, and # was like a modifier on quote that said "functionally quote" rather than "evaluationally quote", if you like.
[Then again, when I first tried to standardize the term "special form" (I'm doubt I invented it, but I think I first published about it), it meant what we now mean by "special form or macro" (that is, anything that wasn't a normal functional form). Under that old terminology, you could say that LAMBDA now _is_ a special form; but under the modern terminology, not by my choice, there is no abstract term for that union set, and consequently you have to identify LAMBDA as a macro, not a special form, and thus still neither really "primitive" nor even ambiguously "maybe primitive maybe not". Pity. The community might wish to employ such ambiguity now in order to transition LAMBDA to a higher status, but there's really no good lingo for doing that. Maybe that's my fault for not adding yet another glossary word for people to cling to, though, while I had the chance.]
And, fourth, my preference for #' is partly due to the fact that while I do quite a lot of #'(lambda...), I still don't think of myself as doing functional programming. I consider the use of functions as data an unusual enough event that I don't mind case-marking it.
I don't really mind the modern day (LAMBDA...) and I understand why people want it, but I think it primarily a "comfort" matter for people who come from a different culture. I don't think it's a cut and dried matter for which a coherent objective case can be made, even though I often observe people trying.
What I find funny in all of this is that this is all about "highlighting" and one of the problems I have with highlighting is that it does not vary during the editing process. That is, one puts #'(lambda...) and it is highlit there WHETHER OR NOT the function it is highlighting is in my "activity focus". In a sense, it's always blinking in my peripheral vision. "Right!" I can hear you haters of "#'" saying, "that's why I don't like it." But those very same people will tell me they love syntax highlighting. I find it quite a lot more offensive to see every keyword in purple (or whatever) and every string in brown and so on just because I may not be caring about comments or keywords. I definitely am annoyed to see editors highlight the definition name in a function even when I'm not debugging anything that requires use of the name.
I don't know a good solution to this, and maybe I'm not explaining it well, but imagine an interface where both my eye and perhaps even my train of thought was tracked. So that when I was debugging args to OPEN, suddenly the keyword args to _that_ function (and only that function) would turn purple. In such a situation, then I wouldn't have peripheral vision effects, and I'd like coloring better.
I have grudgingly tried to train myself to live with colors because I think most people like them, and because there are occasionally times that the color tells me something important. But I almost wish I could have an editor that hid color and that had a command that would instantaneously enable color when I was searching for something in particular...
(I have similar problems with Unix ANSI-colored directory list, which is always highlighting too many things, making it hard to find the one kind of thing I want highlit.)
Anyway, the reason I mentioned all of this is that I find #'(lambda ...) to be about an order of magnitude, maybe two, less obtrusive than colorizing my entire screen, and yet people who are hugely offended by the "#'" notation (to call attention to the promotion of a "function name" from the function namespace to the variable namespace) are usually quite happy and unoffended at the use of color to simultaneously call attention to everything on the screen. And my real point is that I honestly believe this matter to be considerably more subjective than people are acknowledging.
Incidentally, I can't entirely clear my buffer on this topic without also mentioning the bug in Dylan that was replicated from Common Lisp design over my objections. (Pretty much none of my suggestions were taken in Dylan, so that's not big surprise.) In particular, Common Lisp should have used :optional, :rest, :key, etc. and _not_ &optional, &rest, &key, etc. The fact that & was chosen is unfortunate for a variety of reasons, not the least of which is that these symbols have to be individually exported, plus it makes the use of & in other contexts questionable. A number of times, good suggestions were made to extend Common Lisp that were rejected because of the need to add "yet another &xxx keyword" but that I'm confident would have been accepted trivially if it had been "adding yet another :xxx keyword" because we're already used to having myriad :keywords. Dylan made #keywords to mirror CL's :keywords, but there was really no syntactic need. The argument was that people need to have their eye drawn to these things. My argument, by contrast is, "they need to find it when they need to find it and not otherwise". The issue of drawing one's eye could have been handled in color if that really mattered, IMO, but I'd rather have seen (... foo :optional (x 4) (y 7) :key ((:ex x) 3) ...)in CL or ... foo opt: x=4, y=7, key: ex:x=3 ... in Dylan. We _did_ "fix" this in ISLISP, where either &optional (as a transitional/compatibility notation) or :optional can be used, etc.
Bottom line? Programming language notations are statically required all the time. Focus issues are dynamically needed or not needed, so are not always well addressed by static notation. It's often a judgment call what to emphasize and what not to in the static notation, and people often think they're being a lot more principled than they are. Mostly I don't see a lot of science applied here at all.
David Golden <qnivq.tby...@bprnaserr.arg> writes: > Could use unicode these days... which common lisp implementations > are unicode-capable ?
There is a page on CLiki based on a post here by Bruno Haible, which summarises Unicode support in clisp, eclipse, acl and lispworks. It's out of date (of course) but it might give you a place to start
* Christopher C. Stacy | People already complain about parenthesis because it makes things look | different from most programming languages. Now you're going to tell them | (or let them mistakenly assume) that they need special characters in | order to use Lisp?
Well, it might get their attention off the parentheses. :)
Besides, one of the perceived problems with the parentheses, is that they are basically the only syntax you have, and some people seem to get lost in the homogeneous syntax. So it _might_ actually help...
/// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.
In article <sfw3czkl9dt....@shell01.TheWorld.com>, Kent M Pitman wrote: > Nils Goesche <car...@cartan.de> writes:
>> I remember that I disliked #'(lambda ...) from the very first time I >> saw it. To me, (lambda ...) looks like something that evaluates >> to a /function/, not to a symbol whose value slot would be taken >> if I left out the #'.
> It's probably a matter of historical effect, but I find #'foo and > #'(lambda ...) to be more aesthetic, not less.
> First, it makes it easier to find the head of the function.
> Second, it is more consistent to me because it means functions as data > are all case-marked by #'. I was taught that #' was followed by a function > name, and that (lambda ...) was the name of a function.
I am not sure if that was clear: I have nothing against #'car, only against #'(lambda ...), because if #'blark is a function that returns another function I do (funcall (blark ...) ...); then, (funcall (lambda ...) ...) looks more visually consistent, doesn't it? It doesn't, of course, if you think of (lambda ...) as the ``name'' of a function, as you say, but that sounds really foreign to me :-) Indeed a cultural matter, it seems.
> I find it quite a lot more offensive to see every keyword in purple > (or whatever) and every string in brown and so on just because I may > not be caring about comments or keywords. I definitely am annoyed > to see editors highlight the definition name in a function even when > I'm not debugging anything that requires use of the name.
> I have grudgingly tried to train myself to live with colors because > I think most people like them, and because there are occasionally > times that the color tells me something important. But I almost > wish I could have an editor that hid color and that had a command > that would instantaneously enable color when I was searching for > something in particular...
> (I have similar problems with Unix ANSI-colored directory list, > which is always highlighting too many things, making it hard to find > the one kind of thing I want highlit.)
Interesting. I love syntax coloring just as much as I violently hate ``ls --color''...
How about ``ls -F''? Does that look fine to you?
> Bottom line? Programming language notations are statically required > all the time. Focus issues are dynamically needed or not needed, > so are not always well addressed by static notation. It's often > a judgment call what to emphasize and what not to in the static > notation, and people often think they're being a lot more principled > than they are. Mostly I don't see a lot of science applied here > at all.
Sure, it is pretty clear that this is all about aesthetics. Trying to have a rigorous discussion about this seems as futile to me as, say, wondering about what kind of being the ``it'' in ``it is rainy'' is :-)
Regards, -- Nils Goesche "Don't ask for whom the <CTRL-G> tolls."
Erik Naggum <e...@naggum.net> writes: > * Christopher C. Stacy > | People already complain about parenthesis because it makes things look > | different from most programming languages. Now you're going to tell them > | (or let them mistakenly assume) that they need special characters in > | order to use Lisp?
> Well, it might get their attention off the parentheses. :)
> Besides, one of the perceived problems with the parentheses, is that they > are basically the only syntax you have, and some people seem to get lost > in the homogeneous syntax. So it _might_ actually help...
Allowing people to use {}'s and []'s interchangeably with ()'s might help more.
Or allowing {...} to mean (PROGN ...) so that you had (if x { (print x) (print y) } { (print z) }) But then, people can already do this so trivially, and it's so controversial to do it globally (meaning, for all people), that it will never be adopted as a standard. But I don't know why people can't just insert the two lines of code it takes to reorganize the lisp reader this way.
With a couple more lines of work, the pretty printer can be made to display things back this way, too.
Would that other languages had such flexible syntax redefinition...
But then, the real problem with using notations like this is that they are opaque as to structure. It's not that you can't write a macro that destructures a PROGN, but if it looks like {...}, you might not realize it's a PROGN, and that becomes a barrier to your writing macros. Lisp, by constantly exposing you to the parsed notation, prepares you to write macros because the stuff of macro arguments is so easily predictable from having seen it everywhere right in front of you forever.
* Daniel Barlow wrote: > Ran out of single characters for variable names, did they?
That can't be it. The Perl Way would be to have only a small finite number of identifiers but to have an elaborate, ill-explained and buggy notion of `context' which causes them to mean subtly, or occasionally completely, different things. A large space of single-character identifiers would be seen as a positive disadvantage.
Now the MS C++ people are going to love unicode variable names, because they will be able to pack the whole naming convention (hungarian naming?) into *single characters*. Studies have shown[1] that there is no significant loss of readability with this technique.
I like (lambda...) more than #'(lambda...) because double-clicking the latter leaves the #' behind.
--
kenny tilton clinisys, inc --------------------------------------------------------------- "Be the ball...be the ball...you're not being the ball, Danny." - Ty, Caddy Shack
> I don't think it can be reasonably argued that either reader macro > version is so valuable as to outveigh their costs, which are firstly > to take up one macro character, and secondly to be non-standard.
Actually, I find that these two arguments apply so often, that I've never felt a shortage of available macro characters. About the only one I use regularly is, in code that does a lot of lexer like actions, a #L"string" that expands to (#\s #\t #\r #\i #\n #\g) for use in calls to member, as character-bag etc. But then to use it in case constructs, I need to write #.#L"foo" which I find is a bit too obscure.
So, what are people using reader macro's for?
-- Lieven Marchand <m...@wyrd.be> She says, "Honey, you're a Bastard of great proportion." He says, "Darling, I plead guilty to that sin." Cowboy Junkies -- A few simple words
For the immediate case at hand (lambda seems bulky), you're right - I am just looking for some sugar. But obviously a little sugar is good - else why '#... for function, or ' for list? Do you tink you could get by without that? I don't think the motivation here is to import syntax from another language, just to find some simpler ways of expressing things. If I wrote a lot of progn's, {} might be a nice, simple alternative for me. But I wouldn't want other people viewing my code to see that - I'd want them to see the progn. Likewise for my suggested lambda hack. This is going into stream of consciousness mode, so bear with me. What if you had a Lisp environment that let you elevate the read macro kind of thing into the editor - where the editor let you specify how you want to view and type certain things, but the source file stored the actual forms? Would that be worth anything?
GB
"Erik Winkels" <aeri...@xs4all.nl> wrote in message
> Kent M Pitman <pit...@world.std.com> wrote on Fri, 1 Mar 2002 14:17:54 GMT: > > But I don't know why people can't just insert the two lines of code > > it takes to reorganize the lisp reader this way.
> Isn't that mostly because they are newbies and are not aware of it > being possible? (For which I'm glad.)
> Most other people stop worrying about importing the syntactic sugar > from their previous, and more familiar, languages once they are used > to Lisp.
In article <sfw3czkl9dt....@shell01.TheWorld.com>, Kent M Pitman <pit...@world.std.com> wrote:
>What I find funny in all of this is that this is all about "highlighting" >and one of the problems I have with highlighting is that it does not vary >during the editing process. That is, one puts #'(lambda...) and it is >highlit there WHETHER OR NOT the function it is highlighting is in my >"activity focus". In a sense, it's always blinking in my peripheral >vision. "Right!" I can hear you haters of "#'" saying, "that's why I >don't like it." But those very same people will tell me they love >syntax highlighting. I find it quite a lot more offensive to see every >keyword in purple (or whatever) and every string in brown and so on just >because I may not be caring about comments or keywords. I definitely am >annoyed to see editors highlight the definition name in a function even >when I'm not debugging anything that requires use of the name.
Syntax-highlighting is always optional. #' is forever.
> For the immediate case at hand (lambda seems bulky), you're right - I am > just looking for some sugar. But obviously a little sugar is good - else > why '#... for function, or ' for list?
this may have just been a mental typo, but <'> is <QUOTE>, not <LIST> - very different.
"Glenn Burnside" <glenn.burns...@ni.com> writes: > What if you had a Lisp environment that let you elevate the read > macro kind of thing into the editor - where the editor let you > specify how you want to view and type certain things, but the source > file stored the actual forms? Would that be worth anything?
This is a long-term goal of my DefDoc (f.k.a. LambdaTeX) project. A structured source editor that would automagically reindent all code to your constraints about line-breaking, line-size, visual markup, etc. The reason I think it's a good sub-project of a document layout application is that the layout of the code is similar to layout of text on paper, just with different ideas of what can be changed to satisfy the layout constraints.
-- -> -/- - Rahul Jain - -\- <- -> -\- http://linux.rice.edu/~rahul -=- mailto:rj...@techie.com -/- <- -> -/- "I never could get the hang of Thursdays." - HHGTTG by DNA -\- <- |--|--------|--------------|----|-------------|------|---------|-----|-| Version 11.423.999.221020101.23.50110101.042 (c)1996-2002, All rights reserved. Disclaimer available upon request.
* "Glenn Burnside" <glenn.burns...@ni.com> | But obviously a little sugar is good - else why '#... for function, or ' | for list?
One of the things I hope you will appreciate here is that people take some pains to be as precise as they can when they post, and that means that '# instead of #' is an annoyance. ' does not mean list, it means quote. 'x does _not_ do the same as (list x), but (quote x).
| Do you think you could get by without that?
You mean would I abstain from defining them if I wanted them? No. :)
| What if you had a Lisp environment that let you elevate the read macro | kind of thing into the editor - where the editor let you specify how you | want to view and type certain things, but the source file stored the | actual forms? Would that be worth anything?
If you are not familiar with Emacs, yet, now is a good time to start.
/// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.
> I was reading recently about read macros - another extensibility feature > I've never seen anywhere else. And I noticed that the CL standard reserves > special delimiters like #n() for things like vectors, etc. But I didn't see > anything for defining a lambda expression. I realize I'm probably treading > on holy ground, but I can't help feeling that something like
> #[(x y z) (some-op-over x y z)] > or even > #l((x y z) (some-op-over x y z)) > would be easier to deal with than > #'(lambda (x y z) (some-op-over x-y-z))
> Is there already a read macro shortcut for lambda expressions that I'm not > aware of? Are there any common implementations that do that? Am I walking a > road that every CL newbie walks, only to get spanked by the gurus in the > end?
> Any comments are greatly appreciated.
Slightly OT, but I sometimes prefer to use FLET instead of LAMBDA, because it can help make the code self-documenting by giving the function a sensible name. -- Martin Simmons, Xanalys Software Tools zne...@xanalys.com rot13 to reply
> For the immediate case at hand (lambda seems bulky), you're right - I am > just looking for some sugar. But obviously a little sugar is good - else > why '#... for function, or ' for list? Do you tink you could get by without > that? I don't think the motivation here is to import syntax from another > language, just to find some simpler ways of expressing things. If I wrote a > lot of progn's, {} might be a nice, simple alternative for me. But I > wouldn't want other people viewing my code to see that - I'd want them to > see the progn. Likewise for my suggested lambda hack. This is going into > stream of consciousness mode, so bear with me. What if you had a Lisp > environment that let you elevate the read macro kind of thing into the > editor - where the editor let you specify how you want to view and type > certain things, but the source file stored the actual forms? Would that be > worth anything?
For some reason, this reminded me of the first Lisp I ever played with, where the editor was a function that required you to walk over the conses in your function definition using operations that were thin layers over CAR and RPLACA... -- Martin Simmons, Xanalys Software Tools zne...@xanalys.com rot13 to reply
>>>>>> On Thu, 28 Feb 2002 22:35:32 GMT, Espen Vestre ("Espen") writes:
> Espen> Erik Naggum <e...@naggum.net> writes: > >> The reason is that they are not sufficiently widely used. Even Scheme > >> has not done a lot of work to make writing lambda forms easier, even > >> though they are far more frequently used there.
> Espen> I think they are widely enough used - it *is* slightly irritating that > Espen> they use so much s-expression real estate. But every time I think about > Espen> it, I can't come up with an idea for a substitute that I really like > Espen> (the cutest thing would have been to use the lambda letter, of course, > Espen> where were all the lispers when 7-bit ascii was designed? ;-)).
> By the 1970s they had already moved on from ASCII to other extended > character sets. On PDP-10 timesharing (and later, Lisp Machines) at MIT, > the keyboards and operating systems supported character glyphs like Lambda. > The idea to support this in hardware and software was based on what > was available on Stanford's PDP-10 (eg. the "SAIL character set").
> Some people wrote their Lisp code using the Lambda glyph instead of > spelling out LAMBDA, but this was not widely accepted in the lab.
> I think the main reason most people like #'(LAMBDA..) is that it's an > obvious visual marker that takes about as much space as a DEFUN would. > That's why they don't want to make it smaller. (To the extent that > they think about it at all -- is this really a problem, anyway?!?)
> One reason for not defining a new syntax, such as "\\" for LAMBDA, > today, is that it would not be Common Lisp. Anytime you introduce > new reader macros or your own (arguably redundant) control constructs > into your code, you are making it harder for someone else to read. > This is so important that you should only do it iff after thorough > consideration it really is justified by necessity. Your personal > taste and idiosynchrocy are not good reasons to change around the > language, and most people who have been programming in Lisp for > decades choose to hardly ever do that.
> Macros, especially reader macros, are like when desktop publishing > with fonts was first invented. It was something new and powerful > and exciting and everyone wanted to _UsE THeM!!_. It takes a > fair amount of self-control and experience to use them reasonably.
> Nowadays, I suppose you could program EMACS to display the LAMBDA as a > special character. You're going to have to worry about how it looks > in all the different character sets that you might choose to display > your code in. Past that technical issue, what happens when you hand > the program to someone who does not have that display hack? Your code > might look awful on their screen. This is similar to the existing > formatting issue of how wide you should assume someone's screen is > when writing the code (without any display magic).
Heh. Someone just asked how to display LAMBDA as λ (the lambda character) on comp.emacs, and I posted a short hack to do this. It doesn't work particularly well, but it would be easy to extend to work normally.
> Before I learned Lisp, APL was my favorite language, so I'm not > personally adverse to using funny characters for programming. > But I can assure you that it is not a big selling point when trying > to get mainstream programmers to take a look at your language.
> People already complain about parenthesis because it makes things look > different from most programming languages. Now you're going to tell > them (or let them mistakenly assume) that they need special characters > in order to use Lisp?
Regards, -- BPT <b...@tunes.org> /"\ ASCII Ribbon Campaign backronym for Linux: \ / No HTML or RTF in mail Linux Is Not Unix X No MS-Word in mail Meme plague ;) ---------> / \ Respect Open Standards
David Golden <qnivq.tby...@bprnaserr.arg> writes: > Espen Vestre wrote:
>> (the cutest thing would have been to use the lambda letter, of course, >> where were all the lispers when 7-bit ascii was designed? ;-)).
> Could use unicode these days... which common lisp implementations > are unicode-capable ?
SBCL has Unicode support, I think, but not in the latest released version.
> Then you just need a few of those keyboards with little lcd screens > on every key so that you can find all the extra characters....
> I know Perl now supports unicode identifiers (in an effort to allow for > even more unreadable programs), and Java sorta does (AFAIK you can run > utf8 source thru native2ascii which changes all unicode chars to \uxxxx > sequences before passing it to javac...which noone ever does...)
> -- > Don't eat yellow snow.
-- BPT <b...@tunes.org> /"\ ASCII Ribbon Campaign backronym for Linux: \ / No HTML or RTF in mail Linux Is Not Unix X No MS-Word in mail Meme plague ;) ---------> / \ Respect Open Standards
> I think of lambda as a function-constructor, whereas > function is a function-getter.
I think that's probably the crux. One of the lisp books (Winston?) says lambda, in modern lisp, really should have been renamed to MAKE-FUNCTION (or some such).
Then your point would be well taken: renaming lambda to make-function, and the current function to function-slot, we'd get:
(defun make-adder (n) (make-function (x) (+ x n)))
Alain Picard <apic...@optushome.com.au> writes: > Erik Naggum <e...@naggum.net> writes:
> > I think of lambda as a function-constructor, whereas > > function is a function-getter.
> I think that's probably the crux. One of the lisp books (Winston?) > says lambda, in modern lisp, really should have been renamed > to MAKE-FUNCTION (or some such).
> Then your point would be well taken: > renaming lambda to make-function, and the current function > to function-slot, we'd get:
> all of which looks fairly clean and symmetric. Thanks.
One of the reasons it's not done this way is that often functions don't have to cons. In this sense, they are a little like symbols. You name them and you mean "map the function that adds 3 to its arg over my-list" not "make a function that adds 3 to its arg and then map it over my-list", just as when you do (list 'a 3) you do not mean "make a symbol A and then make a list containing that symbol and 3".
A very astute observation by Paul Robertson (who authored Robertson Common Lisp, a CLTL that Symbolics licensed and adapted to become the lesser-known Symbolics CLOE 386-based native Lisp product) made privately to me one day in the hall, but something I periodically repeat to this day because it struck me as so obvious and important that he should have written it down, was that it was a shame, probably in general but particularly for those with C mindset who obsess about consing, that LAMBDA blurred two very different operations:
(lambda (x) (+ x 3)) refers to a function that can be statically compiled and has no overhead to execute beyond that of a literal. That is, given (defun f () (lambda (x) (+ x 3))), you'll note that (f) is a non-consing function.
(lambda (x) (+ x y)) refers to a closure that has a more complex operation, more like LIST. When you do (defun f (y) (lambda (x) (+ x y))) you're doing something more like (defun f-helper (closure-storage x) (+ x (storage-ref closure-storage 0))) which can be statically compiled and then (defun f (y) (let ((storage (make-storage 1))) (setf (storage-ref storage 0) y) (make-closure #'f-helper storage)))
Paul suggested that if these two operations were different, such that [I don't remember the names he used, if any, so I'll make some up] (PROCEDURE (X) (+ X 3)) meant the first kind [non-consing] and (CLOSURE (X) (+ X 3)) meant hte second kind [closing/consing], then compilers could be an error rather than do unwanted capture; that is, it's easy to write (LAMBDA (X) (+ X Y)) not realizing you're doing capture, but if you did (PROCEDURE (X) (+ X Y)) the compiler could stop you dead in your tracks, while if you did (CLOSURE (X) (+ X Y)) the compiler would assume you knew what you were up to.
Note there's still some opportunity to lose a little in (CLOSURE (X) (+ X Y Z)) because in hairy code, you might have thought Z wasn't a capture even though you expected Y to be, and maybe (CLOSURE-OVER (Y) (X) (+ X Y Z)) would catch that. But that's a detail, by comparison.
It is an issue of the difference between Common Lisp and C that what we say is "this is what I want" not "this is how to implement what I want", but Paul's formulation was nice because one could just always use CLOSURE and sometimes be pleasantly surprised that it didn't cons. (Maybe one could make it "complain" if nothing got captured, but probably that would turn out to be annoying in the case of degenerate macros.) So there's some question as to whether it's dictating implementation or just saying "this establishes a conceptual space".
The functional programming community, in general, prefers to blur these two notations because both describe functions. But compiler writers are VERY familiar with the difference, and no one who becomes a writer of good code in CL fails to understand the distinction between these two things. So it's quite bizarre, in a way, that we map them to one function.
It reminds me a little of the absolute nightmare I had when translating Symbolics Macsyma from MACLISP to Common Lisp back in 1986 and trying to accomodate QUOTIENT. MACLISP's QUOTIENT had the awful property that if you gave it only integers, it did truncating divide. But if you gave it any arg that was a flonum (the MACLISP name for float), it did floating point division instead. So (QUOTIENT 3 2) => 1, but (QUOTIENT 3.0 2) => 1.5. Obviously, some of these had to be translated to / in CL and others to TRUNCATE. Figuring which was which, since they were all called QUOTIENT. If you step back from Lisp, and functional languages in general, you can see how LAMBDA would have this same kind of nightmarish ambiguity to some who really cared about what it was "doing" ...
> I was reading recently about read macros - another extensibility feature > I've never seen anywhere else. And I noticed that the CL standard reserves > special delimiters like #n() for things like vectors, etc. But I didn't see > anything for defining a lambda expression. I realize I'm probably treading > on holy ground, but I can't help feeling that something like
> #[(x y z) (some-op-over x y z)] > or even > #l((x y z) (some-op-over x y z)) > would be easier to deal with than > #'(lambda (x y z) (some-op-over x-y-z))
> Is there already a read macro shortcut for lambda expressions that I'm not > aware of? Are there any common implementations that do that? Am I walking a > road that every CL newbie walks, only to get spanked by the gurus in the > end?
The following is extracted from the iterate package. It creates a #L syntax for creating functions, and automatically creates variables !1 !2 by finding them in the definition and creating the lambda list automatically e.g.
The function created by #L automatically takes two arguments which replace !1 and !2. A numeric argument indicates exactly how many arguments there should be, in case it is different from that indicated by the 'bang' variables.
On 01 Mar 2002 14:09:40 +0000, Tim Bradshaw <t...@cley.com> wrote:
> (hungarian naming?) into *single characters*. Studies have shown[1] > that there is no significant loss of readability with this technique. [...] > [1] I asked my cat
That's unfair: cats see in the dark much better than humans.