Quick Search for:  in language:    
program,accepts,list,asociation,lists,searche
   Code/Articles  |  Newest/Best  |  Community  |  Jobs  |  Other  |  Goto  | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
LISP Stats

 Code: 6,703. lines
 Jobs: 7. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for LISP.
There is currently no new code. Please check back soon.
Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

asc-list-sorter

Print
Email
 
VB icon
Submitted on: 11/25/2002 3:28:43 PM
By: Greg Whitaker 
Level: Beginner
User Rating: Unrated
Compatibility:Auto Lisp

Users have accessed this code 2565 times.
 
(About the author)
 
     This program accepts a list of as*ociation lists and searches the lists retrieving the elements that the user specifies. The program then takes these elements and places them in a two element list, the first element in the list is the element identifier (e.g. 8 for layer name) and the second element in the list is a list of the element 8's data for all of the as*ociation lists searched. If the user specifies, duplicate entries will be deleted from the list. I have included a commented out test function with this code so that you can run it and see exactly how the code functions.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    ;**************************************
    ; Name: asc-list-sorter
    ; Description:This program accepts a lis
    ;     t of as*ociation lists and searches the 
    ;     lists retrieving the elements that the u
    ;     ser specifies. The program then takes th
    ;     ese elements and places them in a two el
    ;     ement list, the first element in the lis
    ;     t is the element identifier (e.g. 8 for 
    ;     layer name) and the second element in th
    ;     e list is a list of the element 8's data
    ;     for all of the as*ociation lists searche
    ;     d. If the user specifies, duplicate entr
    ;     ies will be deleted from the list. I hav
    ;     e included a commented out test function
    ;     with this code so that you can run it an
    ;     d see exactly how the code functions.
    ; By: Greg Whitaker
    ;
    ; Inputs:1) a list of association lists 
    ;     (NOTE: if using entity data lists for th
    ;     ese the -1 and 330 elements must be remo
    ;     ved because they contain invalid cdrs).
    2) a list of sort elements to retrieve the data for. For example, say you want to retrieve the 0,8 and 11 elements from a list of entity lists, you would simply supply this list '(0 8 11).
    3) A boolean to tell the program whether to remove duplicate elements or not. Supply a "t" if you would like the duplicates elements removed or a "nil" if you would like them left in the lists.
    ;
    ; Returns:This program returns a list of
    ;     lists. Each list within the master list 
    ;     has the same format which is as follows:
    ;     (sort element (list of data retrieved fo
    ;     r that sort element from the as*ociation
    ;     lists)). For example if I was collecting
    ;     the number 8 element from a set of two e
    ;     ntity data lists that had differing laye
    ;     r names, "girt" and "purlin", this progr
    ;     am would return the following: ((8 ("gir
    ;     t" "purlin")))
    ;
    ; Assumes:This program assumes that it i
    ;     s being supplied correct association lis
    ;     ts. That means if you are supplying enti
    ;     ty data lists that contain the -1 and 33
    ;     0 elements that you would get from makin
    ;     g a call to entget, the program will not
    ;     function correctly. You must remove the 
    ;     -1 and 330 elements beforing supplying t
    ;     hem to this function.
    ;
    ;This code is copyrighted and has    ; limited warranties.Please see http://w
    ;     ww.Planet-Source-Code.com/vb/scripts/Sho
    ;     wCode.asp?txtCodeId=59&lngWId;=13    ;for details.    ;**************************************
    
    (defun asc-list-sorter (alists sort-list remove-duplicates? / master-list tmp-lst match nlist)
    (setq tmp-lst (list))
    (foreach sorter sort-list
    (foreach lst alists
    (foreach element lst
    	(if (equal (car element) sorter)
    	 (setq tmp-lst (append tmp-lst (list (cdr element))))
    	 )
    	)
    )
    (if remove-duplicates?
    (setq tmp-lst (remove-duplicates tmp-lst))
    )
    (if master-list
    (setq master-list (append master-list (list (list sorter tmp-lst))))
    (setq master-list (list (list sorter tmp-lst)))
    )
    (setq tmp-lst (list))
    )
    master-list
    )
    (defun remove-duplicates (lst / nlist match)
    (foreach element lst
    (if nlist
    (progn
    	(setq match nil)
    	(foreach mbr nlist
    	 (cond ((null match)
    		 (if (equal element mbr)
    		(setq match t)
    		)
    		 )
    		)
    	 )
    	(if (null match)
    	 (setq nlist (append nlist (list element)))
    	 )
    	)
    (setq nlist (list element))
    )
    )
    nlist
    )
    ; Test function to give you an example o
    ;     f how this program works
    ; 
    ;(defun c:test ()
    ; (asc-list-sorter '(((0 . "LINE") (5 . 
    ;     "2B") (100 . "AcDbEntity") (67 . 0) (410
    ;     . "Model") (8 . "0")
    ;		 (100 . "AcDbLine") (10 4.02739 2.978
    ;     62 0.0) (11 10.8895 5.92974 0.0) (210 0.
    ;     0 0.0 1.0))
    ;		 ((0 . "TEXT") (5 . "2B") (100 . "AcD
    ;     bEntity") (67 . 0) (410 . "Model") (8 . 
    ;     "GIRT")
    ;		 (100 . "AcDbLine") (10 4.02739 2.978
    ;     62 0.0) (11 10.8895 5.92974 0.0) (210 0.
    ;     0 0.0 1.0))
    ;		 ((0 . "LINE") (5 . "2B") (100 . "AcD
    ;     bEntity") (67 . 0) (410 . "Model") (8 . 
    ;     "PURLIN")
    ;		 (100 . "AcDbLine") (10 4.02739 2.978
    ;     62 0.0) (11 10.9999 5.92974 0.0) (210 0.
    ;     0 0.0 1.0))
    ;		 )
    ;'(0 8 11)
    ;t)
    ; )


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments

 There are no comments on this submission.
 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | LISP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.