From: Claudio Morgia
Subject: Help about lists
Date: 
Message-ID: <356840AF.E3D504@dia.uniroma3.it>
Hi,I'm a student at the University of Rome "RomaTre" and I've a problem
with Common Lisp.
I have a list that can contain symbols and lists,that can contain
symbols and lists and so on.
I need a way to obtain a new list that contains only all the symbols
contained in the nested list: I need to flat a list.
Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)

Does somebody know how can i do?
Thanks a lot,
Claudio

From: marisa
Subject: Re: Help about lists
Date: 
Message-ID: <35686F95.8209731B@kabelfoon.nl>
Claudio Morgia wrote:

> Hi,I'm a student at the University of Rome "RomaTre" and I've a problem
> with Common Lisp.
> I have a list that can contain symbols and lists,that can contain
> symbols and lists and so on.
> I need a way to obtain a new list that contains only all the symbols
> contained in the nested list: I need to flat a list.
> Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)

The easiest way (although it might not be the most efficient) is to make a
recursive function. This is a hint:
suppose the function "flatten" takes a list (possibly with sublists as
elements) and returns a flat list of it. This is how such function should
work:
- if the list is nil then return nil
- otherwise, take the first element of the list. If it is an atom cons it
to the result of applying flatten to the rest of the list. If it is a list,
apply flatten to it and append the result to <flatten of the rest of the
list>
Simple, isn't it?
Prego.
From: Stig Hemmer
Subject: Re: Help about lists
Date: 
Message-ID: <ekv3edz1qpu.fsf@gnoll.pvv.ntnu.no>
Claudio Morgia <······@dia.uniroma3.it> writes:
> Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)

You obviously need to remove all the parenteses.

So, convert the first list to a string, remove all the parenteses from
it, except for the outermost pair, then convert back to a list.

Hope this helps.

Stig Hemmer.
From: Marco Antoniotti
Subject: Re: Help about lists
Date: 
Message-ID: <lw7m3aomqc.fsf@galvani.parades.rm.cnr.it>
Stig Hemmer <····@pvv.ntnu.no> writes:

> Claudio Morgia <······@dia.uniroma3.it> writes:
> > Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)
> 
> You obviously need to remove all the parenteses.
> 
> So, convert the first list to a string, remove all the parenteses from
> it, except for the outermost pair, then convert back to a list.
> 

What if parenthesis are not balanced?

I suggest a YACC grammar (+ lexer of course) capable of reporting such
an error. :)

-- 
Marco Antoniotti ===========================================
PARADES, Via San Pantaleo 66, I-00186 Rome, ITALY
tel. +39 - (0)6 - 68 80 79 23, fax. +39 - (0)6 - 68 80 79 26
http://www.parades.rm.cnr.it
From: Hartmann Schaffer
Subject: Re: Help about lists
Date: 
Message-ID: <3569AE2E.153C033C@netcom.ca>
Marco Antoniotti wrote:
> 
> Stig Hemmer <····@pvv.ntnu.no> writes:
> 
> > Claudio Morgia <······@dia.uniroma3.it> writes:
> > > Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)
> >
> > You obviously need to remove all the parenteses.
> >
> > So, convert the first list to a string, remove all the parenteses from
> > it, except for the outermost pair, then convert back to a list.
> >
> 
> What if parenthesis are not balanced?
> 
> I suggest a YACC grammar (+ lexer of course) capable of reporting such
> an error. :)

Wouldn't this only be possible with symbols that have parentheses in
their names (the string is generated from a list)

-- 

Hartmann Schaffer
Guelph, Ontario, Canada
········@netcom.ca (hs)
From: Rainer Joswig
Subject: Re: Help about lists
Date: 
Message-ID: <yavr88go.fsf@lise.lavielle.com>
Claudio Morgia <······@dia.uniroma3.it> writes:

> Hi,I'm a student at the University of Rome "RomaTre" and I've a problem
> with Common Lisp.
> I have a list that can contain symbols and lists,that can contain
> symbols and lists and so on.
> I need a way to obtain a new list that contains only all the symbols
> contained in the nested list: I need to flat a list.
> Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)
> 
> Does somebody know how can i do?

Sure. You have several options:

1) Hope that somebody from Usenet will do your homework.
2) Try to see if there are solutions available on the
   cheat servers.
3) Browse the Usenet archives for already posted solutions.
4) Browse software archives with Common Lisp code for a version.
   Hint: Typically the function will be called "flatten".
5) Think yourself.

Agreed, version 5) maybe the most complicated.
Maybe you can come up with some thoughts and
we will put you on the right track.

I guess we need a newsgroup:

comp.lang.lisp.homework
From: Markku Laukkanen
Subject: Re: Help about lists
Date: 
Message-ID: <356A58D0.650AAD29@research.nokia.com>
Claudio Morgia wrote:

> Hi,I'm a student at the University of Rome "RomaTre" and I've a problem
> with Common Lisp.
> I have a list that can contain symbols and lists,that can contain
> symbols and lists and so on.
> I need a way to obtain a new list that contains only all the symbols
> contained in the nested list: I need to flat a list.
> Eg: ( A (B (C D) E) (F G ) H) -> ( A B C D E F G H)
>
> Does somebody know how can i do?
> Thanks a lot,
> Claudio

  (defun guy-who-dont-do-his-homework) (x)
   (if (atom x)
     (list x)
      (apply #'nconc
        (fool (car x))
        (mapcar #'guy-who-dont-do-his-homework)  (cdr x)))))


    PKY