CLisp Programming LISP program that produce a mirrored list

Discussion of Common Lisp
findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: CLisp Programming LISP program that produce a mirrored list

Post by findinglisp » Thu Feb 26, 2009 11:15 am

intel1397 wrote:I came to this forum to learn and discuss Lisp Programming of any dialect. Not to have my “easy” question ridiculed and mocked about. Now if there is such a category “so easy it must be for homework or learning CL.” point me in the direction so that I am able to get the help that I need other then some immature juvenile looking to distract a new learner of CLISP. I understand that in order to learn the language one must first put forth at least something regarding the issue in question, and so I will and have done just that.

However if this is the way you all treat each other here then Ill just have to find another forum, for this one has to find valuable solutions to various problems.

findinglisp-Im shocked that you, an Admin would instigate something like that.

Im sorry I came here. I guess I took a wrong turn.
Lets make sure no one else makes the same mistake.

WOT/mcafee site advisor – mediary
GoogleReviews
Intel1397
Sigh...

Okay, first, nobody mocked you. They simply said that you were asking something that sounded like a homework question and because of that, rather than answer it directly, they would give you a pointer that would hopefully help you discover the answer yourself.

Second, you only have 3 posts at the present time on this site. You don't have a history with this forum or its members that lets us know anything about you.

Third, your original post lacks all context for what you are trying to do, in the large. You simply ask a basic "How do I...?" question and that's all. There is no, "I'm trying to write a program to do X," or "I'm trying to learn Lisp so that I can do Y."

Realize that there are a LOT of members of this forum that only have about 2 or 3 posts on this forum and don't read it actively. Their posts typically look exactly like yours. The dynamic is this... Around the start of a new semester, a bunch of college undergrads always land in an AI or basic programming class where somebody (rightly!) tries to teach them Scheme or Lisp. When they get confused or lazy or whatever, they run straight to comp.lang.lisp or LispForum or whereever and post a question like, "How do I perform such-and-such basic list manipulation?" There is no history with the forum. There is no context that suggests a bigger purpose. In fact, the questioner typically tries to keep all the context out of it because they want somebody to answer a homework question for them and provide them code that they will then submit to their prof for credit. Once the question is answered, they disappear, never to return. Maybe we actually get a "Thank you" posting, but that's about it.

So, please forgive us if we have judged you incorrectly. Your question looks a lot like a common pattern that Lispers are very used to--an undergrad looking for a quick way to solve a homework problem. If you hang around here a while, you'll find us a very friendly and helpful group, but you'll also find that we have no interest in doing anybody's homework for them. Suggestions for how to figure things out themselves? Sure, we'd be happy to help with that. We all want people to learn Lisp.

There are some things you can do in the future, should you decide to return, that will help make future requests for help look like "real questions" (yea, I know, whatever that might mean), rather than requests to solve homework problems:
  1. First, tell us something about yourself, either in your first posting or in a specific posting in the Lounge. We'd like to meet you and hear about how you came to want to learn Lisp and what you're trying to do with it. That's all good from a community standpoint. It allows us to get to know each other better. If you just pop in, and ask a question with no context as your first posting, it's almost impolite. You wouldn't run up to a stranger on the street and ask them something similar, with no introduction or context, so why would you think it would work on a forum?
  2. When you post a question, tell us what you have tried and why it's not working. Undergrads post lots of "How do I do X?" questions, with nothing beyond that. Real programmers learning new languages post, "I'm trying to figure out how to do X. Right now, I have written this..., but it's not working the way I want it to. I have looked in the Common Lisp Hyperspec, for such and such, and I'm obviously doing something wrong. Can anybody spot what it is in this code ... or give me a pointer to something that might help me?" Remarkably, when confronted with a request like this, where the one posing the question looks like he's done some background work, people will often rise to the occasion and supply lots of code.
  3. Where did you come up with such a problem? Are you working through a book? If so, which one? Which page is the problem on?
