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

Equal elements in list.

29 REPLIES 29
Reply
Message 1 of 30
BillZ
397 Views, 29 Replies

Equal elements in list.

R14 Autolisp:

I have a list of file names, there are at least two files in the list that have the same file extension, eg. cnclbln0.112 & cnclblo0.112 and woodlbl0.112. When these files are chosen from a list, I would like to insure that only files with the same "0.112" are selected. So, how would I check/compare the last 5 characters of the 2-3 members of the list to see if they are indeed the same?

TIA

BillZ
29 REPLIES 29
Message 2 of 30
Anonymous
in reply to: BillZ

I think I understand what you are after A bit clunky, but does it help? Or
have I missed the point on what you are trying to do?


(defun Test (/ Lst i Rtn)
(setq Lst '("cnclbln0.112" "cnclblo0.112" "woodlbl0.112")
Lst (mapcar'(lambda(x)(substr x (-(strlen x)4)(strlen x)))Lst))
(setq i 0)
(while (< i (1+ (length Lst)))
(if (equal (nth i Lst) (nth (1+ i) Lst))
(setq Rtn (cons (nth i Lst) Rtn))
)
(setq i (1+ i))
)
(equal (length Lst) (length Rtn))
)


--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


"BillZ" wrote in message
news:f0e5e9b.-1@WebX.maYIadrTaRb...
> R14 Autolisp:
> I have a list of file names, there are at least two files in the list that
have the same file extension, eg. cnclbln0.112 & cnclblo0.112 and
woodlbl0.112. When these files are chosen from a list, I would like to
insure that only files with the same "0.112" are selected. So, how would I
check/compare the last 5 characters of the 2-3 members of the list to see if
they are indeed the same?
>
> TIA
>
> BillZ
>
>
Message 3 of 30
Anonymous
in reply to: BillZ

Bill:

If you know the exact suffix, eg. "0.112" then this will return the matching
items in the given list of strings:
(defun matchsuffix1 (lst suffix / matches)
(if (/= (substr suffix 1 1) "*")
(setq suffix (strcat "*" suffix))
)
(foreach item lst
(if (wcmatch item suffix)
(setq matches (cons item matches))
)
)
(reverse matches)
)

If you don't care to know the suffix, but just want to derive it from some STR
that's in the list based on the last N characters, then this will do:
(defun matchsuffix2 (lst str n / len matches)
(and
(setq n (1- n))
(setq len (strlen str))
(> len n)
(setq str (strcat "*" (substr str (- len n))))
(foreach item lst
(if (wcmatch item str)
(setq matches (cons item matches))
)
)
)
(reverse matches)
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"BillZ" wrote in message
news:f0e5e9b.-1@WebX.maYIadrTaRb...
> R14 Autolisp:
> I have a list of file names, there are at least two files in the list that
have the same file extension, eg. cnclbln0.112 & cnclblo0.112 and woodlbl0.112.
When these files are chosen from a list, I would like to insure that only files
with the same "0.112" are selected. So, how would I check/compare the last 5
characters of the 2-3 members of the list to see if they are indeed the same?
>
> TIA
>
> BillZ
>
Message 4 of 30
BillZ
in reply to: BillZ

Jason & John
I have the list of suffixes already from the program.
Sometimes the list looks like this: ("0.112" "0.112" "0.112")
But sometime, according to who's selecting from the list, it might look like ("0.112" "0.112" "0.109") which is unacceptable. I'm just looking for a simple way to know that all the selections are the same suffixes. I couldn't get Johns to work. But I'll play around with this stuff and see what I can do.
Thanks.

BillZ
Message 5 of 30
Anonymous
in reply to: BillZ

Check out the VL-EVERY function.  I'm on my
way out the door to grab a bite, but I'll be back soon...
--
Bobby C.
Jones
www.acadx.com


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Jason
& John
I have the list of suffixes already from the program.

Sometimes the list looks like this: ("0.112" "0.112" "0.112")
But
sometime, according to who's selecting from the list, it might look like
("0.112" "0.112" "0.109") which is unacceptable. I'm just looking for a simple
way to know that all the selections are the same suffixes. I couldn't get
Johns to work. But I'll play around with this stuff and see what I can do.

Thanks.

BillZ

Message 6 of 30
Anonymous
in reply to: BillZ

R14, Bobby.

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


> Check out the VL-EVERY function. I'm on my way out the door to grab a
bite, but I'll be back soon...
Message 7 of 30
Anonymous
in reply to: BillZ

Untested, but I think they'll work:

(vl-some '(lambda(x)(substr x (- (strlen x) 4)(strlen x))) Lst) yourlist)

(vl-every '(lambda(x)(substr x (- (strlen x) 4)(strlen x))) Lst) yourlist)
--

Regards,
Eric S.
A2k/W2k
Message 8 of 30
Anonymous
in reply to: BillZ

Oh, yeah. R14.
--

Regards,
Eric S.
A2k/W2k
Message 9 of 30
Anonymous
in reply to: BillZ

Bill,
Does this do it for ya?

(defun Test (/ Lst)
(setq Lst '("cnclbln0.112" "cnclblo0.112" "woodlbl0.112")
Lst (mapcar'(lambda(x)(substr x (-(strlen x)4)(strlen x)))Lst)
)
(not (member 'nil (mapcar '(lambda (x) (equal (car Lst) x)) Lst)))
)

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


>I'm just looking for a simple way to know that all the selections are the
same suffixes.
Message 10 of 30
Anonymous
in reply to: BillZ

Okay, so you know the suffix.
Then...
(defun matchsuffix5 (lst suffix / matches)
(if (/= (substr suffix 1 1) "*")
(setq suffix (strcat "*" suffix))
)
(foreach item lst
(if (wcmatch item suffix)
(setq matches (cons item matches))
)
)
(and lst (= (length matches)(length lst)))
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"BillZ" wrote in message
news:f0e5e9b.2@WebX.maYIadrTaRb...
> Jason & John
> I have the list of suffixes already from the program.
> Sometimes the list looks like this: ("0.112" "0.112" "0.112")
> But sometime, according to who's selecting from the list, it might look like
("0.112" "0.112" "0.109") which is unacceptable. I'm just looking for a simple
way to know that all the selections are the same suffixes. I couldn't get Johns
to work. But I'll play around with this stuff and see what I can do.
> Thanks.
> BillZ
>
Message 11 of 30
Anonymous
in reply to: BillZ

I'll just stay 'Out To Lunch'
--
Bobby C. Jones
www.acadx.com

"Jason Piercey" wrote in message
news:0EB0ACF8E65D2A305121FEB984214342@in.WebX.maYIadrTaRb...
> R14, Bobby.
>
> --
> -Jason
>
> Member of the Autodesk Discussion Forum Moderator Program
>
>
> > Check out the VL-EVERY function. I'm on my way out the door to grab a
> bite, but I'll be back soon...
>
>
>
>
Message 12 of 30
BillZ
in reply to: BillZ

John, Keeps coming up nil.
BillZ
Message 13 of 30
Anonymous
in reply to: BillZ

What keeps coming up nil? Show me.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"BillZ" wrote in message
news:f0e5e9b.10@WebX.maYIadrTaRb...
> John, Keeps coming up nil.
> BillZ
Message 14 of 30
Anonymous
in reply to: BillZ

If what you want is a list with only members that match your suffix then
this small modification of John's program will do it:

(defun matchsuffix (lst suffix / matches)
(setq suffix (strcat "*" suffix))
(foreach item lst
(and
(wcmatch item suffix)
(setq matches (cons item matches))))
(reverse matches))

"John Uhden" wrote in message news:0B4F025D1505E0E4E61CFA5324B14D20@in.WebX.maYIadrTaRb...
> What keeps coming up nil? Show me.
>
> --
> John Uhden, Cadlantic/formerly CADvantage
> http://www.cadlantic.com
> Sea Girt, NJ
>
>
> "BillZ" wrote in message
> news:f0e5e9b.10@WebX.maYIadrTaRb...
> > John, Keeps coming up nil.
> > BillZ
>
Message 15 of 30
Anonymous
in reply to: BillZ

Since you already have the list of suffix's, how is this?

(defun EqLst (Lst)
(not (member 'nil (mapcar '(lambda (x) (equal (car Lst) x)) Lst)))
)

(EqLst '("0.112" "0.112" "0.112"))
T

(EqLst '("0.112" "0.112" "0.109"))
nil

There was a discussion just a few days ago on the equality of lists couldn't
seem to find it today, maybe you can find it?

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program



> I have the list of suffixes already from the program.
Message 16 of 30
Anonymous
in reply to: BillZ

Doug:

I suspected something fishy in the use of (wcmatch) for Bill's data, and found
it...
"." matches any single non-alphanumeric character...
Command: (wcmatch "abc0.112" "*0.112") T
Command: (wcmatch "abc0$112" "*0.112") T

So hopefully Bill is lurking:
(defun matchsuffix6 (lst suffix / n)
(and
lst
(not (atom (cdr lst)))
(= (type suffix) 'STR)
(setq n (1- (strlen suffix)))
(not
(member
nil
(mapcar
'(lambda (x)
(and
(= (type x) 'STR)
(> (strlen x) n)
(= (substr x (- (strlen x) n)) suffix)
)
)
lst
)
)
)
)
)
--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" wrote in message
news:88874917822070120E22C00F7748249F@in.WebX.maYIadrTaRb...
> If what you want is a list with only members that match your suffix then
> this small modification of John's program will do it:
>
> (defun matchsuffix (lst suffix / matches)
> (setq suffix (strcat "*" suffix))
> (foreach item lst
> (and
> (wcmatch item suffix)
> (setq matches (cons item matches))))
> (reverse matches))
>
> "John Uhden" wrote in message
news:0B4F025D1505E0E4E61CFA5324B14D20@in.WebX.maYIadrTaRb...
> > What keeps coming up nil? Show me.
> >
> > --
> > John Uhden, Cadlantic/formerly CADvantage
> > http://www.cadlantic.com
> > Sea Girt, NJ
> >
> >
> > "BillZ" wrote in message
> > news:f0e5e9b.10@WebX.maYIadrTaRb...
> > > John, Keeps coming up nil.
> > > BillZ
> >
>
>
Message 17 of 30
inovat
in reply to: BillZ

Try this one:



(defun check (lst)

(setq str (car lst)

sfx (substr str (- (strlen str) 4))

)

(foreach x (cdr lst)

(if (/= sfx (substr x (- (strlen x) 4)))

(progn

(Alert "Incorrect list. Exiting program")

(exit)

)

)

)

(Alert "List is A-OK")

)



Noah
Message 18 of 30
Anonymous
in reply to: BillZ

Not efficient for large lists, but ...

(defun EqLst ( lst / item )
(setq item (car lst))
(apply 'and
(mapcar
'(lambda (x) (equal x item))
(cdr lst)
)
)
)

Another alternative might be more efficient with large lists ...

(defun EqList ( lst / item )
(setq item (car lst))
(foreach x (cdr lst)
(if (not (equal x item))
(setq lst nil)
)
)
(if lst t)
)

"Jason Piercey" wrote in message
news:CDA247B938ECE60282A710981D0D4A0F@in.WebX.maYIadrTaRb...
> Since you already have the list of suffix's, how is this?
>
> (defun EqLst (Lst)
> (not (member 'nil (mapcar '(lambda (x) (equal (car Lst) x)) Lst)))
> )
>
> (EqLst '("0.112" "0.112" "0.112"))
> T
>
> (EqLst '("0.112" "0.112" "0.109"))
> nil
>
> There was a discussion just a few days ago on the equality of lists couldn't
> seem to find it today, maybe you can find it?
>
> --
> -Jason
>
> Member of the Autodesk Discussion Forum Moderator Program
>
>
>
> > I have the list of suffixes already from the program.
>
>
>
Message 19 of 30
Anonymous
in reply to: BillZ

Noboy likes the one-liner, eh?

--
-Jason

Member of the Autodesk Discussion Forum Moderator Program


> (defun matchsuffix6 (lst suffix / n)
> (and
> lst
> (not (atom (cdr lst)))
> (= (type suffix) 'STR)
> (setq n (1- (strlen suffix)))
> (not
> (member
> nil
> (mapcar
> '(lambda (x)
> (and
> (= (type x) 'STR)
> (> (strlen x) n)
> (= (substr x (- (strlen x) n)) suffix)
> )
> )
> lst
> )
> )
> )
> )
> )
>
Message 20 of 30
Anonymous
in reply to: BillZ

For a relatively small number of list
elements, and assuming only 3 character
file extensions, this should be fine:

(defun equal-extension (filelist)
(apply '=
(mapcar
'(lambda (name)
(strcase (substr name (- (strlen name) 3)))
)
filelist
)
)
)

"BillZ" wrote in message
news:f0e5e9b.-1@WebX.maYIadrTaRb...
> R14 Autolisp:
> I have a list of file names, there are at least two files in the list that
have the same file extension, eg. cnclbln0.112 & cnclblo0.112 and
woodlbl0.112. When these files are chosen from a list, I would like to
insure that only files with the same "0.112" are selected. So, how would I
check/compare the last 5 characters of the 2-3 members of the list to see if
they are indeed the same?
>
> TIA
>
> BillZ
>
>

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

Post to forums  

Autodesk Design & Make Report

”Boost