XLISP member

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# member

Type: | - | function (subr)
Source: | - | xllist.c

## Syntax

(member expr list-expr [{:test | :test-not} test])
  expr - the expression to find [an atom or a list]
  list-expr - the list to search
  test - optional test function, default is eql
  returns - the remainder of the list starting with expr

## Description

The 'member' function searches through 'list-expr' for 'expr'. If found, 'member' returns the remainder of the 'list-expr' starting with 'expr'. If 'expr' is not found, a NIL is returned. You may specify your own test with the ':test' and ':test-not' keywords followed by the test you which to perform.

## Examples

    (member 'a '(1 2 3 4))                         ; returns NIL
    (member '2 '(1 2 3 4))                         ; returns (2 3 4)

    (setq mylist '(2 4 8 16 32 64 128 256))        ; make a numeric list
    (member 6 mylist :test '<)                     ; returns (8 16 32 64 128 256)
    (member 6 (reverse mylist) :test-not '<)       ; returns (4 2)
    (member '20 '(60 40 20 10) :test '> )          ; returns (10)

    (member '(a) '((see) (a) (cat)) :test 'equal)  ; returns ((A) (CAT)) with EQUAL as test
    (member "hi" '("a" "hi" "c") :test 'string= )  ; returns ("hi" "c") with STRING= as test

Note: The 'member' function can work with a list or string as the 'expr'. However, the default eql test does not work with lists or strings, only symbols and numbers. To make this work, you need to use the ':test' keyword along with equal for 'test'.

Common Lisp: Common Lisp supports the use of the ':key' keyword which specifies a function that is applied to each element of 'list-expr' before it is tested. XLISP does not support this.

See the member function in the XLISP 2.0 manual.

Back to Top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference