Saturday, November 21, 2009
Home   |   Search   |   About AUGI   |   My AUGI   |   Join Now

Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP
 Welcome, Guest. 

Login

Join Now FAQ Members List Calendar Search Today's Posts Mark Forums Read

AutoLISP AutoLISP or Visual LISP, learn both here!

Reply
 
Thread Tools Display Modes
Old 2004-06-09, 02:50 PM   #1
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
Default Removing duplicate strings in a list

Can someone refresh my memory as to what function is used to remove duplicate strings from a list.

I'm having a brain fart this morning.

Thanks,
Will
whdjr is offline   Reply With Quote
Old 2004-06-09, 03:24 PM   #2
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default RE: Removing duplicate strings in a list

VL-REMOVE would probably be a good choice.

(vl-remove "hey" '("hey" "this" "is" "a" "bunch" "of" "heys"))
("this" "is" "a" "bunch" "of" "heys")

(vl-remove "heys" '("hey" "this" "is" "a" "bunch" "of" "heys"))
("hey" "this" "is" "a" "bunch" "of")
stig.madsen is offline   Reply With Quote
Old 2004-06-09, 03:30 PM   #3
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
Default RE: Removing duplicate strings in a list

stig,

Thanks for the response. That worked too well I'm afraid.
Let me clarify what I need. I need to delete all the duplicates except one.

list would be :
("hey" "this" "is" "hey" "a" "bunch" "hey" "of" "heys")

remove all "hey" duplicates:
("hey" "this" "is" "a" "bunch" "of" "heys")

Does that clarify it a bit?

Thanks,
__________________
Good Blockin'

Will DeLoach
AutoCad / ADT 2006
whdjr is offline   Reply With Quote
Old 2004-06-09, 04:31 PM   #4
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default

Hmmm, it clarifies but also makes it a bit more complex. How is the code supposed to know which item to keep? If the first match is to remain then perhaps something like this will do?

Code:
(defun removeAllButFirst (item lst / n ll)
  (setq n (cdr (member item lst)))
  (repeat (- (length lst) (length n))
    (setq ll  (cons (car lst) ll)
          lst (cdr lst)))
  (append (reverse ll) (vl-remove item n))
)
stig.madsen is offline   Reply With Quote
Old 2004-06-09, 05:59 PM   #5
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
Default RE: Removing duplicate strings in a list

I just want it remove all items that are the same except one of them. It doesn't matter which one of them.

Thanks,
__________________
Good Blockin'

Will DeLoach
AutoCad / ADT 2006
whdjr is offline   Reply With Quote
Old 2004-06-09, 06:39 PM   #6
MarkTheSwampThomas
Member
 
Join Date: 2004-02
Location: Tampa, Florida
Posts: 32
MarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightlyMarkTheSwampThomas is glowing brightly
Default RE: Removing duplicate strings in a list

I think you want this:

(vl-remove-if predicate-function list)

or:

(vl-remove-if-not predicate-function list)
__________________
C3D/LDT2006
I'd rather be using NetBSD
MarkTheSwampThomas is offline   Reply With Quote
Old 2004-06-09, 07:29 PM   #7
stig.madsen
100 Club
 
Join Date: 2000-12
Posts: 126
stig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightlystig.madsen is glowing brightly
Default

Ah, no need for order, only removing duplicates:

Code:
(defun removeDups (item lst / ll)
  (foreach n lst
    (cond ((equal n item)
           (and (not (member item ll))
                (setq ll (cons n ll))))
          (T (setq ll (cons n ll)))))
  (reverse ll)
)
Ok, so it keeps the first occurrence like the former

Mark, just being curious: which predicate function would you write for VL-REMOVE-IF to remove duplicates?
stig.madsen is offline   Reply With Quote
Old 2004-06-09, 07:40 PM   #8
whdjr
I could stop if I wanted to
 
Join Date: 2003-05
Posts: 335
whdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of lightwhdjr is a beam of light
Default RE: Removing duplicate strings in a list

Thanks stig I'll work that into my code and see how it works.
__________________
Good Blockin'

Will DeLoach
AutoCad / ADT 2006
whdjr is offline   Reply With Quote
Reply


Go Back   AUGI Forums > AUGI Technical (English) > Programming > AutoLISP

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate centroids panderson.60593 AutoCAD Map 3D - General 3 2004-06-09 05:40 PM
List of problems after my first big work with Revit overcaffeined Revit Architecture - General 12 2004-02-04 05:43 AM


All times are GMT +1. The time now is 01:15 PM.