danilopedraza / symstatic

The Symstatic programming language code repository
https://symstatic.org/book
GNU General Public License v3.0
2 stars 0 forks source link

list/set comprehension #7

Closed danilopedraza closed 3 months ago

danilopedraza commented 5 months ago

I want to use list and set comprehensions, just like in Python, SETL and Picat (which I found recently). That will require the addition of a keyword like for, in, or both.

danilopedraza commented 3 months ago

I will define two tipes of set comprehensions:

let ZPlus := { k : k >= 1 }
2 in ZPlus # true
let nums := [1, 2, 3, 4, 5, 6]
for even in { k in nums : isEven(k) }:
    println(even)
danilopedraza commented 3 months ago

Following this definitions, every tangible set is a property set, but the inverse is not true.

danilopedraza commented 3 months ago

I think of list comprehensions the same way Picat does: is just an idiomatic way of mapping an iterable. They are always like this:

[ f(k) : k in iterable ]

While sets can be seen as properties, lists are always seen as ordered containers, independently of how they are generated (lazily or not).

danilopedraza commented 3 months ago

This is naively implemented right now.