Remove Items
Function Syntax | (LM:RemoveItems <items> <lst>) |
Current Version | 1.0 |
Arguments | ||
---|---|---|
Symbol | Type | Description |
items | List | List of zero-based integers specifying indexes of items to remove |
lst | List | List from which to remove items |
Returns | ||
Type | Description | |
List | List with items at the specified indexes removed |
Program Description
This function will remove items at specified indexes from a list.
Recursive Version
Select all
;;--------------------=={ Remove Items }==--------------------;; ;; ;; ;; Removes the items at specified indexes from a list ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; items - list of zero-based indexes to remove ;; ;; lst - list from which items are to be removed ;; ;;------------------------------------------------------------;; ;; Returns: List with items removed ;; ;;------------------------------------------------------------;; (defun LM:RemoveItems ( items lst ) (if (and lst items) (if (zerop (car items)) (LM:RemoveItems (mapcar '1- (cdr items)) (cdr lst)) (cons (car lst) (LM:RemoveItems (mapcar '1- items) (cdr lst))) ) lst ) )
Iterative Version
Select all
;;--------------------=={ Remove Items }==--------------------;; ;; ;; ;; Removes the items at specified indexes from a list ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; items - list of zero-based indexes to remove ;; ;; lst - list from which items are to be removed ;; ;;------------------------------------------------------------;; ;; Returns: List with items removed ;; ;;------------------------------------------------------------;; (defun LM:RemoveItems ( items lst / i ) (setq i -1) (vl-remove-if '(lambda ( x ) (member (setq i (1+ i)) items)) lst) )
Example Function Call
_$ (LM:RemoveItems '(1 3 5) '("A" "B" "C" "D" "E" "F")) ("A" "C" "E") _$ (LM:RemoveItems '(2 3) '(0 1 2 3 4 5)) (0 1 4 5)