Giter Club home page Giter Club logo

Comments (7)

d-torrance avatar d-torrance commented on June 14, 2024

We already have f \ L and L / f as shortcuts for apply(L, f). That seems pretty compact!

from m2.

mahrud avatar mahrud commented on June 14, 2024

Compactness is not the main problem, mostly proximity to math notation and readability. directSum(L / a -> (...)) seems worse to me.

from m2.

mahrud avatar mahrud commented on June 14, 2024

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.

d-torrance avatar d-torrance commented on June 14, 2024

-> 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.

mikestillman avatar mikestillman commented on June 14, 2024

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.

mahrud avatar mahrud commented on June 14, 2024

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)
image

Haskell's is pretty nice:

s = [ 2*x | x <- [0..], x^2 > 3 ]

from m2.

mahrud avatar mahrud commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.