Comments (7)
We already have f \ L
and L / f
as shortcuts for apply(L, f)
. That seems pretty compact!
from m2.
Compactness is not the main problem, mostly proximity to math notation and readability. directSum(L / a -> (...))
seems worse to me.
from m2.
To be more specific, here's why I don't think f \ L
and L / f
are any better:
i1 : max({1,2,3} / i -> 10*i)
stdio:1:13:(3): error: expected parenthesized argument list or symbol
Maybe this is solvable independently, but even then I think L / f
and f \ L
are good for piping and other purposes, not set comprehension.
from m2.
->
has really low precedence, so maybe adding a new operator with even lower precedence would work. But I'm not sure what that would be. The natural choices I think would be :
or |
to look like set-builder notation, but both already exist in the language with higher precedence.
from m2.
Personally, I generally prefer the L/f, f/L notation to list comprehensions in e.g. python, not just due to compactness, but also readability, although of course, this kind of like/dislike is a personal judgement. I suggest we try to improve usability of these notions to fix the kind of issues @mahrud found.
from m2.
Maybe the examples I gave weren't good ones, but I don't consider L/f
and f\L
to be list comprehension at all. For instance, here's an example from python:
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
newlist = [x for x in fruits if "a" in x]
We can't do this with L/f
or even apply
alone, we need select
. This is what I think of as list comprehension: (ignore that this one is infinite)
Haskell's is pretty nice:
s = [ 2*x | x <- [0..], x^2 > 3 ]
from m2.
In light of #1978, it would be great if the following were equivalent:
{ 2^x for x in {1..5,3,2:2} if odd x } -- syntactic sugar akin to { 2^x | x \in {1,2,3,4,5,3,2,2}, odd x }
for x in splice(1..5,3,2:2) list if odd x then x^2 else continue
The benefit is that if we wanted an array, we could simply switch to:
[2^x for x in {1..5,3,2:2} if odd x]
As a first step, at least this should work:
for x in splice(1..5,3,2:2) if odd x then x^2
from m2.
Related Issues (20)
- coefficients not returning coefficients in the coefficient ring HOT 2
- AssociativeAlgebras crash
- Cannot load package "ToricVectorBundles" in version 1.23 HOT 2
- Pushforward fails for the cuspidal cubic immersion HOT 2
- LengthLimit in Complexes
- Crash on negative rational exponents HOT 2
- RInterface test failures on loong64/riscv64 architectures HOT 1
- toField() leads to a crash HOT 1
- primaryDecomposition issue with nonstandard grading HOT 2
- Negative variable degrees, incorrectly computed Ext/Cohomology
- Polyhedra Package Changes Lineality Space of Fan
- equality of ideals over different rings
- Promotion issues
- Redhat Enterprise 8 Build problem HOT 20
- Operator wishlist
- Precision error with hilbert basis HOT 1
- Precedence of subscripts and superscripts HOT 1
- "published article DOI" unused for certified packages HOT 1
- Building with Nix - various problems with the autoconf build process HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from m2.