I am about to get my copy of Paul Graham's book (ANSI CommonLISP) and I am very anxious.
Still , I have some questions:
FIRST:
Here in Israel , we have thousands of C\C++ programmers and so the newspapers want ads are filled with requests for this kind of programmers , BUT never did I see a CLOS \ Lisp programmer want ad .!!!
If CLOS is so powerfull and (I read that) P Graham sold his software (in CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the programming community ?
SECOND:
I have Allegro CL 5.0 Lite and Lispworks Personal Edition.
None of the above can export to EXE in the Windows Environment, Is there a program to do this (even in its demo version), As I haven't even started programming in CLOS - I won't be going paying 600 U$ for a program that I still do not need. How do CLOS beginners usually start programming. CLISP is too primitively interfaced (still).
THIRD
I program AutoLISP in an IDE called VitalLISP and I came to like the way it works. (automatic completion of symbols names) - I once downloaded FreeLISP and then lost the copy. I can remeber that it reminded me of VitalLISP - Can anybody tell me where can I find the latest version that Harlquin released ?
"Nir Sullam" <nir...@actcom.co.il> writes: > Here in Israel , we have thousands of C\C++ programmers and so the > newspapers want ads are filled with requests for this kind of programmers , > BUT never did I see a CLOS \ Lisp programmer want ad .!!!
> If CLOS is so powerfull and (I read that) P Graham sold his software (in > CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the > programming community ?
For a whimsy way to see an approximate answer, try this:
In the above, substitute "uranium" for "CLOS", "atomic power" for "Lisp", "coal" for "C", "oil" for "C+", and "fuel sources" for "programmers" in the above and see if it helps you understand the answer.
Is atomic power for everyday use? In principle it probably could be. Look at atomic subs, for example. Pretty small-scale use of atomic power. But as a practical reality, atomic power just isn't used the same as fossil fuels. The market is not segmented that way. Does that mean that coal and oil is the future and uranium the past? Not nearly as clear. Observing usage stats is sometimes predictive, but not always. The quick and easy availability of coal and oil has turned an artificial distinction into a situation where two "would-be competitors" appear to be different markets.
Not by necessity but more by what is now custom, Lisp tends to get used in highly leveraged situations where other solutions don't work. Not so much because it has to work that way, but because people usually reach for something quick and easy and prevalant for ordinary problems. But C/C++ doesn't work for some sets of things because it doesn't scale well, and since Lisp is designed to scale, it works better in really big situations.
Also, Lisp where it is used often it allows fewer people to do what many would otherwise do. This means you often don't see large shops of Lisp programmers.
The analogy isn't perfect, though. Contrary to prevailing myth, you don't have to wear special clothing to handle Lisp. And it isn't unhealthy to other products living downstream.
* "Nir Sullam" <nir...@actcom.co.il> | Here in Israel, we have thousands of C/C++ programmers and so the | newspapers want ads are filled with requests for this kind of | programmers, BUT never did I see a CLOS / Lisp programmer want ad.
you're comparing a commodities market with a luxury market. why?
| If CLOS is so powerfull and (I read that) P Graham sold his software (in | CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the | programming community?
because it's a luxury.
essentially, any damn fool can pretend to be a C/C++ programmer, as you will very quickly find out if you _place_ one of those ads and try to sort one or two good guys out from of the liars and incompetent fucks who apply for the job. if you want to apply for jobs where the requirement is Common Lisp, you will equally quickly find out that you can't fool anyone. likewise, you can find a job at a hamburger joint without any skills whatsoever, but if you want to look at how you produce equipment used in hamburger joints that should be simple enough that any unskilled person can operate it without causing himself damage or produce bad food, you look at the end of the market that Common Lisp is good at helping -- you don't see many ads for hamburger joint equipment designers, either.
with all those ads for C/C++, it means companies are _desperate_ to hire people who seem to know C/C++. why do you think this is? it's because C/C++ are job-creating languages. let's take the development of the telephone as an example: initially, there were human operators, and all this worked great: but the more people wanted phones, the more people were required to be operators, and the companies were scrambling for operators, offering a lot of people work. then better technology came to the rescue and released the work force tied up in operators to do other necessary tasks. think of C/C++ programmers are human telephone operators -- the more successful they are, the more of them are needed (it is no accident the languages come from the biggest telephone company in the United States, either). in contrast, the Common Lisp programmers as designers of the automated telephone switching system, and the more successful they are, the less investment will be in human operators.
| None of the above can export to EXE in the Windows Environment,
you're assuming that this is what you will need to produce. why?
| How do CLOS beginners usually start programming?
they play with their Lisp environments, and use Emacs as their main interface to this environment unless they have a visual something that does the same. it seems that you simply use your tools inefficiently, but you should investigate how to interface several powerful tools with eachother to make them work as one. they don't have to come as one form the Single Vendor to work as one if they were designed well. (this may well be very foreign to a Microsoft victim. :)
all programming languages are not alike. that you have found interest in Common Lisp sets you out from the crowd. don't let the crowd run you down just because you have found something much better. however, it is essential to succeeding "on your own" that you can talk to people who know how to do it. the only upside of a commodities market is that lots of people use the commodity, and that they can talk a lot among themselves. so try to find people in your community that you can talk to about Lisp. posting here is a great start in this regard.
oh, by the way, C/C++ are quite interesting languages from a marxist point of view, too (it being May 1 and all): they are so bad that any professional who wants to do interesting work needs to learn new tools all the time and have the employer pay for it. the means of production are thus removed from the hands of the owners into the hands of the workers in a very new way. if the employers were any smart, they would not use languages that removed _all_ their investments in their people this way, because it is as unhealthy for a market with disproportionate power in the hands of employees as it is with disproportionate power in the hands of employers. shortly, therefore, smart employers will figure it all out and look for stable, solid languages where programmers don't need to be paid to acquire this week's skill set simply in order _not_ to quit for the job that requires it... C/C++ are very bad for business, which is another reason why you see so many companies hiring: it's such a terrible tool that managers who used to or taught how to manage industry will throw people are failing projects.
advertising is a symptom of insufficient demand or insufficient supply. in many ways, competition itself stems from insufficiency in solving a problem. also remember that quality can never compete with quantity. please remember this when you use the consequences of competition as a measure of success: it never is. success is when you have no competition and you ensure that you match the demand. then you can go and talk to people with a confidence that the desperately competing people can't. it is also sage advice to remain sufficiently above it all that you don't become a pawn in the games of the marketers. in other words: resist the temptations of the mass market in any area where it matters to you.
> Here in Israel , we have thousands of C\C++ programmers and so the > newspapers want ads are filled with requests for this kind of programmers , > BUT never did I see a CLOS \ Lisp programmer want ad .!!!
The same here in Taiwan, where you can add VB, assembly and hardware stuff as well. tw.bbs.comp.lang is full of BC++, VC++, etc. articles, one won't find Lisp stuff (haven't seen the word for ages). But, anyway, that's not going to stop me learning it because it's great and ...
> If CLOS is so powerfull and (I read that) P Graham sold his software (in > CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the > programming community ?
... even if you cannot use it as your primary language, as it really opens your mind to a different way of thinking and solving problems. Though I haven't used Common Lisp yet in any project (only SIOD and Emacs Lisp), I have make sure that people in my departement have heard about it, especially management. As I may do some kind of official presentation of it in the future, I think it would be a good idea to invite people from marketing, sales and field engineering to come.
jo...@removethisbeforesending.cetasoft.com (Joshua Scholar) writes: > I still don't see the difference between closures and objects. A > closure is just a function or set of functions with some trapped > variables, right?
The Devil is in the details... In Common Lisp you can easily define a closure that contains(?) two or more functions that access a set of values. To do the same in C++, you have to
1) define a struct/class to hold the closure data 2) define classes for each of the functions in the closure 3) instantiate an object for the closure data (from [1]) 4) instantiate objects for each of the classes from [2]. Each of these objects need a reference to the closure object, passed via the constructor.
Note that the classes defined in [1] and [2] are named classes; in Common Lisp, there is no need to introduce classes for the functions, and the closure itself is anonymous.
Compare the following: (defun f(a) (cons (lambda () (setq a (1+ a))) (lambda () (setq a (+ a a)))))
This sounds like prejudice and bigotry to me. Hmm, am I the first person to think this? I've dallied with functional languages before. I did LISP, and I did ML. LISP was interesting, but ultimately impractical. The left and right parenthesis keys wore out on my keyboard before I finished my second program. Give me C++ any day. This sensible language spreads the load out much more evenly across _all_ the number-keys in the top row of my keyboard.
-----Original Message----- From: Erik Naggum [mailto:e...@naggum.no]
Posted At: 01 May 1999 20:08 Posted To: lisp Conversation: Newbie questions Subject: Re: Newbie questions
* "Nir Sullam" <nir...@actcom.co.il> | Here in Israel, we have thousands of C/C++ programmers and so the | newspapers want ads are filled with requests for this kind of | programmers, BUT never did I see a CLOS / Lisp programmer want ad.
you're comparing a commodities market with a luxury market. why?
| If CLOS is so powerfull and (I read that) P Graham sold his software (in | CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the | programming community?
because it's a luxury.
essentially, any damn fool can pretend to be a C/C++ programmer, as you will very quickly find out if you _place_ one of those ads and try to sort one or two good guys out from of the liars and incompetent fucks who apply for the job. if you want to apply for jobs where the requirement is Common Lisp, you will equally quickly find out that you can't fool anyone. likewise, you can find a job at a hamburger joint without any skills whatsoever, but if you want to look at how you produce equipment used in hamburger joints that should be simple enough that any unskilled person can operate it without causing himself damage or produce bad food, you look at the end of the market that Common Lisp is good at helping -- you don't see many ads for hamburger joint equipment designers, either.
with all those ads for C/C++, it means companies are _desperate_ to hire people who seem to know C/C++. why do you think this is? it's because C/C++ are job-creating languages. let's take the development of the telephone as an example: initially, there were human operators, and all this worked great: but the more people wanted phones, the more people were required to be operators, and the companies were scrambling for operators, offering a lot of people work. then better technology came to the rescue and released the work force tied up in operators to do other necessary tasks. think of C/C++ programmers are human telephone operators -- the more successful they are, the more of them are needed (it is no accident the languages come from the biggest telephone company in the United States, either). in contrast, the Common Lisp programmers as designers of the automated telephone switching system, and the more successful they are, the less investment will be in human operators.
| None of the above can export to EXE in the Windows Environment,
you're assuming that this is what you will need to produce. why?
| How do CLOS beginners usually start programming?
they play with their Lisp environments, and use Emacs as their main interface to this environment unless they have a visual something that does the same. it seems that you simply use your tools inefficiently, but you should investigate how to interface several powerful tools with eachother to make them work as one. they don't have to come as one form the Single Vendor to work as one if they were designed well. (this may well be very foreign to a Microsoft victim. :)
all programming languages are not alike. that you have found interest in Common Lisp sets you out from the crowd. don't let the crowd run you down just because you have found something much better. however, it is essential to succeeding "on your own" that you can talk to people who know how to do it. the only upside of a commodities market is that lots of people use the commodity, and that they can talk a lot among themselves. so try to find people in your community that you can talk to about Lisp. posting here is a great start in this regard.
oh, by the way, C/C++ are quite interesting languages from a marxist point of view, too (it being May 1 and all): they are so bad that any professional who wants to do interesting work needs to learn new tools all the time and have the employer pay for it. the means of production are thus removed from the hands of the owners into the hands of the workers in a very new way. if the employers were any smart, they would not use languages that removed _all_ their investments in their people this way, because it is as unhealthy for a market with disproportionate power in the hands of employees as it is with disproportionate power in the hands of employers. shortly, therefore, smart employers will figure it all out and look for stable, solid languages where programmers don't need to be paid to acquire this week's skill set simply in order _not_ to quit for the job that requires it... C/C++ are very bad for business, which is another reason why you see so many companies hiring: it's such a terrible tool that managers who used to or taught how to manage industry will throw people are failing projects.
advertising is a symptom of insufficient demand or insufficient supply. in many ways, competition itself stems from insufficiency in solving a problem. also remember that quality can never compete with quantity. please remember this when you use the consequences of competition as a measure of success: it never is. success is when you have no competition and you ensure that you match the demand. then you can go and talk to people with a confidence that the desperately competing people can't. it is also sage advice to remain sufficiently above it all that you don't become a pawn in the games of the marketers. in other words: resist the temptations of the mass market in any area where it matters to you.
jo...@removethisbeforesending.cetasoft.com (Joshua Scholar) writes: > On Sat, 01 May 1999 06:14:09 GMT, cba...@2xtreme.net (Christopher R. > Barry) wrote:
> >>... But C/C++ > >> doesn't work for some sets of things because it doesn't scale well, and > >> since Lisp is designed to scale, it works better in really big situations.
> I REALLY should know better than to fall for the bait...
> C++ scales very well, thank you. C doesn't - that was the point of > adding object oriented extensions.
it may have been the point, but imho it hasn't succeeded.
just to take one point, compare lisp macros to C++ templates or preprocessor macros. lisp wins this contest handily.
in C++ templates are rock stupid and can only be used if you could have mechanically swapped out the types in your editor and stamped out multiple copies. the situatation for the different types must be *exactly* the same.
lisp macros let you inspect and digest the arguments and do different things depending on circumstances. if an algorithm shares 99% (or 1%) of the same stuff, you can make a macro to share what you can and special case what you cannot.
i think macros (amongst other things) are key to scaling.
* Philip Morant <p.mor...@edina.co.uk> | This sounds like prejudice and bigotry to me.
some people see something they can hate whenever they get the chance.
| LISP was interesting, but ultimately impractical. The left and right | parenthesis keys wore out on my keyboard before I finished my second | program. Give me C++ any day. This sensible language spreads the load | out much more evenly across _all_ the number-keys in the top row of my | keyboard.
I'm truly relieved. I actually appreciate it when the people who hate me are certified nut cases.
Johan Kullstam <kulls...@ne.mediaone.net> writes: > lisp macros let you inspect and digest the arguments and do different > things depending on circumstances. if an algorithm shares 99% (or 1%) > of the same stuff, you can make a macro to share what you can and > special case what you cannot.
> i think macros (amongst other things) are key to scaling.
Yes, and to connect to the other thread, parts of the MOP, Open Implementation and Aspect Oriented Programming seem indeed to be the extensions of that principle[1].
Regs, Pierre.
Footnotes: [1] Although I find the names a bit hypey, but I guess in these days you have to call Lisp macros "Dynamic Compilation Optimizers" or "Semantic Oriented Transformations" to get your point across, with all the mainstream hype around.
Philip Morant <p.mor...@edina.co.uk> writes: > I've dallied with functional languages before. I did LISP, and I did ML. > LISP was interesting, but ultimately impractical. The left and right > parenthesis keys wore out on my keyboard before I finished my second > program. Give me C++ any day. This sensible language spreads the load > out much more evenly across _all_ the number-keys in the top row of my > keyboard.
Hmm, I think you're a month and 2 days late, but just for the fun of it:
If the spread of wear on the keys of your keyboard is the sole concern in your programming, then either you are the sad victim of very shoddy keyboards, or you have not understood what programming[1] is all about ;)
Regs, Pierre.
(Hmm, maybe I should get that saying trademarked and put on some nice mugs. Anyone want to pre-order?)
Footnotes:
[1] That is in the sense of system and program construction, and not some of the other things people currently seem to think programming is, or might be...
> On 01 May 1999 16:59:58 +0200, Lieven Marchand <m...@bewoner.dma.be> > wrote:
> >* advanced object system with multiple dispatch. You can forget half > > of the Pattern book when you have these. > Then I'm going to have to figure out this multiple dispatch thing!
I think what he was trying to convey was not that you forget the "patterns part" of the pattern's book, but the OTHER half of the book. The periodic C++ kludges that you need to implement some of those patterns.
For example the Vistor pattern, to a certain extent, IS multiple dispatch. You don't have to hack up some explicit representation for it.
[ It is a matter open to debate as to how much CLOS and a dynamic language make those patterns "simplistic" to implement.
I also think the GoF (Gang of Four) probably picked a set of patterns that include a larger set of things that C++ doesn't do well. Since those folks are one of their primary audiences, you might as well pick patterns that have a high "wow, doing that was so much more painful before" effect. :-) ]
> >* closures in stead of function pointers or similar half baked measures.
> I still don't see the difference between closures and objects. A > closure is just a function or set of functions with some trapped > variables, right?
Closures are anonymous. You don't have to enlarge your global namespace to use them. I suppose you could use nested classes to aviod conflicts. However, that is using the outer class more as a "namespace" mechanism than as an "object" mechanism. Those aren't necessarily the same thing.
(defun add-n ( n ) #'(lambda (x) (+ n x)))
(mapcar (add-n 2) '( 1 2 3 4))
In C++, the mapcar equivalent could invoke a prespecified function on the "closure object" to each value of the num-list to the "computation". It would have to "know" what type of closure it is and what the "name" of that function is.
In Lisp, the environment takes care of creating these sorts of "objects" and of throwing them away when they aren't needed anymore. Therefore, there is less "overhead" the user needs to worry about. Also, the function being passed is any function, closure or otherwise. There is no carefully orchestrated mating dance you have to go through to use them.
It isn't that they aren't substitutable for each other... it is required drudgery involved. On the flip side, closures make for awkward classes, too.
Johan Kullstam <kulls...@ne.mediaone.net> writes: > in C++ templates are rock stupid and can only be used if you could > have mechanically swapped out the types in your editor and stamped out > multiple copies. the situatation for the different types must be > *exactly* the same.
Actually, C++ templates are Turing complete.
Yes, somebody actually implemented a Turing machine with them.
Then again, somebody did the same with vi macros.
-- Lieven Marchand <m...@bewoner.dma.be> If there are aliens, they play Go. -- Lasker
jo...@removethisbeforesending.cetasoft.com (Joshua Scholar) writes: > >* dynamic development environment that allows for incremental change
> I guess it saves a lot on building tools, testing programs and user > interfaces for them when you can just apply your functions manually, > I'm jealous.
Not only that. If you've made an error and try to do something that doesn't make sense like adding a number to a symbol or taking the car of an atom, your program doesn't happily do that to dump core some 5 functions deeper; no, you get put in a nice debugger where you can inspect the whole call stack, the arguments of your function etc. and after you've made the necessary adjustments you can even continue the computation or restart from higher up the call stack.
-- Lieven Marchand <m...@bewoner.dma.be> If there are aliens, they play Go. -- Lasker
Philip Morant <p.mor...@edina.co.uk> writes: > The left and right parenthesis keys wore out on my keyboard before I > finished my second program. Give me C++ any day. This sensible > language spreads the load out much more evenly across _all_ the > number-keys in the top row of my keyboard.
You should swap "( )" and "[ ]", even if you are not a Lisp programmer, since the parenthesis keys are used far more. Even in C and C++ with all the "[ ]" and "{ }", a quick hack to count the occurence of each character in a large source tree shows that the parenthesis beat out the others combined comfortably. I regret not having done this earlier.
If you are using X, add the following to your .Xmodmap (some unixes have a different file like .xmodmaprc, I think):
Then run "$ xmodmap .Xmodmap", or restart X. Manually running "$ xmodmap SOME_FILE" where SOME_FILE contains the above will always work if you can't figure out your system's xmodmap startup file.
"Nir Sullam" <nir...@actcom.co.il> writes: > Here in Israel , we have thousands of C\C++ programmers and so the > newspapers want ads are filled with requests for this kind of programmers , > BUT never did I see a CLOS \ Lisp programmer want ad .!!!
> If CLOS is so powerfull and (I read that) P Graham sold his software (in > CLOS) to Yahoo in 49 Million U$, How come CLOS is so obscure in the > programming community ?
I think you've answered your own question in a way. Newspaper advertising is a mass medium. It is appropriate to reach mass audiences. The Lisp programming community is not that large and so job announcements get distributed through other channels. I have personally had job announcements through email, by friends or people who get asked by their management to search for additional Lisp programmers.
I've never seen newspaper ads for brain surgeons but I'm fairly certain that a competent brain surgeon has no trouble finding a job.
-- Lieven Marchand <m...@bewoner.dma.be> If there are aliens, they play Go. -- Lasker
<kulls...@ne.mediaone.net> wrote: >lisp macros let you inspect and digest the arguments and do different >things depending on circumstances. if an algorithm shares 99% (or 1%) >of the same stuff, you can make a macro to share what you can and >special case what you cannot.
I'm new to Lisp but am interested in macros. I'm wondering if Lisp macros can be invoked by code that is in a non-standard syntax, such that the macro processes the syntax to make it work. For example, can a macro be called by its name followed by a sequence of whitespace delimited arguments with some defined pattern to end the list of arguments, and the number of arguments found would determine the macro processing? Or can a macro be invoked by an arbitrary expression in an arbitrary syntax, such that the parts of the expression would be the macro arguments? The macro definition would have to define the syntax, and there would have to be some way for the compiler to recognize that syntax from knowledge of that macro.
And can you do things like rename the parenthesis characters so some other character or symbol would represent them in ordinary Lisp syntax?
Or if not that kind of stuff, what kind of stuff can you do with Lisp macros?
Lieven Marchand <m...@bewoner.dma.be> writes: > Actually, C++ templates are Turing complete.
> Yes, somebody actually implemented a Turing machine with them.
> Then again, somebody did the same with vi macros.
Yes, they are Turing complete (and have a syntax, if used to that effect, that makes Turing machines look appealing in comparison), but you'll still have huge problems using them to do more than simple renaming operations on the C++ template itself. That IMHO is the most hillarious thing about templates: In the effort to create a very restricted kind of "macro system", C++ ended up with a Turing complete macro language that still isn't overly useful for usage in C++.
If they had written some sophisticated m4 macrology[1], it might have been more useful, and less work... IMHO templates are just bondage & discipline all over again.
Regs, Pierre.
Footnotes: [1] Not that I condone use of m4 for this purpose ;) Today I'm more convinced than ever, that "Thou shalt not have a macro language other than thine language itself", or words to this effect...
In article <372df5e2.793333...@news.earthlink.net>,
<please-reply-in-the-fo...@thank.you> wrote: >I'm new to Lisp but am interested in macros. I'm wondering >if Lisp macros can be invoked by code that is in a >non-standard syntax, such that the macro processes the >syntax to make it work. For example, can a macro be called >by its name followed by a sequence of whitespace delimited >arguments with some defined pattern to end the list of >arguments, and the number of arguments found would >determine the macro processing? Or can a macro be >invoked by an arbitrary expression in an arbitrary syntax, >such that the parts of the expression would be the macro >arguments? The macro definition would have to define the >syntax, and there would have to be some way for the compiler >to recognize that syntax from knowledge of that macro.
A macro's parameters are the subexpressions of the expression of which it's the head. For instance, in the expression (push <expression> <place>), the PUSH macro will be given the unevaluated expressions <expression> and <place> as its parameter. Since the function definition containing the macro invocation will already have been processed lexically by the reader, all the objects will have been read into internal data types.
This means that a macro can define arbitrary semantics to its syntax, but it can't change the lexical nature of the language. For an example of a macro that defines a pretty complex syntax of its own, see LOOP.
>And can you do things like rename the parenthesis characters >so some other character or symbol would represent them in >ordinary Lisp syntax?
These things can be done using reader macros. These are functions that are invoked by the reader when it encounters a specific character during lexical analysis. See the I/O chapter of CltL or the CLHS for details.
-- Barry Margolin, bar...@bbnplanet.com GTE Internetworking, Powered by BBN, Burlington, MA *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups. Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
: | LISP was interesting, but ultimately impractical. The left and right : | parenthesis keys wore out on my keyboard before I finished my second : | program. Give me C++ any day. This sensible language spreads the load : | out much more evenly across _all_ the number-keys in the top row of my : | keyboard.
: I'm truly relieved. I actually appreciate it when the people who hate me : are certified nut cases.
It is actually important to me that I believe Philip was joking when he wrote this. Despite all the evidence to the contrary, I've managed to convince myself that no-one in the world is that clueless. It will destroy my world construct if people I respect take the above comments by Philip seriously.
Erik, please don't take him seriously.
-- Brent Ellingson (belli...@badlands.NoDak.edu) "It is amazing how complete is the delusion that beauty is goodness." -- Leo Tolstoy
>> I still don't see the difference between closures and objects. A >> closure is just a function or set of functions with some trapped >> variables, right?
> The Devil is in the details... In Common Lisp you can easily >define a closure that contains(?) two or more functions that access >a set of values. To do the same in C++, you have to
> 1) define a struct/class to hold the closure data > 2) define classes for each of the functions in the closure > 3) instantiate an object for the closure data (from [1]) > 4) instantiate objects for each of the classes from [2]. Each > of these objects need a reference to the closure object, > passed via the constructor.
> Note that the classes defined in [1] and [2] are named >classes; in Common Lisp, there is no need to introduce classes for the >functions, and the closure itself is anonymous.
> Compare the following: > (defun f(a) > (cons > (lambda () (setq a (1+ a))) > (lambda () (setq a (+ a a)))))
There are lots of ways of doing this stuff in C++, none of which take the 30 line to define that you took. When we really want all the generality of a closure (which we rarely do) we use a template class that will combine any function pointer with an object pointer to make a closure that contains both and, (since all such templates are derived from a single root), they can be passed around like anonymous functions.
In any case, no matter what you do, the simple mapping from a closure is one object = one activation record.
class f { int a; public: f(int _a):a(_a){} int operator++() { return ++a; } int Times2() { return a*=2; }
};
void main() { f g(2);
//when you really want all the generality of a closure
Off the top of my head, the template for closures of this type signature would look like this:
class IntClosureBase { public: virtual int operator() = 0;
};
template <class T> IntClosure : public IntClosureBase { T *object; int (T::*function)(); public: IntClosure(T* _o,(T::*_f)()):object(_o),function(_f){}
virtual int operator() { return (object->*function)(); }
};
We don't really call our template "Closures" but I'm being LISP friendly.
please-reply-in-the-fo...@thank.you writes: > I'm new to Lisp but am interested in macros. I'm wondering if Lisp > macros can be invoked by code that is in a non-standard syntax, such > that the macro processes the syntax to make it work.
[My answer is about Common Lisp, not Lisp in general]
A macro cannot change the basic syntax of parentesis, whitespace etc. It is still damn powerful and very, very useful.
A macro _character_ on the other hand, can change anything.
So you cannot say (with-angle-brackets <+ 2 <* 3 4>>)
But you _can_ say ?<+ 2 <* 3 4>> by properly defining the meaning of "?"
For example, I have defined ?(func-name arg1 arg2) to mean (my-funcall #'func-name arg1 arg2)
* belli...@badlands.NoDak.edu (Brent A Ellingson) | It is actually important to me that I believe Philip was joking when he | wrote this. Despite all the evidence to the contrary, I've managed to | convince myself that no-one in the world is that clueless.
the evidence to the contrary is overwhelming: there is no limit to cluelessness, and no reason to presume cluelessness is a joke: failing to realize that the clueless aren't joking is how most politicians manage to pull their tricks on all of us.
| It will destroy my world construct if people I respect take the above | comments by Philip seriously.
that's harsh, but I think you should just convince yourself otherwise.
jo...@removethisbeforesending.cetasoft.com (Joshua Scholar) writes: > There are lots of ways of doing this stuff in C++, none of which take > the 30 line to define that you took.
> [... example snipped... ]
One problem with your approach is returning the closure objects you created:
This would result in a dangling reference to the destructed 'g' object - as 'g' would have gone out of scope.
I miss closures and lambda functions the most when using some of the stl algorithms. For example:
class Person { string getName();
};
vector<Person*> people = ...;
// Find a person with the name 'John': vector<Person*>::iterator it = find_if( people.begin(), people.end(), compose( bind2nd(equal_to<string>(), string("John")). mem_fun(&Person::getName)));
I would much prefer writing an anonymous function inline:
The main problem with closure simulators in C++ is the memory management and providing access to the local variables without having to create a class which copies and stores them.
> You should swap "( )" and "[ ]", even if you are not a Lisp > programmer, since the parenthesis keys are used far more.
My norwegian keyboard favours lisp over the C-syntax family of languages, since {[]} are almost ultimately unaccessible ;-)
Having to type shift-8 and shift-9 isn't a big deal though, I think my stiff left arm is caused by EscapeMetaAltControlShifts - ingenious ideas for remapping emacs control combinations are very welcome (is it possible, on a sun keyboard, to use the caps lock as an ordinary modifier?).