XLISP > XLISP Plus  -  Previous | Next

mapcon


Type:   -   defined macro (closure)
Source:   -   init.lsp

Syntax

(mapcon function list1 [list2 ... ])
function - a function definition like a lambda form
listN - a list or list expression
returns - a list from the results of the function applications

Description

The 'mapcon' macro applies the 'function' to the successive cdrs of each of the lists 'listN'. Each of the lists supplies one of the arguments to 'function'. The 'mapcon' macro is similar to the maplist function, except that 'mapcon' returns a list that is constructed via the destructive nconc function from the results of the 'function' applications. If the lists are of different lengths, the shortest list will determine the number of applications of 'function'.

(defmacro mapcon (&rest args)
  `(apply #'nconc (maplist ,@args)))

Note: The 'mapcon' macro is intended to simplify porting code from Common Lisp to XLISP. This macro is not included in the standard Nyquist distribution. If you want to use it, copy the code above to your 'init.lsp' file.

Examples

(maplist 'list '(a b))   ; returns (((A B)) ((B)))
(mapcon  'list '(a b))   ; returns ((A B) (B))

Note: Remember that 'mapcon' uses nconc and so it destructively deals with its list arguments.

Note: The use of the 'function' will work properly when it is a quoted symbol [the name of the function], an unquoted symbol whose value is a function or a closure object like a lambda form.

See also the XLISP Plus mapcan function.


XLISP > XLISP Plus  -  Previous | Next