2 ms·
Makes me wonder if maybe the syntax for mapping, folding and other collection operations should have a similar syntax to for instead of the current method-style
by tormeh 8y ago
Makes me wonder if maybe the syntax for mapping, folding and other collection operations should have a similar syntax to for instead of the current method-style syntax popular in most modern languages.
- symlinkk 8y agoC# has a syntax called Linq Query Syntax that provides keywords in the language to do things like map, filter, and reduce. Example: var queryLondonCustomers = from cust in customers where cust.City == "London" select cust; I'm not a big fan of it honestly, the function style seems more consistent and easier to read to me.
- hnlauncher 8y agohttps://www.pyret.org/ https://www.pyret.org/ does it like this: for each(str from [list: "Ahoy", "world!"]): print(str) end for map(n from [list: 1,2,3]): n * n end # ==> [list: 1, 4, 9] for filter(n from [list: 1, 2, 3]): n >= 2 end # ==> [list: 2, 3] for fold(sum from 0, n from [list: 4, 5, 6]): sum + n end # ==> 15
- saghm 8y agoThat sounds a lot like Python list comprehensions