Use List comprehension in Common LISP

Source: Internet
Author: User

 

In Python and Haskell, there are very simple and powerful list comprehension usage:

 

>>> [(X, y) for X in range (1, 4) for Y in ["A", "B"] <br/> [(1, 'A'), (1, 'B'), (2, 'A'), (2, 'B'), (3, 'A'), (3, 'B')] <br/>

 

 

In Common LISP, you can use the incf-Cl library for implementation. It is convenient to install quicklisp:

 

 

* (QL: quickload "incf-Cl") <br/> to load "incf-Cl": <br/> load 1 ASDF system: <br/> Cl-ppcre <br/> install 1 quicklisp release: <br/> incf-Cl <br/>; fetching # <URL "http://beta.quicklisp.org/archive/incf-cl/2010-10-06/incf-cl-20101006-git.tgz"> <br/>; 14.63kb <br/> ====================================== ==================< br/> 14,981 bytes in 0.01 seconds (ipv4.99kb/sec) <br/>; loading "incf-Cl" <br/> .............................. .................... <br/> [Package incf-Cl] ...... <br/> ("incf-Cl") <br/> * (use-package: incf-cl) <br/> T <br/> * (LC (cons x y) (<-X (range 1 3) (<-y '(a B ))) <br/> (1. a) (1. b) (2. a) (2. b) (3. a) (3. b) <br/>

 

 

Incf-Cl is a syntax that imitates HASKELL:

 

Prelude> [(x, y) | x <-[1 .. 3], Y <-["A", "B"] <br/> [(1, "A"), (1, "B"), (2, "A"), (2, "B"), (3, "A"), (3, "B")] <br/>

 

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.