Use of Map

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.