Stream: cull-os

Topic: Bind expressions


view this post on Zulip RGBCube (Jul 23 2024 at 12:21):

I wanted to make fix and makeScope a built in operator in my language and this is the way I'm going to do it:

view this post on Zulip RGBCube (Jul 23 2024 at 12:21):

myident @ {
  foo = 132;
  bar = myident.foo;
}

view this post on Zulip RGBCube (Jul 23 2024 at 12:23):

This behaves the way you expect it to, just like fix. But you can also override the bind:

{
  needsBaz = self @ { bar = self.baz; };
} ==> {
  bazzed = setMeta { bind = (getMeta needsBaz).bind // { baz = 123; } needsBaz;
}

view this post on Zulip RGBCube (Jul 23 2024 at 12:24):

So you can leverage this to implement anything, basically. Also the bind in foo @ { pattern, here }: here will act specially and bind to the argument instead of the lambda itself. So it is basically identical to the Nix version here.

view this post on Zulip RGBCube (Jul 23 2024 at 12:27):

Further, when you do inputs @ { ... } ==> ..., the bind inputs will bind to the "use"d attribute set, and it will get overriden by the language itself when the "use"d attribute set gets overriden. So it will all work magically.


Last updated: Oct 18 2024 at 08:48 UTC