Acad Independent Functions

Lists

Topics

Topics in this section:

Predicates

Accessors

Modifying

Mapping, Iteration

Set Operations

Others

Defined in the module STDLIST, the file STDLIST.LSP.

Naming Conventions

CONSP and FIRST,...,REST have no STD- prefix, all others should have. Since native AutoLISP and known utilities have not very much list handling functions, the names are Common Lisp like.

X-OF, ... have no STD- prefix because they are too simple and often needed as readable point accessors. Prefixing these would certainly enlarge line lengths which would require reformatting source code. X-OF has about the same length as CAR.

Function Reference

Predicates

(CONSP x) ; not empty list?

(STD-DOTTED-PAIR-P x) ; (a . b)

(STD-NOT-PROPER-LIST-P x) ; (a b . c) also

(STD-STRING-LIST-P x) ; a list of strings?

(STD-NUMBER-LIST-P x) ; a list of numbers?

Accessors, Searching

single elements:

(FIRST lst) ; as cadr

(SECOND lst) ; as caddr

(THIRD lst) ; as cadddr

(FOURTH lst) ; as (car (cddddr))

(FIFTH lst) ; as (cadr (cddddr))

(SIXTH lst) ; as (caddr (cddddr))

(SEVENTH lst) ; as (cadddr (cddddr))

(EIGHTH lst) ; as (car (cddddr (cddddr)))

(SEVENTH lst) ; as (cadddr (cddddr))

(EIGHTH lst) ; as (car (cddddr (cddddr)))

(NINTH lst) ; ...

(TENTH lst) ; ...

(REST lst) ; as cdr

(STD-LIST-LENGTH lst) ; accepting dotted pairs

(STD-ELT lst i) ; safe NTH variant (throws error)

(STD-POSITION x lst) ; position of x in lst or nil

(STD-POSITION-IF pred lst) ; first x matching pred

(STD-POSITION-IF-NOT pred lst) ; first not matching pred

(STD-RPOSITION x lst) ; last x in lst

(STD-RASSOC x alst) ; reverse assoc

(STD-MEMBER-IF pred lst) ; member with predicate

(STD-MEMBER-IF-NOT pred lst) ;

(STD-COUNT x lst) ;

(STD-COUNT-IF pred lst) ;

(STD-COUNT-IF-NOT pred lst) ;

sublists:

(STD-FIRSTN n lst) ; the first n elements

(STD-NTHCDR n lst) ; the rest after std-firstn.

(STD-SUBSEQ lst start end) ; inclusive start, exclusive end

(STD-BUTLAST lst) ; list without the last element

(STD-SELECT lst i|lst) ; extended ELT for subsequences

Modifying

not destructive operations

(STD-ADJOIN x lst) ; cons if new

(STD-SETNTH new i lst) ; replace at position

Depricated: (STD-RPLACE lst i new) ; old: replace at position

(STD-DELPOS i lst) ; delete at position

(STD-REMOVE x lst) ;

(STD-REMOVE-IF pred lst) ;

(STD-REMOVE-IF-NOT pred lst) ; keep if

(STD-REMOVE-DUPLICATESlst) ;

(STD-SPLIT-LIST n lst) ; split into sublists of length n

(STD-FLATTEN lst) ; tree => flat list

(STD-ROTATE-LEFT lst) ; rotate leftwise: put first to back

(STD-ROTATE-RIGHT lst) ; rotate rightwise: put last to front

push/pop ("destructive" ):

(STD-PUSH x 'lst)

(STD-POP 'lst)

(STD-PUSHNEW x 'lst)

(STD-PUSHMAX x 'lst nmax) ; keep limited stacksize (queue)

Mapping, Iteration

(STD-MAPATOM func tree) ; mapping on each atom in the tree, keeps tree structure intact

(STD-EVERY pred lst) ; T if pred is non-nil for every element

(STD-EVERY-N pred lists) ; for predicates taking more args

(STD-SOME pred lst) ; T if pred is non-nil for some elements

(STD-SOME-N pred lists) ; for predicates taking more args

Set Operations (Lists as unordered multisets)

(STD-UNION set1 set2) ; all elements (unordered)

(STD-ORDERED-UNION set1 set2) ; keeping their order

(STD-INTERSECTION set1 set2) ; elements only in both

(STD-SET-DIFFERENCE set subset) ; set minus subset

(STD-SET-EXCLUSIVE-OR set1 set2) ; only those appearing once

(STD-SUBSETP subset set) ; does set contains subset?

(STD-SET-EQUAL-P lst1 lst2) ; have both the same elements?

Others

list creation

(STD-MAKE-LISTn def); => (def def...) of length n

(STD-INT-LIST n) ; => (0 1 2 3 ...) of length n

(STD-ISEQ start end) ; integer sequence including both

(STD-RSEQ start end n) ; real sequence of n nums

(STD-NXTCYCi n incr-func); next element in integer ringbuffer

(STD-COPY-TREElst) ; => a fresh copy of the list, for sort

sorting and merging

(STD-SORTlst less-pred) ; (std-sort '(2 3 1) '<)

(STD-STABLE-SORTlst less-pred) ; keeping order

(STD-FAST-SORTlst less-pred) ; without removing duplicates

(STD-MERGElst1 lst2 less-pred) ; (std-merge '(0 2 4) '(1 3 5) '<)

randomizing

(STD-RANDOMIZE lst) ; shuffle the list

(STD-RANDOM-ELT lst) ; return a random element from the list

Only Lists, not Sequences (no strings)

Most if the functions follow the ANSI Common Lisp standard, with the difference that AutoLISP list functions cannot operate on sequences, which would include strings too.

Common LISP uses a hierarchical type system. In CL a string is a subtype of a vector, which is a subtype of sequence. A list is also a sequence.
sequence
  –list
  –vector –string

Common Lisp list functions like position, reverse, sort, ... operate on sequences, that means on strings too, which is for performance reasons not implemented in the StdLib. Also we avoid the following incompatibility:

List operations are 0-based but most old string operations are one-based (substr).
(nth 0 '(A B C)) => A, (substr "abc" 1 1) => "a"

However, recently some low-level string functions appeared to be zero-based, which matches other lisps. These are STD-STRING-ELT and STD-STRING-POSITION. Higher level string functions are one based to match SUBSTR.