In short, rather than being insulted yourself, perhaps you can stop and think about your behavior and realize that the active members of this forum have demonstrated their value to this community already while you have not. They have a right not to be asked to solve homework problems on demand. If you, by your manner and question, look like you are trying to play them for fools, it's not unreasonable for them to treat you as such. If that's not the case, then by all means come in, introduce yourself, kick your feet up on the footstool and have a drink with us while we discuss Lisp. We'd love to have you as part of our community.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: CLisp Programming LISP program that produce a mirrored list

Post by findinglisp » Thu Feb 26, 2009 11:22 am

BTW, I should also clarify. If you are an undergrad learning Lisp, you're still very welcome on this forum. We will not do your homework for you, but we will try to point you in the right direction. If you're really trying to learn Lisp and not just use the forum members as an oracle for Lisp homework problems, we'd love to have you here.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

intel1397
Posts: 5
Joined: Wed Feb 25, 2009 1:23 pm

Re: CLisp Programming LISP program that produce a mirrored list

Post by intel1397 » Thu Feb 26, 2009 11:47 am

Well well well.
Looks I really did blew it all out of proportion.

In fact I will now mark all of post with a trailing 2.0, just to show that I have upgraded.


I'm threw with this thread.
Down the Hatch!
2.0

smithzv
Posts: 94
Joined: Wed Jul 23, 2008 11:36 am

Re: CLisp Programming LISP program that produce a mirrored list

Post by smithzv » Thu Feb 26, 2009 2:34 pm

:shock: Whoa, what just happened...
I came to this forum to learn and discuss Lisp Programming of any dialect. Not to have my “easy” question ridiculed and mocked about.
intel1397, in case you are reading this: I was here just yesterday and I thought I was helping. I think I have just witnessed myself being a smug Lisp weenie of sorts. I will just go ahead and use this skill my fiancee taught me and say, "I'm sorry". I have been on the other side of this many times (though never here) and it is not fun.

There are easy problems and there are hard problems and everything in between; I was not trying to mock you by saying your problem was too easy, nor was I trying to say you were stupid to have to ask. In fact, it is kind of tricky and your solution turned out clearer than mine. You see, I coded up a solution when I read your post, but before I posted it I got to thinking about what good was it going to do you. If the entire point was to learn how to create such functions yourself, posting this is actually detrimental to your learning. That is how they train you to teach people where I work. So I said what I said.

To others, I definitely don't want to go down the road of reinforcing Lisper stereotypes. I didn't think my post was going to go down like I was a $%!#@!-bag, but it seemed to, at least to the OP. In the past I have saturated my posts with a multitude of complements, reassurances, and sugar coating to diffuse this kind of reaction. Basically, all of the last paragraph would be paraphrased in some way in my post. Isn't there another way; it seems wasteful... maybe my language is just too blunt. Anyway, let me be an example of what not to do.

Zach S

Harleqin
Posts: 71
Joined: Wed Dec 17, 2008 5:18 am
Location: Bonn, Germany

Re: CLisp Programming LISP program that produce a mirrored list

Post by Harleqin » Thu Feb 26, 2009 10:12 pm

CONSP is just the inverse predicate of ATOM.

I thought that I'd use a LAMBDA for testing before recursing; something like:

Code: Select all

(defun mirror-list (list)
  (reverse (mapcar (lambda (element)
                     (if (consp element)
                         (mirror-list element)
                         element))
                   list)))
However, I like your version better now :) -- at least in principle. I have a few stylistic annotations:

- Don't use underscores to separate words in variable names. Use hyphens instead.
- To insert a function as an argument, use the "#'" reader syntax, which is an abbreviation for FUNCTION (can someone explain why the single quote seems to work here, too?).
- The interpreter will upcase ALL symbols, but usually, everything is written in lowercase.
- Use meaningful names.

Code: Select all

