Erik Naggum <e...@naggum.net> writes: > * Jacek Generowicz <jacek.generow...@cern.ch> > | I guess I can't claim that this is going to become too tedious or > | error-prone to write for, err, much longer alphabets :-)
> I "wrote" it using Emacs Lisp. For each line I evaluated
> (loop for i from ?V to ?Z do (insert (format "#\\%c " i)))
My approach was to type in a grid of pure letters, and then insert a few text rectangles.
> Unfortunately, I typed in lower-case letters in one of the lines.
> | Having said that, the fact that the approach _is_ error-prone is > | demonstrated by the line of lowercase chars in your code.
> I have added you to my do-not-help list.
I am sorry to hear that.
I doubt that adding yet-another-wretched-smiley[1], as I had been tempted to do, would have avoided this.
[1] I hate the things. I don't, in normal conversation, interject continuously with "you shouldn't take what I just said entirely seriously", or "nudge, nudge, wink, wink" . . . but time and again I find that in NGs one just cannot be cautious enought. Your sensitivities, in particular, I find extremely difficult to gauge.
> There is nothing error-prone about this. He just made a typo;
I find this a strange statement to make. It's almost self contradictory. When typing in lots of (pseudo-)repetitive data, a typo is exactly the sort of mistake that is very likely to be made, and is exactly the reason why I naturally look to a more algorithmic solution in such cases.
> Alas, like any source code, it is subject to the failings of our > fingers. Then again, he might have done this on purpose for educational > purposes, to see if you were a student looking for homework assistance
This possibility had crossed my mind . . .
> (who can tell?)
. . . and I am not sure how to interpret the offense Erik appears to have taken at my mention of the, err . . . anomalous line.
> Your character sets can't get any longer than what's available on your > system (255?).
Yes, there was a rather deliberate smiley on that line.
> You can always right a function or macro around his idea
I'd have difficulty righting one, but I might just manage to write one :-)
> to handle expressions of of character intervals (regular expression > patterns like [A-G,a-g] that expand into a CASE statement with very > large keys.
By which time finding a way of consecutively numbering the characters and using floor looks a lot more appealing.
* Jacek Generowicz | > | Having said that, the fact that the approach _is_ error-prone is | > | demonstrated by the line of lowercase chars in your code. | > | > I have added you to my do-not-help list. | | I am sorry to hear that. | | I doubt that adding yet-another-wretched-smiley[1], as I had been | tempted to do, would have avoided this.
Probably not. You came here to receive help, and respond by ridiculing those who help you. This is _remarkably_ stupid of you.
| Your sensitivities, in particular, I find extremely difficult to gauge.
How do you react when people sneer at you when you give them a gift you think would be valuable to them, but which might have a very minor flaw that you could easily fix yourself?
I help people I think deserve it. I give you freely of my extensive experience and skills -- I have probably worked longer with computers than you have lived, and offer you time-saving advice so you can be relieved of having to go through all the same problems to arrive at some good practice. I consider it my prerogative to refuse to help people who are so dumb that they do not realize that they came to a public forum of people far better skilled than themselves and ask them to save you potentially a lot of time. You do _not_ just ask other newbies who are are as clueless as yourself, as in the usual horizontal communication that young people tend to think is all there is to communication, but vertical communication to what you should treat as masters and teachers, at least as long as you ask them to help you. If you keep treating those who help you as if they were at your own level, anybody who have a clue will simply ignore your pleas for help. I am impolite enough to tell you, others just do what I have done and do not even tell you. What you react to is probably that I care enough to tell you. Think about this.
You might take some note of the fact that several other people reacted pretty harshly to your snotty-young-punk remark about the "error-prone- ness" that you immediately spotted, anyway, so it could not have been _that_ hard to detect, now, could it?
Another item you should realize causes friction is when you ignore the value of the "Mail-Copies-To: never" header. I started to respond to your mailed copy, which I expressly do _not_ want, when I noticed the news article. When you send someone mail, at least identify it as a mailed copy. As you grow more experienced in using USENET, you also mark your personal communcation as such when you respond to someone's news article by mail. This is actually necessary because private and public communication are very, very different.
/// -- 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.
* Jacek Generowicz | I find this a strange statement to make. It's almost self | contradictory. When typing in lots of (pseudo-)repetitive data, a typo | is exactly the sort of mistake that is very likely to be made, and is | exactly the reason why I naturally look to a more algorithmic solution | in such cases.
Just because you would have typed it in by hand does not mean that other people would. I have already explained how this was produced. Go learn something from it instead of being a snotty thankless punk who find faults that are not there.
| > Alas, like any source code, it is subject to the failings of our | > fingers. Then again, he might have done this on purpose for educational | > purposes, to see if you were a student looking for homework assistance | | This possibility had crossed my mind . . .
Is that why you typed "a-z" instead of "a-e" in your problem spec? You know, most of the world uses QWERTY keybaords. Some of us have seen how some backward European cultures have to use other keyboard layouts with gratuitous key movements, and realize that on an AZERTY keyboard, Z and E are pretty close, while nobody in their right mind would have made this typo on a QWERTY keyboard. Perhaps you should learn something from the fact that I silently ignored the obvious typo you made, even taking into account your probably deviant keyboard?
| . . . and I am not sure how to interpret the offense Erik appears to | have taken at my mention of the, err . . . anomalous line.
Your mention of it would be fine. Sneering at it is not. Let's have another example of how you deal with other people's simple mistakes:
| > You can always right a function or macro around his idea | | I'd have difficulty righting one, but I might just manage to write | one :-)
You cannot help yourself, can you? Here are two words that are often used when responding to people like you in real life: FUCK OFF!
/// -- 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.
> (let ((code (char-code ch))) > (if (> code 128) -1 > (svref #.(let ((array (make-array 128 :initial-element -1))) > (loop for ch > across "abcdefghjklmnopqrstuvwxyz" ;apparently no "i" > for lc = (char-code ch) > for uc = (char-code (char-upcase ch)) > for i from 0 > do ;; I made both upper and lowercase work here, but > ;; obviously you could choose one or the other. > (setf (aref array lc) > (setf (aref array uc) > (truncate i 5))))) > i)))
Your post has given me a number of things to think about. Thanks.
I'd like to go off on one particular tangent for now. As I have no experience with #. and haven't seen it used very often at all, if I were trying to implement an idea like this, I would most probably have chosen to do it with a closure:
;;; To save space for illustrative purposes. (defun complicated-contents-calculation (n) (loop for i from 0 below n collect (* i i )))
Christopher Browne <cbbro...@acm.org> wrote: > Centuries ago, Nostradamus foresaw when Erik Naggum <e...@naggum.net> would write: >> * Thomas Bushnell, BSG >> | And the lack of one letter too. >> The specification of the goddamn _problem_ required I to be >> excluded, you obnoxious dimwit. Pay some _attention_ around here, >> will you? > It was excluded from the "values mapping to 1" sequence. > The very first clause of the spec said a-z map to 0, so for I to map > to NIL seems somewhat unexpected. > Mind you, a waggish answer to the problem would stop with the first > clause: > (defun valuate-ch (ch) > (if (alpha-char-p ch) > 0 > nil))
> That would seem likely to be a bit more correct than what you > presented, not that "a bit more correct" is a terribly useful > metric...
Actually, based on a-z being a-e, which was an error I'd not have thought of, not commonly encountering AZERTY keyboards, I'll propose another answer:
Note that final clause, which shows that there's something fairly seriously lacking in the specifications.
Some might think the appropriate answer to be to return NIL; if I were "king," I'd argue for applying strong electrical shocks to those responsible for creating not-terribly-well-defined specifications.
Presumably _something_ should be done with #\I.
-> Perhaps #\I should be a case that can never happen.
In that case we could add in the clause... ((#\I) (activate-cyanide-feed)) which should never get executed, and so is "perfectly safe."
-> Perhaps #\I should return NIL.
We don't know that, though; it wasn't specified.
The answer of what to do with #\9 or #\+ or #\~ and other non-alphabetic values were also not specified.
The same possibilities also apply; perhaps they can't happen, so having a clause of (otherwise (drop-grand-piano-on-an-unsuspecting-kent-pitman)) might be a very entertaining idea, perfectly safe, for the unwitting Kent, because it'll never happen. -- (concatenate 'string "aa454" "@freenet.carleton.ca") http://www3.sympatico.ca/cbbrowne/rdbms.html The hypochondriac's epitaph: "NOW will you believe me?"
Erik Naggum <e...@naggum.net> writes: > * Jacek Generowicz > | > | Having said that, the fact that the approach _is_ error-prone is > | > | demonstrated by the line of lowercase chars in your code. > | > > | > I have added you to my do-not-help list. > | > | I am sorry to hear that. > | > | I doubt that adding yet-another-wretched-smiley[1], as I had been > | tempted to do, would have avoided this.
> Probably not. You came here to receive help, and respond by ridiculing > those who help you.
I had absolutely no intention of ridiculing you or anyone else. I apologize for any feeling of ridicule you may have inferred from what I wrote.
I agree, in retrorpect, that I should have been more explicitly thankful for your (excellent) suggestion.
If I had considered your offering ridiculous, do you think I would have based one of my two `final' implementation alternatives (see the followup 4 messages downtheread of your original) on it ? As I re-read my comments in that article, I see that I express a slight preference for the solution based on your idea.
Would you care to reconsider your opinion of my opinion of your post ?
> | Your sensitivities, in particular, I find extremely difficult to gauge.
> How do you react when people sneer at you when you give them a gift you > think would be valuable to them, but which might have a very minor flaw > that you could easily fix yourself?
My reasons for wishing to avoid, in general, solutions which involve the generation of tables of (repetitive) data by hand are based on my perception that _I_ am very likely to make mistakes in said generation.
That _you_ made such a mistake only helps to illustrate the point.
By my first comment (which, in retrospect didn't really convey what I meant to say very well at all):
> | > | I guess I can't claim that this is going to become too tedious > | > | or error-prone to write for, err, much longer alphabets :-)
I meant that, given this particular problem, your example, by virtue of its conciseness and clarity, has persuaded me that I can afford to ignore my reservations about generating the data by hand.
The second comment
> | > | Having said that, the fact that the approach _is_ error-prone > | > | is demonstrated by the line of lowercase chars in your code.
was intended to note that there actually is some basis for my reservations about hand-generating data, even for sets as small as this. It was also meant as a friendly remark commenting, in passing, on the fallibility of everyone.
I found the irony --- that in convincing me that I should not worry about making typos, you made exactly the type of typo I feared --- amusing. I hoped you would have found it entertaining too.
I am sorry if you felt offended by it.
I resolve take extra care not to offend your sensitivities in future.
> You might take some note of the fact that several other people reacted > pretty harshly to your snotty-young-punk remark about the "error-prone- > ness"
On my news server (and on Google) there are two articles, besides yours, which can in any way be construed as passing comment on my remark. The _entire_ original contribution of the first is:
Take the solution Jacek. Its the best one. Why make your life difficult? All coding is error prone.
Wade
and of the second:
Jacek,
There is nothing error-prone about this. He just made a typo; you aren't going to get anything tighter than a CASE statement like this.
Alas, like any source code, it is subject to the failings of our fingers. Then again, he might have done this on purpose for educational purposes, to see if you were a student looking for homework assistance (who can tell?)
Your character sets can't get any longer than what's available on your system (255?). You can always right a function or macro around his idea to handle expressions of of character intervals (regular expression patterns like [A-G,a-g] that expand into a CASE statement with very large keys.
slong
I don't find anything harsh in these.
Maybe I am more thick-skinned than you.
Maybe your news server is better than mine.
> Another item you should realize causes friction is when you ignore the > value of the "Mail-Copies-To: never" header. I started to respond to > your mailed copy, which I expressly do _not_ want, when I noticed the > news article. When you send someone mail, at least identify it as a > mailed copy.
By virtue of having hit the wrong key, I accidentally replied to your article, rather than following up, as I had intended. I realized my mistake, and sent you an apology explaining this, four minutes an twenty-four seconds later. Given that over six-and-a-half hours have elapsed between my apology and your reply, I am somewhat surprised to receive these comments. However, I apologize once more, for having accidentally mailed you the message.
In article <tyf3cz93bb7.fsf...@pcitapi22.cern.ch>, Jacek Generowicz wrote: > Your post has given me a number of things to think about. Thanks.
> I'd like to go off on one particular tangent for now. As I have no > experience with #. and haven't seen it used very often at all, if I > were trying to implement an idea like this, I would most probably have > chosen to do it with a closure:
> ;;; To save space for illustrative purposes. > (defun complicated-contents-calculation (n) > (loop for i from 0 below n collect (* i i )))
> Are there arguments to recommend one approach over the other ?
> Are there other ways of achieving something similar ?
You might change complicated-contents-calculation to
(eval-when (:compile-toplevel :load-toplevel :execute) (defun complicated-contents-calculation (n) (format t "~&Computing list~%") (loop for i below n collect (* i i))))
Then save everything in a file, and do compile-file and load. Play around a bit and you'll see that your ``complicated calculation'' is being executed at quite different times. The important thing about the #. read macro is that it is evaluated as early as /read/ time.
Regards, -- Nils Goesche PGP key ID 0x42B32FC9
"The sooner all the animals are dead, the sooner we'll find their money." -- Ed Bluestone
Erik Naggum <e...@naggum.net> writes: > Go learn something from it instead of being a snotty thankless > punk who find faults that are not there. > Is that why you typed "a-z" instead of "a-e" in your problem spec? You > know, most of the world uses QWERTY keybaords. Some of us have seen how > some backward European cultures have to use other keyboard layouts with > gratuitous key movements, and realize that on an AZERTY keyboard, Z and E > are pretty close, while nobody in their right mind would have made this > typo on a QWERTY keyboard. Perhaps you should learn something from the > fact that I silently ignored the obvious typo you made, even taking into > account your probably deviant keyboard?
I see that you are settling into abuse-hurling mode.
As I don't see how anything of any use to anyone can come from this, I trust that you will understand if I decline to continue participation in this exchange.
Just one thing . . .
> | > You can always right a function or macro around his idea > | > | I'd have difficulty righting one, but I might just manage to write > | one :-)
> You cannot help yourself, can you? Here are two words that are often > used when responding to people like you in real life: FUCK OFF!
. . . Would you allow me to assume that other people have a sense of humour, even if you have clearly demonstrated that _you_ have not ?
The self-referential nature of your last sentence, BTW, is quite delightful.
* Jacek Generowicz <jacek.generow...@cern.ch> | I don't find anything harsh in these.
Not in words, but in contents. Some people do not find harshness unless the language is harsh. I ignore form and go for contents. What some people say is really destructive if you care to understand it, but they can be oh so polite in how they express it. I consider polite people who are also destructive to be one of the worst scourges of the earth, because the more polite, the more deliberate the destructiveness.
| Maybe I am more thick-skinned than you.
Maybe you think much less about what people actually say and do.
| By virtue of having hit the wrong key, I accidentally replied to your | article, rather than following up, as I had intended. I realized my | mistake, and sent you an apology explaining this, four minutes an | twenty-four seconds later.
It _arrived_ 8 hours and 47 minutes later.
| Given that over six-and-a-half hours have elapsed between my apology and | your reply, I am somewhat surprised to receive these comments. However, I | apologize once more, for having accidentally mailed you the message.
I think you should be pretty damn careful about making a point out of other people's mistakes when you make so goddamn many of them yourself. If you want to learn, you do not find human fallibility "ironic", you learn how to cope with it. People who defend themselves when criticized also have a problem with human fallibility. And people who turn personal when they are criticized should stay out of public fora. I think you do that. Please try to focus on what you could gain out of your discussions and much less on how you can fun on other people's expense.
/// -- 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.
* Jacek Generowicz | I see that you are settling into abuse-hurling mode.
Wrong. Some day you will learn that you must listen before you talk. Until such time, you are nothing but a yapping puppy. Now, quit peeing on the floor.
/// -- 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.
Jacek Generowicz <jacek.generow...@cern.ch> writes: > Kent M Pitman <pit...@world.std.com> writes:
> > (let ((code (char-code ch))) > > (if (> code 128) -1 > > (svref #.(let ((array (make-array 128 :initial-element -1))) > > (loop for ch > > across "abcdefghjklmnopqrstuvwxyz" ;apparently no "i" > > for lc = (char-code ch) > > for uc = (char-code (char-upcase ch)) > > for i from 0 > > do ;; I made both upper and lowercase work here, but > > ;; obviously you could choose one or the other. > > (setf (aref array lc) > > (setf (aref array uc) > > (truncate i 5))))) > > i)))
> Your post has given me a number of things to think about. Thanks.
> I'd like to go off on one particular tangent for now. As I have no > experience with #. and haven't seen it used very often at all, if I > were trying to implement an idea like this, I would most probably have > chosen to do it with a closure:
> ;;; To save space for illustrative purposes. > (defun complicated-contents-calculation (n) > (loop for i from 0 below n collect (* i i )))
> Are there arguments to recommend one approach over the other ?
Yes.
In favor of #1: a. If you were going to be modifying the datastructure, using a literal constant would not be an option; you're not allowed to modify literal constants. b. Some people don't like the look of #. ... but those people pay a potential speed price in some implementations. c. If you were maintaining your program with other meta-programs that do editing, #. will be lost the first time you read the program #2 and you'll see instead (defun look-it-up-2 (n) (svref #(0 1 4 9 16 25 36 49 64 81) n)) Whether this is good or bad is a subjective judgment, but some would say that if you'd meant to write it this way, it was bad.
In favor of #2: a. Not all implementations do aggressive inlining of variables; this can be faster in some implementations than #1. I don't know any implementations where it is likely or even possible to be slower. b. You don't plan to be modifying cells so that's not an issue.
> Are there other ways of achieving something similar ?
Erik Naggum <e...@naggum.net> writes: > * Jacek Generowicz > | I see that you are settling into abuse-hurling mode.
> Wrong. Some day you will learn that you must listen before you talk. > Until such time, you are nothing but a yapping puppy. Now, quit peeing > on the floor.
As promised, here is the excerpt from our private exchange . . .
> | I think the NG should be dominated by technical traffic.
> So stick to it, damnit.
I resolve to ensure that from now on, at least 95%[1] of the content of each and every one of my posts in comp.lang.lisp will be about Lisp[2].
Would you care to make a similar resolution, Erik ?
I will make my resolution regardless of whether you make one or not, but I think many people would appreciate one from you too.
[1] To allow me some interaction on a friendly human level[3].
[2] I will first post an article stating this resolution, which will have no Lisp content. Thereafter I stick to it.
* Jacek Generowicz <jacek.generow...@cern.ch> | Would you care to make a similar resolution, Erik ?
No. I will continue to respond to and identify people who abuse the goodwill of this and any other technical and professional community in order to feel good about their own bad behavior, usually by posting resolutions instead of just behaving like they say they will. Just behave, respect people you ask for help, listen to criticism, and be grateful for the help you get. If you have to insult and ridicule those who help you, no number of dishonest "resolutions" or apologies will save you. _Only_ your actions (that is, your posted articles) count. Unlike you, most people respond only to the individual article the respond to, not to past promises, resolutions, and apologies. Just behave, and you stay out of trouble. If you are honest about it, you do not need any "resolution" to behave, just do it. It really is that simple.
/// -- 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.
Jacek Generowicz wrote: > As I don't see how anything of any use to anyone can come from this, I > trust that you will understand if I decline to continue participation > in this exchange.
Uh, it ain't easy, but the way not to continue would have been not to post again. A post saying one is not continuing continues. not continuing /was/ a good idea.
bad ideas were:
(1) an entry of lowercase being a problem. nah, that kinda typo turns up in about the first two seconds of testing; and
(2) you wanted a more algorithmic solution? well flunk me out of cryptology, but I did not see a pattern, nor did your spec name a pattern (you just gave all the cases) so... an algorithmic solution would be flat out wrong to code.
--
kenny tilton clinisys, inc --------------------------------------------------------------- "Be the ball...be the ball...you're not being the ball, Danny." - Ty, Caddy Shack
Jacek Generowicz <jacek.generow...@cern.ch> writes: > I doubt that adding yet-another-wretched-smiley[1], as I had been > tempted to do, would have avoided this.
> [1] I hate the things. I don't, in normal conversation, interject > continuously with "you shouldn't take what I just said entirely > seriously", or "nudge, nudge, wink, wink"
No, but you convey *lots* of out-of-band information about your intentions: inflection, tone, meter, facial expressions, body language, etc. I'm not a big fan of smileys, but you do need *some* sort of in-band method of communicating this information online, especially when you're in an international setting (people not on the West Coast, much less in Eastern Europe, are much less likely to parse my writing in the correct rhythm and recreate the out-of-band information).
-- /|_ .-----------------------. ,' .\ / | No to Imperialist war | ,--' _,' | Wage class war! | / / `-----------------------' ( -. | | ) | (`-. '--.) `. )----'
> > Note that final clause, which shows that there's something fairly > > seriously lacking in the specifications.
> Not necessarily. If #\I is just plain wrong, then it's best not to > include it in the (informal) spec. This is practically screaming for > ECASE.
Incidentally, I think (too lazy to check) ISLISP has CASE-USING, where you can specify a predicate like CHAR-EQUAL rather than EQL, which would have avoided the casification problem.
I don't think (though didn't check) it has ECASE-USING, though. Heh. Sometimes ya just can't quite win.
Kent M Pitman wrote: > Steve Long <sal6...@hotmail.com> writes:
> > Jacek,
> > There is nothing error-prone about this. He just made a typo; you aren't > > going to get anything tighter than a CASE statement like this.
> You're not? How about
> (let ((code (char-code ch))) > (if (> code 128) -1 > (svref #.(let ((array (make-array 128 :initial-element -1))) > (loop for ch > across "abcdefghjklmnopqrstuvwxyz" ;apparently no "i" > for lc = (char-code ch) > for uc = (char-code (char-upcase ch)) > for i from 0 > do ;; I made both upper and lowercase work here, but > ;; obviously you could choose one or the other. > (setf (aref array lc) > (setf (aref array uc) > (truncate i 5))))) > i)))
> In most implementations, I'd expect this to be faster than the CASE > statement, not that I checked. At least if you're doing straight > ordering, since it's 25 compares in the worst case and 12.5 in the > average case, compared to the cost of one char-code and one SVREF.
> In certain pathological data where you had a very biased distribution > and you exploited that in the case ordering, you might do better with > the CASE, though I bet even then you'd need nested cases to get > optimal speed.
The problem you were solving was pretty simple, and either approach will work. You will find that there is a trade-off between spending time worrying about achieving a particular style in your implementation, using a style that is easily portable and extensible, and algorithmic efficiency.
As a point of etiquette, don't forget to thank Erik and Barry for their help. These guys can be very helpful when it comes to giving examples of practical solutions (or at least directions for solving problems) in CL.
Jacek Generowicz wrote: > Steve Long <sal6...@hotmail.com> writes:
> > Jacek,
> > There is nothing error-prone about this. He just made a typo;
> I find this a strange statement to make. It's almost self > contradictory. When typing in lots of (pseudo-)repetitive data, a typo > is exactly the sort of mistake that is very likely to be made, and is > exactly the reason why I naturally look to a more algorithmic solution > in such cases.
> > Alas, like any source code, it is subject to the failings of our > > fingers. Then again, he might have done this on purpose for educational > > purposes, to see if you were a student looking for homework assistance
> This possibility had crossed my mind . . .
> > (who can tell?)
> . . . and I am not sure how to interpret the offense Erik appears to > have taken at my mention of the, err . . . anomalous line.
> > Your character sets can't get any longer than what's available on your > > system (255?).
> Yes, there was a rather deliberate smiley on that line.
> > You can always right a function or macro around his idea
> I'd have difficulty righting one, but I might just manage to write > one :-)
> > to handle expressions of of character intervals (regular expression > > patterns like [A-G,a-g] that expand into a CASE statement with very > > large keys.
> By which time finding a way of consecutively numbering the characters > and using floor looks a lot more appealing.
Steve Long <sal6...@hotmail.com> writes: > The problem you were solving was pretty simple, and either approach will > work.
Couldn't agree more; the two favoured solutions I posted reflect this.
> You will find that there is a trade-off between spending time worrying > about achieving a particular style in your implementation, using a style > that is easily portable and extensible, and algorithmic efficiency.
Agreed, but, as Barry astutely observed, I was `hoping that there were some built-in way to map letters directly to their position in the alphabet'.
I asked the question not because I wanted the problem solved quickly, but because in the process of discussing it I hoped to learn some new things about Common Lisp. I have been given food for thought in various corners of the language, and I am grateful to all those who have made suggestions.
I still would be interested to find a built in way of mapping the letters to their positions, though from previous posts I infer that I am unlikely to find one.
-- I resolve to ensure that from now on, at least 95% of the content of each and every one of my posts in comp.lang.lisp will be about Lisp.
Jacek Generowicz, 9-3-2002
Forgive me if I do not respond to non-technical issues.
> > Your post has given me a number of things to think about. Thanks.
> > I'd like to go off on one particular tangent for now. As I have no > > experience with #. and haven't seen it used very often at all, if I > > were trying to implement an idea like this, I would most probably have > > chosen to do it with a closure:
> > ;;; To save space for illustrative purposes. > > (defun complicated-contents-calculation (n) > > (loop for i from 0 below n collect (* i i )))
> In favor of #1: > a. If you were going to be modifying the datastructure, > using a literal constant would not be an option; you're not allowed > to modify literal constants. > b. Some people don't like the look of #. ... but those people pay a > potential speed price in some implementations. > c. If you were maintaining your program with other meta-programs that do > editing, #. will be lost the first time you read the program #2 > and you'll see instead > (defun look-it-up-2 (n) > (svref #(0 1 4 9 16 25 36 49 64 81) n)) > Whether this is good or bad is a subjective judgment, but some would say > that if you'd meant to write it this way, it was bad.
> In favor of #2: > a. Not all implementations do aggressive inlining of variables; this > can be faster in some implementations than #1. I don't know any > implementations where it is likely or even possible to be slower.
I'm not sure I follow. Are you saying that in the closure case there may be an overhead of variable lookup, which, clearly, will never be in the #. case ?
> b. You don't plan to be modifying cells so that's not an issue.
> > Are there other ways of achieving something similar ?
> (defun complicated-contents-calculation (n) > (loop for i from 0 below n collect (* i i )))
> ) ;nehw-lave
I guess it will take me a few readings of the spec around this topic to really get the hang of the purpose of this. Something new to think about, thanks . . . though am I right is suspecting that I can write a lot of Lisp without having to resort to the use of eval-when ?
The spec says
CT LT E Mode Action New Mode Yes Yes --- --- Process compile-time-too <snip: no other lines with Yes Yes in first columns>
Does this mean that your inclusion of :exectue was superfluous ?
> This nullifies advantage 1c since MACROLET information is not lost by the > mere act of reading the expression.
I don't see why you needed the eval-when; as far as I can tell this would work just the same without it.
Hmm . . . I suspect I'm completely missing the point, and will have to read the spec a bit more . . . just one hint, please: is your definiton of look-it-up-2 dependent on your use of eval-when, or are the two unrelated ?
Thank you for your ideas. -- I resolve to ensure that from now on, at least 95% of the content of each and every one of my posts in comp.lang.lisp will be about Lisp.
Jacek Generowicz, 9-3-2002
Forgive me if I do not respond to non-technical issues.
* Jacek Generowicz | I still would be interested to find a built in way of mapping the letters | to their positions, though from previous posts I infer that I am unlikely | to find one.
I find your lack of faith disturbing. In the interest of not having Common Lisp portrayed as thw feeble-minded language you portray it to be, I offer a solution for the public interest, not particularly for you. I would prefer if you did not use it, but instead reinvented this badly.
(- (digit-char-p <char> 36) 10)
returns the numeric value of a character in base 36, which has value 10 for #\A and 35 for #\Z, minus the obvious 10, to get the position of the character. It works in both cases. Note that digit-char-p is probably using a table lookup, so you cannot trust it.
(digit-char (+ 10 weight) 36)
likewise returns the letter of the alphabet corresponding to its position in our basic alphabet, and the easiest solution here, too, is a table lookup, so you cannot trust these solutions at all.
Note that the mess that is created by #\i is actually best left to a table regardless of your highly irrational fear of tables. My suggested solution of using case may be created with a macro if you really, really have to see code that is harder to read and prove correct than a simple table, but know that a case that has only simple constants and values would be turned into a table lookup by any reasonably smart compiler.
Consider, for instance, the same typo in (range #\l #\p) as in its value -- would it be any _less_ error-prone or hard to catch? Considering that you did catch the table error immediately, but have not been able to find your way in the hyperspec for a simple mapping from character to digit, I think you would trust the code just as blindly and irrationally as you do _not_ trust the tables. Irrationalities of your kind betray a larger and more fundamental problem with dealing with human fallibility, of which I think we have seen quite enough.
Please express your gratitude in style with your bogus "resolution".
/// -- 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.