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
············@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)
············@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
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?
>> (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
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)
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)
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
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
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.
············@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
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>"))
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! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'