Closed danilopedraza closed 3 months ago
I will define two tipes of set comprehensions:
property
sets: a set that, in general, cannot be generated or iterated through, and its only purpose is to verify properties. Something likelet ZPlus := { k : k >= 1 }
2 in ZPlus # true
tangible
sets: a property-based restriction of a structure that can be generated or iterated through. Something likelet nums := [1, 2, 3, 4, 5, 6]
for even in { k in nums : isEven(k) }:
println(even)
Following this definitions, every tangible
set is a property
set, but the inverse is not true.
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).
This is naively implemented right now.
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.