> > In article <3227731039017...@naggum.net>, Erik Naggum <e...@naggum.net> wrote:
> > > Because I want you to quit and stay technical. You keep claiming that > > > you do not want to engage in these things, yet you always _start_ them!
> > Not so. Go back and look how this current conversation started. I wasn't > > even talking to you. All I did was cite something you said. You then > > butted in with "I can speak for myself..." and the whole thing devolved > > from there. I made several attempts to steer the conversation back to > > technical matters, but you deleted those passages every time you > > responded.
> Since you cite very often out of context, your citations are usually > quite annoying provocations.
Here's the passage in question:
But in general, using symbols to name things is the (Common) Lisp way, and using the values directly is the Scheme way.
These are very basic questions, (the kind of problem that one encounters in the first week of an introductory course) so you should be able to find the answers yourself by reading the HyperSpec - Kent even gave you an additional hint, and suggested that you should take a look at mapcar.
Please don't take offense, but we get a lot of students here essentially asking correspondents to c.l.l to do their homework for them. Yours are such elementary questions, that they look like a first week homework set. If you're not asking for help with homework, but are merely a newcomer to Common Lisp, then your should *really* familiarize yourself with the HyperSpec - a document which is one of the best references for any subject anywhere - the Common Lisp community is *extremely* fortunate to have it.
BTW, Kent, who was too modest to say so in his post, is the author of the HyperSpec.
In article <3227763757063...@naggum.net>, Erik Naggum <e...@naggum.net> wrote: > Quit attacking me.
I don't believe I am. But if you could be more specific about what I've said that you consider an attack then I will try to be more careful in the future.
> Quit talking about what I think or believe.
Talking about what others think is an inherent part of academic discourse. You need to realize that just because someone talks about your views doesn't mean that you are under attack. If your views are being misrepresented (which seems hardly possible in this case since all I've done is cite direct quotes from your postings) the appropriate response is to clarify your views, not to insist that people stop talking about them, or to call them idiots.
You are absolutely right about what you said. this is the first time I use newsgroups for such things... Thanks for replying to me. and here are the questions in a clear way and what I did so far:
i wanted to construct a function that will sort this list:
(b (c (d (e f)) ) g h k)
i was able to write the function to sort a list like this but that has integers and not characters.
> > Is this a lisp technical discussion group or what....I did not even receive > > a comment about my questions....
> > desperate here...:)
> You did get replies.
> However, it's hardly surprising you didn't see them and that's your > own fault. You should also always start a new thread when starting a > new topic and put a clear subject line on it. (This is standard > newsgroup procedure, not just for comp.lang.lisp.) Your question was > not about "introduction to Lisp..." so you should have started a new topic. > Having a proper subject line would have made it very much easier to search > for the replies.
> You also even followed up your own original post about substitution > with an apparently-unrelated post about char-code. If those two were > related questions, you did not say how. If they were not releated, you > needed to start a new thread again.
> I replied to both of your queries.
> Incidentally, you didn't say if this was homework. If it was, you should > have said so in the problem description, and you should also have provided > a sample of what code you'd written so far...
So there is no hope for a less hostile, more intelligent Erann Gat who actually manages to focus on the technical, and we can only expect more disillusioned whining and destructive rhetoric and context-free quoting and idiotic attacks that only tell us you refuse to grow a clue. OK.
/// -- 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.
"Sherif Elbanhawy" <egyptiancompu...@hotmail.com> writes: > Thanks for replying to me. and here are the questions in a clear way and > what I did so far:
> i wanted to construct a function that will sort this list:
> (b (c (d (e f)) ) g h k)
> i was able to write the function to sort a list like this but that has > integers and not characters.
As you write it, this tree contains symbols, not characters.
FLATTEN is the common name for this kind of function. Call it whatever you want, but print_list is a bad name for two reasons: First, it doesn't print anything but returns a list; second, we usually use hyphens instead of underscores. And consider using NCONC instead of APPEND.
> I was able to get all the values of the list in one list (b c d e f g h k)
> then I wanna pass this list to char-code to have all the values changed to > their ASCII code.
I don't think there is any guarantee that (char-code #\a) will be the ASCII code of `a'.
> I used this function that I wrote > (sort (mapcar #'char-code '(#\t #\y)) #'>)
> but the problem is I wanna feed the characters in the list to char-code and > not characters that I hardcoded (ex. (#\t #\y in the above example)
> Hope I am clear this time:)
Not yet, I fear :-) First, what does your list really look like? If you do
BLARK 12 > (flatten '(b (c (d (e f))) g h k)) (B C D E F G H K)
you have a list of /symbols/, not characters. And it is already sorted, BTW. Note that the function STRING< works well for symbols, too. If you really want to work with characters, you should do something like
And if you want to sort such a thing, you might either use CHAR< or CHAR-LESSP, or, if you insist on bringing CHAR-CODE into the game, lookup the :KEY argument for SORT.
Regards, -- Nils Goesche Ask not for whom the <CONTROL-G> tolls.
... which is an "expensive" way of reinventing a builtin function called "flatten".
> I was able to get all the values of the list in one list (b c d e f g h k)
> then I wanna pass this list to char-code to have all the values changed to > their ASCII code.
to satisfy my personal curiosity: which programming language(s) do you already know?
> I used this function that I wrote > (sort (mapcar #'char-code '(#\t #\y)) #'>)
you might want to take a look at other sorting functions, for example those for strings ...
> but the problem is I wanna feed the characters in the list to char-code and > not characters that I hardcoded (ex. (#\t #\y in the above example)
hmmm ... if you want to sort the characters represented by the SYMBOL NAMES (hint hint;), why did you hardcode the symbols and not the characters in the first place? Where do those symbols come from?
> Hope I am clear this time:)
I have the feeling that you need to unlearn some old habits to be able to write idiomatic lisp programs. You might also want to read some introductions, referenced e.g. over at http://www.lisp.org
you're right. I think it appeared as a permanent part of my lisp toolbox after a brief encounter with Mathematica some ten years ago ... and I totally forgot about it.
"Sherif Elbanhawy" <egyptiancompu...@hotmail.com> writes: > i wanted to construct a function that will sort this list:
> (b (c (d (e f)) ) g h k)
> i was able to write the function to sort a list like this but that has > integers and not characters.
Your tree doesn't contain characters, it contains symbols. Had it contained characters, Lisp would have printed it like this:
(#\B (#\C (#\D (#\E #\F))) #\G #\H #\K)
> then I wanna pass this list to char-code to have all the values changed to > their ASCII code.
> I used this function that I wrote > (sort (mapcar #'char-code '(#\t #\y)) #'>)
> but the problem is I wanna feed the characters in the list to char-code and > not characters that I hardcoded (ex. (#\t #\y in the above example)
You can perform limited conversion of symbols into characters with either the COERCE or CHARACTER functions. For example, a function which would translate your tree of symbols into a tree of characters could look like this:
Or, using more contemporary Common Lisp functionality, like this:
(defun characterify-tree (tree) (loop for elt in tree collect (if (consp elt) (characterify-tree elt) (character elt))))
Either way, you should get results like this:
(characterify-tree '(a b (c d (e f) g) h)) => (#\A #\B (#\C #\D (#\E #\F) #\G) #\H)
If any of this seems useful, you really ought to read the Common Lisp HyperSpec entry for the CHARACTER function. It has a brief discussion of the situations where coercion between symbols and characters will (and will not) work.
(Erann Gat writes:) Well, according to Erik, it marks me as doing things the "Scheme way". Of course, Erik, also distinguishes between "Scheme is a Lisp" and "Scheme is a member of the Lisp family of languages", so maybe "writing Scheme in CL" and "doing things the Scheme way [in CL]" don't mean the same thing either.
When you're talking about something that you do, believe or think (or whatever) why do you need to bring someone else opinion about it?.
This is a technical forum. It goes like this: 1 You ask a question 2 Get an answer (if lucky) 3 You study the answer assuming it's right 4 Ask for clarification if needed 5 Repeat
Don't need to imagine or talk or whine about other people opinion or thinking.
> > i wanted to construct a function that will sort this list:
> > (b (c (d (e f)) ) g h k)
> > i was able to write the function to sort a list like this but that has > > integers and not characters.
> Your tree doesn't contain characters, it contains symbols. Had it > contained characters, Lisp would have printed it like this:
> (#\B (#\C (#\D (#\E #\F))) #\G #\H #\K)
> > then I wanna pass this list to char-code to have all the values changed to > > their ASCII code.
> > I used this function that I wrote > > (sort (mapcar #'char-code '(#\t #\y)) #'>)
> > but the problem is I wanna feed the characters in the list to char-code and > > not characters that I hardcoded (ex. (#\t #\y in the above example)
> You can perform limited conversion of symbols into characters with > either the COERCE or CHARACTER functions. For example, a function > which would translate your tree of symbols into a tree of characters > could look like this:
> Or, using more contemporary Common Lisp functionality, like this:
> (defun characterify-tree (tree) > (loop for elt in tree > collect (if (consp elt) (characterify-tree elt) (character elt))))
> Either way, you should get results like this:
> (characterify-tree '(a b (c d (e f) g) h)) > => (#\A #\B (#\C #\D (#\E #\F) #\G) #\H)
> If any of this seems useful, you really ought to read the Common Lisp > HyperSpec entry for the CHARACTER function. It has a brief discussion > of the situations where coercion between symbols and characters will > (and will not) work.
Given the style of this function and the desire to use PROG, I get the impression that this class is being taught in an antedilluvian (before the flood of dialects?) style. Did people actually use underscores as word separators back then? I thought the underscore was a very rare character to have before ASCII was in nearly universal use. Or is this just an attempt to make the C programmers taking the class feel better?
-- -> -/ - Rahul Jain - \- <- -> -\ http://linux.rice.edu/~rahul -=- mailto:rj...@techie.com /- <- -> -/ "Structure is nothing if it is all you got. Skeletons spook \- <- -> -\ people if [they] try to walk around on their own. I really /- <- -> -/ wonder why XML does not." -- Erik Naggum, comp.lang.lisp \- <- |--|--------|--------------|----|-------------|------|---------|-----|-| (c)1996-2002, All rights reserved. Disclaimer available upon request.
All I want now is to make the stable-sort function use the list output by the (con..... statement and not the original list. I think that is all I need, right???
"Rahul Jain" <rj...@sid-1129.sid.rice.edu> wrote in message
> Given the style of this function and the desire to use PROG, I get the > impression that this class is being taught in an antedilluvian (before > the flood of dialects?) style. Did people actually use underscores as > word separators back then? I thought the underscore was a very rare > character to have before ASCII was in nearly universal use. Or is this > just an attempt to make the C programmers taking the class feel > better?
> -- > -> -/ - Rahul Jain - \- <- > -> -\ http://linux.rice.edu/~rahul -=- mailto:rj...@techie.com /- <- > -> -/ "Structure is nothing if it is all you got. Skeletons spook \- <- > -> -\ people if [they] try to walk around on their own. I really /- <- > -> -/ wonder why XML does not." -- Erik Naggum, comp.lang.lisp \- <- > |--|--------|--------------|----|-------------|------|---------|-----|-| > (c)1996-2002, All rights reserved. Disclaimer available upon request.
What's with the (L) as the first arg to stable-sort? Does that compile for you?
Anyway, fix that and you are left with a common mistake: append makes a new list which you do not capture anywhere, it just drifts off into a GC. then you sort good old L, which is unchanged and hence still has depth, ie, members which are not chars. char-lessp don't play dat.
throw in (setf L ....) around that append and i think you'll be ok.
--
kenny tilton clinisys, inc --------------------------------------------------------------- "Harvey has overcome not only time and space but any objections." Elwood P. Dowd
Just take charge of your own life, now. Think for yourself. Here is a book suggestion for you: ISBN 0-312-28118-8. Think about yourself, _only_, when you read it. And _please_ figure out this context thing.
/// -- 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.
* Rahul Jain | Did people actually use underscores as word separators back then? I | thought the underscore was a very rare character to have before ASCII was | in nearly universal use.
The underscore is quite young. The character in that position in ASCII and its precursors has a long history, but generally, _ was a back-arrow and ^ was an up-arrow. _ has come to replace blank, which many have rendered as an underscore with very short vertical bars on each side. Primitive syntax descriptions have a serious problem with whitespace, so they claim that a-b is three tokens, a_b one. This arbitrariness is frustrating to people who know better. OfCoursePeopleWhoWriteLikeThisDoNotSeeTheProblem.
| Or is this just an attempt to make the C programmers taking the class | feel better?
It is probably a feebleminded attempt to learn real syntaxes in stages, slow adaptability or something. I mean, no textbooks on Lisp or Scheme or any other sufficiently similar language uses _ in identifiers, so this is an independent creation of the student who is unable to observe what others are doing. Generally, I consider poor indentation and _ in symbol names a clear sign that the requestor is more lost that I would consider it in my interest to try to rectify.
But more generally, space should be a valid character in identifiers, and with ISO 8859 and Unicode, it can be: just use the non-breaking-space. I think this really _rules_ for extra super-high readability.
/// -- 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.
Rahul Jain <rj...@sid-1129.sid.rice.edu> writes: > Bruce Hoult <br...@hoult.org> writes:
> > I may be wrong, but I think I picked up a fine distinction between > > "symbolic programming" (which is pretty much any non-numeric > > programming, done in any language),
> Erm, then would programming using just characters as values be > symbolic programming? No. I have no clue how you picked up this > misconception, but symbolic programming is programming using symbols > as data.
What is a "symbol" according to you?
"Symbolic programming" is a rather broad term which is generally used to contrast with "numeric programming".
> > and "symbol programming", which is specifically the passing around > > of CL symbols (which live in packages, and have function and value > > slots and property lists).
> "Symbol programming" is a term I've never seen before. Not only does > it sound funny, it implies nothing to do with CL...
He (Bruce) made that term up to emphasize the fine line that he is detecting. Right, Bruce?
"Sherif Elbanhawy" <egyptiancompu...@hotmail.com> writes: > Ok Rahul, since you were the first one to know I am a C programmer, let me > ask you this: > This is my code now:
> All I want now is to make the stable-sort function use the list output by > the (con..... statement and not the original list. I think that is all I > need, right???
People here are trying to be helpful. They are giving you all sorts of information. E.g. the fact that your input list does not have characters but symbols.
And the fact that you should use a better editor (since your indentation is "less-than-optimal").
Have you understood the difference between symbols and characters?
Here is the solution BTW. Hope it will help you homework.
Given your last post, I will assume that your input list L is a nested list of characters.
(defun sort-the-homework-list-2 (L) (let ((flattened-list (flatten L))) (unless (every #'characterp flattened-list) (error "Some element in the list (~S) is not a character." (find-if (complement #'characterp) flattened-list))) (sort flattened-list #'char<)))
Does this help? Note that this is a good answer. If your instructor wnats something different it is his problem.
Cheers
-- Marco Antoniotti ======================================================== NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488 719 Broadway 12th Floor fax +1 - 212 - 995 4122 New York, NY 10003, USA http://bioinformatics.cat.nyu.edu "Hello New York! We'll do what we can!" Bill Murray in `Ghostbusters'.
> But more generally, space should be a valid character in identifiers, and > with ISO 8859 and Unicode, it can be: just use the non-breaking-space. I > think this really _rules_ for extra super-high readability.
Provided there is *some* way to visually distinguish it from a breaking space!