Map is a very useful feature, let's give a simple example
Operation of two list elements
(Map + ' (1 2 3) ' ( ) → (51 62 73)
If action for two list elements
(Map if ' (True nil true nil True) ' (1 2 3 4 5) ' (6 7 8 9 10) → ' (1 7 3 9 5)
This is a bit of a meaning, rather with a bunch of bool values to determine whether to pick elements from the first list, or to pick from the second list. Then make a new list.
Use a lambda expression for two lists
(Map (FN (x y) (* x y)) ' (3 4) ' (20 10) → (60 40)
Extract all data from a column in a two-dimensional table
This syntax is very practical and now shows the Rickybody code in the community:
(New Class ' Node) (Set ' l ' (List (node "A" ' Happy) (node "B" ' Sad ") (node" C "' Happy") (node " D" ' indifferent) (node " E" ' Surly ( node "F" ' Happy) ( node "G" ' Sad) ") (println (Map (FN (n) (n 0) L))
The output is:
(Node node node, node node)
if (n 0) is changed to (n 1), the result is:
("A" "B" "C" "D" "E" "F" "G")
Explain:
This creates a node class that uses the newLISP foop mode. Then put multiple node objects in a list, such as Foop, each object is a list, the first element is a type, the second element is the object name, and the third element is an attribute. It looks like a two-dimensional table with three columns and seven rows.
This custom function (FN (n) (n 0)) extracts the No. 0 element in the list of objects and, of course, extracts the 1th and 2nd.
The result becomes a list.
Use of Map