From: ab talebi
Subject: which articles are sold?
Date: 
Message-ID: <3be1462c.93565658@news.uio.no>
if we have this list:
(a <sold> b c d <sold> e f g <sold>)
that shows that article a, d and g are sold and the rest are not how
can we put all the sold articles in one list:
(a d g)


ab talebi

From: Espen Vestre
Subject: Re: which articles are sold?
Date: 
Message-ID: <w6bsimr61j.fsf@wallace.ws.nextra.no>
············@yahoo.com (ab talebi) writes:

> if we have this list:
> (a <sold> b c d <sold> e f g <sold>)
> that shows that article a, d and g are sold and the rest are not how
> can we put all the sold articles in one list:
> (a d g)

Here's a suggestion: Try mapcon.
-- 
  (espen)
From: Frode Vatvedt Fjeld
Subject: Re: which articles are sold?
Date: 
Message-ID: <2hg07y4obd.fsf@dslab7.cs.uit.no>
············@yahoo.com (ab talebi) writes:

> if we have this list: (a <sold> b c d <sold> e f g <sold>) that
> shows that article a, d and g are sold and the rest are not how can
> we put all the sold articles in one list: (a d g)

This might work:

  (loop for (article sold-mark) on list
     when (and (not (eq '<sold> article))
               (eq '<sold> sold-mark))
     collect article)

-- 
Frode Vatvedt Fjeld
From: ab talebi
Subject: Re: which articles are sold?
Date: 
Message-ID: <3be1529d.2323804@news.uio.no>
On Thu, 01 Nov 2001 14:23:50 +0100, Frode Vatvedt Fjeld
<······@acm.org> wrote:

>············@yahoo.com (ab talebi) writes:
>
>> if we have this list: (a <sold> b c d <sold> e f g <sold>) that
>> shows that article a, d and g are sold and the rest are not how can
>> we put all the sold articles in one list: (a d g)
>
>This might work:
>
>  (loop for (article sold-mark) on list
>     when (and (not (eq '<sold> article))
>               (eq '<sold> sold-mark))
>     collect article)
>
>-- 
>Frode Vatvedt Fjeld

I don't understand your approach with the sold-mark variable. What is
that for? and what is the usage of this code?
From: Frode Vatvedt Fjeld
Subject: Re: which articles are sold?
Date: 
Message-ID: <2h7kta4m29.fsf@dslab7.cs.uit.no>
>>  (loop for (article sold-mark) on list
>>     when (and (not (eq '<sold> article))
>>               (eq '<sold> sold-mark))
>>     collect article)

············@yahoo.com (ab talebi) writes:

> I don't understand your approach with the sold-mark variable. What
> is that for? and what is the usage of this code?

The two variables article and sold-mark iterate over the list such
that sold-mark is the element after the article element. The sold-mark
variable is there to be able to check whether the next element of the
list is the symbol <sold>. Whenever article isn't "<sold>" and the
sold-mark is "<sold>" you collect the article in a list, which is what
I thougth you wanted to do.

-- 
Frode Vatvedt Fjeld
From: Kent M Pitman
Subject: Re: which articles are sold?
Date: 
Message-ID: <sfwlmhqmvpw.fsf@world.std.com>
Frode Vatvedt Fjeld <······@acm.org> writes:

> ············@yahoo.com (ab talebi) writes:
> 
> > if we have this list: (a <sold> b c d <sold> e f g <sold>) that
> > shows that article a, d and g are sold and the rest are not how can
> > we put all the sold articles in one list: (a d g)
> 
> This might work:
> 
>   (loop for (article sold-mark) on list
>      when (and (not (eq '<sold> article))
>                (eq '<sold> sold-mark))
>      collect article)

Iterating by the wrong increment and then patching it by checking the article
variable so you ignore ill-formed cases seems very wrong.  I think you want:

 (loop for (article sold-mark) on list by #'cddr
       when (eq sold-mark '<sold>)
         collect article)
From: ab talebi
Subject: Re: which articles are sold?
Date: 
Message-ID: <3be1598b.4098075@news.uio.no>
On Thu, 1 Nov 2001 14:06:35 GMT, Kent M Pitman <······@world.std.com>
wrote:

>Frode Vatvedt Fjeld <······@acm.org> writes:
>
>> ············@yahoo.com (ab talebi) writes:
>> 
>> > if we have this list: (a <sold> b c d <sold> e f g <sold>) that
>> > shows that article a, d and g are sold and the rest are not how can
>> > we put all the sold articles in one list: (a d g)
>> 
>> This might work:
>> 
>>   (loop for (article sold-mark) on list
>>      when (and (not (eq '<sold> article))
>>                (eq '<sold> sold-mark))
>>      collect article)
>
>Iterating by the wrong increment and then patching it by checking the article
>variable so you ignore ill-formed cases seems very wrong.  I think you want:
>
> (loop for (article sold-mark) on list by #'cddr
>       when (eq sold-mark '<sold>)
>         collect article)
>

but as you see this gives us only the last article
(setf list '(a b <sold> c d <sold> g f))
(defun get-article ()
   (loop for (article sold-mark) on list by #'cddr
       when (eq sold-mark '<sold>)
         collect article))

(get-article)
==>  (D)
From: Kenny Tilton
Subject: Re: which articles are sold?
Date: 
Message-ID: <3BE16A24.1060608@nyc.rr.com>
Someone already said this, but the first thing you want to do is change 
the way you are encoding this info:

    '(a b <sold> c d <sold> g f)

If you do not want to define an article structure or class, at least go 
with:

     ((a)(b . <sold)(c)...


kenny
clinisys
From: Frode Vatvedt Fjeld
Subject: Re: which articles are sold?
Date: 
Message-ID: <2h3d3y4lqx.fsf@dslab7.cs.uit.no>
Kent M Pitman <······@world.std.com> writes:

> Iterating by the wrong increment and then patching it by checking
> the article variable so you ignore ill-formed cases seems very
> wrong.

Yes, it seems in a way wrong to me too, but this is how I understood
the problem: That there is no <not-sold> marker and therefore you
cannot examine the symbols two by two. It's not a good data structure
to start with, so my advice to ab talebi would be to change it to
something more regular (for example by having <not-sold> markers), if
that is possible.

-- 
Frode Vatvedt Fjeld
From: Kent M Pitman
Subject: Re: which articles are sold?
Date: 
Message-ID: <sfwk7xamq0c.fsf@world.std.com>
Frode Vatvedt Fjeld <······@acm.org> writes:

> Kent M Pitman <······@world.std.com> writes:
> 
> > Iterating by the wrong increment and then patching it by checking
> > the article variable so you ignore ill-formed cases seems very
> > wrong.
> 
> Yes, it seems in a way wrong to me too, but this is how I understood
> the problem: That there is no <not-sold> marker and therefore you
> cannot examine the symbols two by two. It's not a good data structure
> to start with, so my advice to ab talebi would be to change it to
> something more regular (for example by having <not-sold> markers), if
> that is possible.

Ok, I see.  Sorry to have doubted you.
From: Lieven Marchand
Subject: Re: which articles are sold?
Date: 
Message-ID: <m38zdqbnm3.fsf@localhost.localdomain>
············@yahoo.com (ab talebi) writes:

> if we have this list:
> (a <sold> b c d <sold> e f g <sold>)
> that shows that article a, d and g are sold and the rest are not how
> can we put all the sold articles in one list:
> (a d g)

More homework?

(loop for (first next) on '(a <sold> b c d <sold> e f g <sold>)
      when (eql next '<sold>)
      collect first)

-- 
Lieven Marchand <···@wyrd.be>
She says, "Honey, you're a Bastard of great proportion."
He says, "Darling, I plead guilty to that sin."
Cowboy Junkies -- A few simple words
From: Paul Foley
Subject: Re: which articles are sold?
Date: 
Message-ID: <m2n126k2dv.fsf@mycroft.actrix.gen.nz>
On Thu, 01 Nov 2001 12:57:40 GMT, ab talebi wrote:

> if we have this list:
> (a <sold> b c d <sold> e f g <sold>)
> that shows that article a, d and g are sold and the rest are not how
> can we put all the sold articles in one list:
> (a d g)

One way would be to locate all the <SOLD> symbols and then collect all
the items that are at the immediately-preceding positions.  Another
would be to walk through the list keeping track of the previous
element at each point, and when you see a <SOLD>, add the previous
thing to the result; that's a one-liner using LOOP...

(defun sold-items (list)
  #.(LET ((A'CAR)(C'CONS)(D'CDR)(E'EQ)(F'FUNCALL)(L'LAMBDA)(Q'COND)(Z'NIL))
      `((,L(,D,E)(,F((,L(,L)((,L(,F)(,F,L(,L(,E,A,L,C)(,F(,F,F,F),E,A,L,C))))
	(,L(,F)(,F,L(,L(,Q,D,C,L)(,F(,F,F,F),Q,D,C,L))))))(,L(,F)(,L(,Q,C,D,A)
        (,Q((,E,Q,Z)(,F((,L(,L)((,L(,F)(,F,L(,L(,E,Q)(,F(,F,F,F),E,Q))))
        (,L(,F)(,F,L(,L(,L,D)(,F(,F,F,F),L,D))))))(,L(,F)(,L(,Q,C)(,Q((,E,Q,Z)
        ,C)(,T(,F,F(,D,Q)(,C(,A,Q),C))))))),A,Q))((,E(,A,Q),D)((,L(,E)(,F,F
        (,D,Q),E,D(,C,C,A)))(,Q((,E,Q,Z),C)(,Z,A)(t(,E,A,D)))))(,T(,F,F(,D,Q)
        (,A,Q),D,A)))))),E,Z,D,Z))'<SOLD> LIST)))

-- 
The power of accurate observation is commonly called cynicism by those
who have not got it.
                                                    -- George Bernard Shaw
(setq reply-to
  (concatenate 'string "Paul Foley " "<mycroft" '(··@) "actrix.gen.nz>"))
From: Thomas F. Burdick
Subject: Re: which articles are sold?
Date: 
Message-ID: <xcv3d3ygenw.fsf@flood.OCF.Berkeley.EDU>
Paul Foley <·······@actrix.gen.nz> writes:

> On Thu, 01 Nov 2001 12:57:40 GMT, ab talebi wrote:
> 
> > if we have this list:
> > (a <sold> b c d <sold> e f g <sold>)
> > that shows that article a, d and g are sold and the rest are not how
> > can we put all the sold articles in one list:
> > (a d g)

If you don't have the slightest desire to learn, why are you in school?

> One way would be to locate all the <SOLD> symbols and then collect all
> the items that are at the immediately-preceding positions.  Another
> would be to walk through the list keeping track of the previous
> element at each point, and when you see a <SOLD>, add the previous
> thing to the result; that's a one-liner using LOOP...
> 
> (defun sold-items (list)
>   #.(LET ((A'CAR)(C'CONS)(D'CDR)(E'EQ)(F'FUNCALL)(L'LAMBDA)(Q'COND)(Z'NIL))
>       `((,L(,D,E)(,F((,L(,L)((,L(,F)(,F,L(,L(,E,A,L,C)(,F(,F,F,F),E,A,L,C))))
> 	(,L(,F)(,F,L(,L(,Q,D,C,L)(,F(,F,F,F),Q,D,C,L))))))(,L(,F)(,L(,Q,C,D,A)
>         (,Q((,E,Q,Z)(,F((,L(,L)((,L(,F)(,F,L(,L(,E,Q)(,F(,F,F,F),E,Q))))
>         (,L(,F)(,F,L(,L(,L,D)(,F(,F,F,F),L,D))))))(,L(,F)(,L(,Q,C)(,Q((,E,Q,Z)
>         ,C)(,T(,F,F(,D,Q)(,C(,A,Q),C))))))),A,Q))((,E(,A,Q),D)((,L(,E)(,F,F
>         (,D,Q),E,D(,C,C,A)))(,Q((,E,Q,Z),C)(,Z,A)(t(,E,A,D)))))(,T(,F,F(,D,Q)
>         (,A,Q),D,A)))))),E,Z,D,Z))'<SOLD> LIST)))

That's beautiful/horrifying.

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | No to Imperialist war |                        
     ,--'    _,'   | Wage class war!       |                        
    /       /      `-----------------------'                        
   (   -.  |                               
   |     ) |                               
  (`-.  '--.)                              
   `. )----'