Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Filtering a list

15 REPLIES 15
Reply
Message 1 of 16
Anonymous
609 Views, 15 Replies

Filtering a list

Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
15 REPLIES 15
Message 2 of 16
Anonymous
in reply to: Anonymous

Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 3 of 16
Anonymous
in reply to: Anonymous

M. Janmaat wrote:
> Hi,
>
> I want to filter a list on the value of each second item in the list.
>
> Something like this;
>
> (filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")
>
> To result in this;
> (("1" "D") ("2" "D"))
>
> Does anyone know is there already is something standard for this?
>
> If not, I'll write something myself, but I'm always open to solutions of
> others : )
>
> Cheers,
>
> M


VL-REMOVE-IF
VL-REMOVE-IF-NOT

--
Message 4 of 16
Anonymous
in reply to: Anonymous

Thanks!

"Martti Halminen" schreef in bericht
news:6267314@discussion.autodesk.com...
M. Janmaat wrote:
> Hi,
>
> I want to filter a list on the value of each second item in the list.
>
> Something like this;
>
> (filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")
>
> To result in this;
> (("1" "D") ("2" "D"))
>
> Does anyone know is there already is something standard for this?
>
> If not, I'll write something myself, but I'm always open to solutions of
> others : )
>
> Cheers,
>
> M


VL-REMOVE-IF
VL-REMOVE-IF-NOT

--
Message 5 of 16
Anonymous
in reply to: Anonymous



Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 6 of 16
Kent1Cooper
in reply to: Anonymous

The 'n' argument is for the possibility that they might want to filter for what is in some position in the sub-lists *other than the second item*, usable with a list of lists that presumably could sometimes be longer than two items. Their example used n=2 for the second item, but that wouldn't always be what they need. That's why they have

(nth (1- n) itm)

instead of

(cadr itm)

inside their original code.

The (vl-remove-if-not) function seems a more accurate "description" of what they want to do. Adjusting their optional item position into your sorted approach, but with the remove-if-not variety:

{code}
(defun FLOLI (lst n flt); for Filter List Of Lists by Item
(vl-sort
(vl-remove-if-not
'(lambda (x) (= (nth (1- n) x) flt))
lst
)
'(lambda (x y)
(< (car x) (car y))
)
)
)
{code}

But their original code leaves the list items that pass the test in their order in the original list, without sorting. If sorting is not required, it can be a lot shorter:

{code}
(defun FLOLI (lst n flt)
(vl-remove-if-not
'(lambda (x) (= (nth (1- n) x) flt))
lst
)
)
{code}

--
Kent Cooper


Some Buddy wrote...
....I could have the same result if I remove every item list in your general list which doesn't have "D" as second element and then sort the resulting list, but then I don't understand what is the 'n' argument for....
Kent Cooper, AIA
Message 7 of 16
Anonymous
in reply to: Anonymous

I don't know, I think that a short explanation of his function would be
helpful, a little bit like how the AutoLISP native functions are presented,
function name, what it does, the arguments and what it returns. If the OP
will find his answer in your derivatives, it's even better.


--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


a écrit dans le message de news:
6267603@discussion.autodesk.com...
The 'n' argument is for the possibility that they might want to filter for
what is in some position in the sub-lists *other than the second item*,
usable with a list of lists that presumably could sometimes be longer than
two items. Their example used n=2 for the second item, but that wouldn't
always be what they need. That's why they have

(nth (1- n) itm)

instead of

(cadr itm)

inside their original code.

The (vl-remove-if-not) function seems a more accurate "description" of what
they want to do. Adjusting their optional item position into your sorted
approach, but with the remove-if-not variety:

{code}
(defun FLOLI (lst n flt); for Filter List Of Lists by Item
(vl-sort
(vl-remove-if-not
'(lambda (x) (= (nth (1- n) x) flt))
lst
)
'(lambda (x y)
(< (car x) (car y))
)
)
)
{code}

But their original code leaves the list items that pass the test in their
order in the original list, without sorting. If sorting is not required, it
can be a lot shorter:

{code}
(defun FLOLI (lst n flt)
(vl-remove-if-not
'(lambda (x) (= (nth (1- n) x) flt))
lst
)
)
{code}