(defun mirror-image (maybe-list)
  (if (atom maybe-list)
      maybe-list
      (reverse (mapcar #'mirror-image maybe-list))))
"Just throw more hardware at it" is the root of all evil.
Svante

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: CLisp Programming LISP program that produce a mirrored list

Post by Jasper » Fri Feb 27, 2009 4:52 am

Harleqin wrote:(can someone explain why the single quote seems to work here, too?).
Guess it just looks for functions attached to symbols, if it requires a function, and gets a symbol. Btw, your example only works on lists, better(imo) equivalently to the loop:

Code: Select all

(defun mirror-list (maybe-list)
  (if (listp maybe-list)
     (reverse (mapcar #'mirror maybe-list))
     maybe-list))
Edit: i am such a pedant..
Last edited by Jasper on Fri Feb 27, 2009 7:33 pm, edited 1 time in total.

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: CLisp Programming LISP program that produce a mirrored list

Post by findinglisp » Fri Feb 27, 2009 10:04 am

smithzv wrote: To others, I definitely don't want to go down the road of reinforcing Lisper stereotypes. I didn't think my post was going to go down like I was a $%!#@!-bag, but it seemed to, at least to the OP. In the past I have saturated my posts with a multitude of complements, reassurances, and sugar coating to diffuse this kind of reaction. Basically, all of the last paragraph would be paraphrased in some way in my post. Isn't there another way; it seems wasteful... maybe my language is just too blunt. Anyway, let me be an example of what not to do.
Zach, I didn't think your response was out of line. A little blunt, maybe, but it was clearly a jest and you did offer suggestions to the OP. As the founder of this forum, I'll second your sentiment that I don't want this forum to go down the road of reinforcing Lisper stereotypes. I created LispForum because I wanted a place that was not comp.lang.lisp, where people would feel free to ask questions, and not run into c.l.l-style "smug Lisp weenieness."

That said, I also fundamentally don't believe in catering to the lowest-common-denominator when it comes to interpersonal interaction. I hate today's overly politically-correct world where the highest goal is to never create offense for anybody else. I (we) cannot help if somebody if overly sensitive, and I don't want everybody here walking on egg-shells, writing all sorts of flowery disclaimers to avoid any possibility that anybody would be offended by anything. Simply, while nobody should be quick to give offense, nobody should be quick to take offense, either.

Let's everybody shoot straight, apologize when toes are stepped on or we get out of line, and otherwise move on.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

qbg
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: CLisp Programming LISP program that produce a mirrored list

Post by qbg » Fri Feb 27, 2009 1:52 pm

Harleqin wrote: - To insert a function as an argument, use the "#'" reader syntax, which is an abbreviation for FUNCTION (can someone explain why the single quote seems to work here, too?).
The FUNCTION special form returns the function associated with a function designator, and a symbol can be a function designator. Some functions that take functions can take either, while some can take only a function.
Harleqin wrote: - The interpreter will upcase ALL symbols, but usually, everything is written in lowercase.
Nitpick: It is the reader, not the interpreter, that uppercases the symbols. You can change this by setting the READTABLE-CASE of the current readtable (though if you do, please note that the symbols exported from COMMON-LISP are uppercased, so if you wanted a case-sensitive readtable, using a READTABLE-CASE of :invert would probably be what you want to do).

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: CLisp Programming LISP program that produce a mirrored list

Post by findinglisp » Fri Feb 27, 2009 4:31 pm

qbg wrote:Some functions that take functions can take either, while some can take only a function.
A good example of taking either a function or a function designator is FUNCALL. You could, for instance, do either

Code: Select all

(funcall #'foo)
or

Code: Select all

(funcall 'foo)
If you do the latter, it will essentially call FUNCTION on the symbol you give and then funcall the resulting function. While in this trivial example, I'd always use #'foo (more idiomatic), the fact that FUNCALL does this is convenient in other contexts. For instance, you can use function names, not the functions themselves, in a table that maps symbols to a particular function to call in a given context. When you print the value of the table, you can easily see the function names as symbols and not as "#<compiled function 902734029>" or some such unreadable nonsense.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

raffaelcavallaro
Posts: 5
Joined: Mon Feb 02, 2009 3:00 pm

Re: CLisp Programming LISP program that produce a mirrored list

Post by raffaelcavallaro » Fri Feb 27, 2009 11:03 pm

Code: Select all

(defun mirror (list)
  (reverse
   (loop for elt in list collect
     (if (consp elt) (mirror elt) elt))))

(defun mirror2 (list)
  (reverse
   (mapcar
    (lambda (elt)
      (if (consp elt) (mirror elt) elt))
    list)))

Post Reply