> List comprehension should be no stranger to a Python or (and?) Haskell user. It’s a really compact syntax that deals with Cartesian product [emphasis mine] of lists. Ugh, no. I fail to see where the Cartesian product is in:: [(x,y,z) | x --- @dennisvennink What you feel doesn't matter. It's not a zip.
List Comprehension in Swift
11–20 of 32 posts
Re: List Comprehension in Swift
#12Re: List Comprehension in Swift
#13⇒ Generator expressions are the way to go. They would give you the sequence of elements without generating the (potentially enormous) data structure.
From there, methods to reify the items in a sequence would give you your list, array, or dictionary, where needed.
So, for Swift, I wouldn’t use
Array(1..
but the slightly longer Array(for i in 1..
I’m not sure that is easy to fit in the existing parser, though. If it can be fit in, I would allow that code in ‘normal’ nested for loops, too.Re: List Comprehension in Swift
#14Can someone explain the n modulo operation to me?
Re: List Comprehension in Swift
#15I really dislike the proposed way to do this. If this is "Swifty", give me something else. The Haskell list comprehension made sense to me the first time I saw it, but there is no way I'd know what the mess in the article was doing until someone explained to me. Design has to come first. You can't just go with what's "Swifty" if that doesn't convey what's happening in a reasonable fashion.
Re: List Comprehension in Swift
#16I really dislike the proposed way to do this. If this is "Swifty", give me something else. The Haskell list comprehension made sense to me the first time I saw it, but there is no way I'd know what the mess in the article was doing until someone explained to me. Design has to come first. You can't just go with what's "Swifty" if that doesn't convey what's happening in a reasonable fashion.
Given that this is basic Swift, the complaint makes no sense:
let a = Array(1..Re: List Comprehension in Swift
#17Earlier quoted context omitted.
A subset of a Cartesian product is not a Cartesian product. inb4, spare me the wisecrack “It's the Cartesian product of itself and no other factors”.
> It’s a really compact syntax that deals with Cartesian product of lists. Couldn't taking the subset of a Cartesian product be considered to be dealing with one?
Re: List Comprehension in Swift
#18Earlier quoted context omitted.
> It’s a really compact syntax that deals with Cartesian product of lists. Couldn't taking the subset of a Cartesian product be considered to be dealing with one?
Exactly. Indeed, from what I recall from relational database theory, joins are usually treated as cartesian products (outer joins) which are then filtered by the join condition.
Even if you stick to ordinary (inner) joins, they are pullbacks, not products.
Re: List Comprehension in Swift
#19I really dislike the proposed way to do this. If this is "Swifty", give me something else. The Haskell list comprehension made sense to me the first time I saw it, but there is no way I'd know what the mess in the article was doing until someone explained to me. Design has to come first. You can't just go with what's "Swifty" if that doesn't convey what's happening in a reasonable fashion.
> The Haskell list comprehension made sense to me the first time I saw it, but there is no way I'd know what the mess in the article was doing until someone explained to me. Given that this is basic Swift, the complaint makes no sense: let a = Array(1..
Re: List Comprehension in Swift
#20> (Can’t wait until we can have variadic generic parameters!) This.