--
Kent Cooper


Some Buddy wrote...
....I could have the same result if I remove every item list in your general
list which doesn't have "D" as second element and then sort the resulting
list, but then I don't understand what is the 'n' argument for....
Message 8 of 16
stevor
in reply to: Anonymous

Seems to work with the input list trewritten to lake lists:
(setq sl ( list (list "1" "X") (list"1" "D") (list "2" "D") ) ) ; input list
(setq rl ( FLOLI 2 sl "D" ) ) ; result list
S
Message 9 of 16
Kent1Cooper
in reply to: Anonymous

It works either way, or by any valid way of making the List, except that the arguments need to be in a different order [list before position number]....

Command: ( FLOLI 2 sl "D" )
; error: bad argument type: listp 2

Command: ( FLOLI sl 2 "D" )
(("1" "D") ("2" "D"))

It even works if not all the sub-lists have "enough" items in them:

Command: (setq sl '((3 4 5) ("yes" 3 8 pi) (89.2 4 "whatever") (T "this" "that" 4)))
Command: (floli sl 4 4)
((T "this" "that" 4))

But if it matters, I found, in experimenting with the same list, that if pi is the element in a list that you're filtering for, you have to "do it right" with a preceding apostrophe to get what you want:

Command: (floli sl 4 pi)
nil

But:

Command: (floli sl 4 'pi)
(("yes" 3 8 PI))

That's not required with the symbols T or nil as elements in the sub-lists. I'm not sure whether there might be other things that would require some kind of special handling, as pi does.

--
Kent Cooper


stevor wrote...
Seems to work with the input list trewritten to lake lists:
(setq sl ( list (list "1" "X") (list"1" "D") (list "2" "D") ) ) ; input list
(setq rl ( FLOLI 2 sl "D" ) ) ; result list
Kent Cooper, AIA
Message 10 of 16
Anonymous
in reply to: Anonymous

Kent1Cooper wrote:

> But if it matters, I found, in experimenting with the same list, that if pi is the element in a list that you're filtering for, you have to "do it right" with a preceding apostrophe to get what you want:
>
> Command: (floli sl 4 pi)
> nil
>
> But:
>
> Command: (floli sl 4 'pi)
> (("yes" 3 8 PI))
>
> That's not required with the symbols T or nil as elements in the sub-lists. I'm not sure whether there might be other things that would require some kind of special handling, as pi does.

That is just the normal Lisp evaluation rules at work: you'd need to
quote any symbol except T or nil, which are self-evaluating, like
numbers and strings.

--
Message 11 of 16
Anonymous
in reply to: Anonymous

Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 12 of 16
Anonymous
in reply to: Anonymous

This seems to work for me;
(foreach blk cgl (if (= (car blk) (substr (car itm) 1 5)) (setq xxx (append
xxx (list (cdr blk))))))
But I would like to know if you have a solition also...


"M. Janmaat" schreef in bericht
news:6270550@discussion.autodesk.com...
Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 13 of 16
Anonymous
in reply to: Anonymous

Hi Marcel,

You can try the next one and see if it suits you in all circumstances. If
you don't need it soerted it can be even shorter.

;;;===================
(defun filter (lst flt)
(vl-sort
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x)(= (car x) flt))
lst
)
)
'(lambda(x y)
(> (car x)(car y))
)
)
)
;;;===================



--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6270550@discussion.autodesk.com...
Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 14 of 16
Anonymous
in reply to: Anonymous

And you call it like this:

(filter '(("E_AKS" "" "" "")("E_ARD" "DD" "0000" "")("E_ARD" "" ""
"")("E_ARM" "B13" "0000" "")) "E_ARD")

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"Some Buddy" a écrit dans le message de news:
6270572@discussion.autodesk.com...
Hi Marcel,

You can try the next one and see if it suits you in all circumstances. If
you don't need it soerted it can be even shorter.

;;;===================
(defun filter (lst flt)
(vl-sort
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x)(= (car x) flt))
lst
)
)
'(lambda(x y)
(> (car x)(car y))
)
)
)
;;;===================



