Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
metalua/samples/clist_test.mlua
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
20 lines (15 sloc)
523 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -{extension "clist"} | |
| -- integers from 2 to 50, by steps of 2: | |
| x = { i for i = 2, 50, 2 } | |
| -- the same, obtained by filtering over all integers <= 50: | |
| y = { i for i = 1, 50 if i%2==0 } | |
| -- prime numbers, implemented in an inefficient way: | |
| local sieve, n = { i for i=2, 100 }, 1 | |
| while n < #sieve do | |
| sieve = { | |
| i for i in values(sieve[1 ... n]); | |
| i for i in values(sieve[n+1 ... #sieve]) if i%sieve[n] ~= 0 } | |
| n += 1 | |
| end | |
| print "Prime numbers < 100, computed with lists by comprehension:" | |
| table.print(sieve) | |