chris-martin / bricks

Bricks is a lazy functional language based on Nix.
https://hackage.haskell.org/package/bricks
6 stars 1 forks source link

Allow lists in the right-hand side of dot expressions #8

Open chris-martin opened 6 years ago

chris-martin commented 6 years ago

https://twitter.com/chris__martin/status/911280998389878791

As partial compensation for removing with (#7), we could introduce a new bit of list syntax which would cover the most revered use case, the maintainers field in a nix package.

This is what a common package meta attribute looks like now:

meta = with stdenv.lib; {
    description = "Set of integrated tools for the R language";
    homepage = http://www.rstudio.com/;
    license = licenses.agpl3;
    maintainers = with maintainers; [ ehmry changlinli ciil ];
    platforms = platforms.linux;
};

Proposing to change it to something like this:

meta = let inherit (stdenv.lib) licenses maintainers platforms; in {
    description = "Set of integrated tools for the R language";
    homepage = http://www.rstudio.com/;
    license = licenses.agpl3;
    maintainers = [ inherit (maintainers) ehmry changlinli ciil ];
    platforms = platforms.linux;
};
chris-martin commented 6 years ago

Alternatively: Allowing lists in the right-hand position of a dot expression would be less invasive. Actually, something close could be accomplished with no change to the grammar at all, just a slight change to the dict lookup semantics:

meta = let inherit (stdenv.lib) licenses maintainers platforms; in {
    description = "Set of integrated tools for the R language";
    homepage = http://www.rstudio.com/;
    license = licenses.agpl3;
    maintainers = maintainers.${[ "ehmry" "changlinli" "ciil" ]};
    platforms = platforms.linux;
};

Though more ideally I would like to be able to remove the antiquotes,

meta = let inherit (stdenv.lib) licenses maintainers platforms; in {
    description = "Set of integrated tools for the R language";
    homepage = http://www.rstudio.com/;
    license = licenses.agpl3;
    maintainers = maintainers.[ "ehmry" "changlinli" "ciil" ];
    platforms = platforms.linux;
};

which I believe could be done without much trouble.

chris-martin commented 6 years ago

To make "list inheriting" a bit more flexible, and also make list syntax more like dict syntax, we could introduce optional semicolons.

> let x = { a = "1"; b = "2"; }; in [ inherit (x) a b; "3" "4" ]
[ "1" "2" "3" "4" ]

This is starting to get \~weird\~, though, because then lists would be a mixture of space-delimited and semicolon-delimited items.

Antiquotation isn't allowed inside lists yet, so we could use that...

> let x = { a = "1"; b = "2"; }; in [ ${ inherit (x) a b } "3" "4" ]
[ "1" "2" "3" "4" ]
chris-martin commented 6 years ago

I've decided to go with this:

maintainers = maintainers.[ "ehmry" "changlinli" "ciil" ];