--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6270550@discussion.autodesk.com...
Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 15 of 16
Anonymous
in reply to: Anonymous

Thanks very much!

"Some Buddy" schreef in bericht
news:6270575@discussion.autodesk.com...
And you call it like this:

(filter '(("E_AKS" "" "" "")("E_ARD" "DD" "0000" "")("E_ARD" "" ""
"")("E_ARM" "B13" "0000" "")) "E_ARD")

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"Some Buddy" a écrit dans le message de news:
6270572@discussion.autodesk.com...
Hi Marcel,

You can try the next one and see if it suits you in all circumstances. If
you don't need it soerted it can be even shorter.

;;;===================
(defun filter (lst flt)
(vl-sort
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x)(= (car x) flt))
lst
)
)
'(lambda(x y)
(> (car x)(car y))
)
)
)
;;;===================



--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6270550@discussion.autodesk.com...
Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M
Message 16 of 16
Anonymous
in reply to: Anonymous

You're welcome : )

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6270596@discussion.autodesk.com...
Thanks very much!

"Some Buddy" schreef in bericht
news:6270575@discussion.autodesk.com...
And you call it like this:

(filter '(("E_AKS" "" "" "")("E_ARD" "DD" "0000" "")("E_ARD" "" ""
"")("E_ARM" "B13" "0000" "")) "E_ARD")

--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"Some Buddy" a écrit dans le message de news:
6270572@discussion.autodesk.com...
Hi Marcel,

You can try the next one and see if it suits you in all circumstances. If
you don't need it soerted it can be even shorter.

;;;===================
(defun filter (lst flt)
(vl-sort
(mapcar
'cdr
(vl-remove-if-not
'(lambda (x)(= (car x) flt))
lst
)
)
'(lambda(x y)
(> (car x)(car y))
)
)
)
;;;===================



--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6270550@discussion.autodesk.com...
Hi Some,

Thanks for posting.

Now I came across the following simular "problem";

For example:

I have a list like this;
(("E_AKS" "" "" "") ("E_ARD" "DD" "0000" "") ("E_ARD" "" "" "") ("E_ARM"
"B13" "0000" ""))

I want to filter all lists with "E_ARD" as the first item. and return the
(cdr of that list

Resulting in this;
(("DD" "0000" "") ("" "" ""))

I thought I could use your solution for this. But I haven't figured uit
(yet) how...

Hope you can help.

Kind regards,

M

"Some Buddy" schreef in bericht
news:6267547@discussion.autodesk.com...


Hi,

There's nothing standard other than the AutoLISP functions reference as
presented in the Help. Whatever is not there, has to be built and kept in
your personal library : )

As for your problem, maybe it's a good idea that you elaborate a little more
about what you want to do, because your example is a little bit ambiguous,
because I could have the same result if I remove every item list in your
general list which doesn't have "D" as second element and then sort the
resulting list, but then I don't understand what is the 'n' argument for:

;;;===================
(defun filter (lst flt)
(vl-sort
(vl-remove-if
'(lambda (x)(/= (cadr x) flt))
lst
)
'(lambda(x y)
(< (car x)(car y))
)
)
)
;;;===================

and then

Commande: (filter '(("1" "X") ("1" "D") ("2" "D")) "D")

will return

(("1" "D") ("2" "D"))





--
Humans are born with a wide horizon.
As time goes by, the horizon narrows and
narrows, until it becomes a point of view.


"M. Janmaat" a écrit dans le message de news:
6267279@discussion.autodesk.com...
Now I do this;

(defun filterlist (flt n lst / lstn)
(foreach itm lst (if (= (nth (1- n) itm) flt) (setq lstn (append lstn
(list itm))))) lstn
)

"M. Janmaat" schreef in bericht
news:6267278@discussion.autodesk.com...
Hi,

I want to filter a list on the value of each second item in the list.

Something like this;

(filterlist '(("1" "X") ("1" "D") ("2" "D")) 2 "D")

To result in this;
(("1" "D") ("2" "D"))

Does anyone know is there already is something standard for this?

If not, I'll write something myself, but I'm always open to solutions of
others : )

Cheers,

M

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost