Jump to content

Recommended Posts

Posted

Hi all...

I have a list ("BLKCIR" "BLKCIR" "BLKCIR" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1")

 

I want count the numbers of same block, means if I have user input "BLOCK1... and It will be ( "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1")")

 

I wrote a routine, but surely did some mistake :unsure:

 

 

 

(defun duplc ()

(setq name_lis '(..........)

(setq lista '())

(setq listb '())

(setq blkinput(strcase (getstring "\nPlease Enter a Block Name :-  ")))

(setq count 0 len (length name_lis))

(While (< count len)

 (setq listc (nth count name_lis))

(if (=  (member blkinput listc) nil)

(setq lista (append lista (list blkinput)))

     ) ;if

 (setq listb (append listb (list lista)))

 (setq count (1+ count))

 )  ; while

 listb

                ) ; defun

 

 

I am a beginner in LISP.. this is for your kind info.. :geek:

Posted

Using Visual LISP:

 

(vl-remove-if-not
  '(lambda ( x ) (eq "BLOCK1" x))
  '("BLKCIR" "BLKCIR" "BLKCIR" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1")
)

 

In Vanilla:

 

(apply 'append
   (mapcar
      '(lambda ( x ) (if (eq "BLOCK1" x) (list x)))
      '("BLKCIR" "BLKCIR" "BLKCIR" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1" "BLOCK1")
   )
)

 

BTW, did you resolve your last thread? :?

 

http://www.cadtutor.net/forum/showthread.php?64380-any-other-function&p=439278

Posted

Or maybe like :

(defun count (lst / old res)
(foreach item lst
   (if (setq old (assoc item Res))
       (setq Res (subst (cons item (1+ (cdr old))) old Res))
       (setq Res (append Res (list (cons item 1))))
   )
))

Or :

(defun count (lst / ret)
(while lst    
(setq ret (append Ret (list (cons (car lst)(- (length lst) (length (setq lst (vl-remove (car lst) lst))))))))    
)
ret
)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...