!9IQChSjwSHXPPWTa:lix.systems

Lix

1102 Members
Lix user channel. Feel free to discuss on-topic issues here and give each other help. For matrix.to links to the rest of the Lix channels, see: https://wiki.lix.systems/books/lix-organisation/page/matrix-rooms294 Servers

Load older messages


SenderMessageTime
15 Oct 2025
@charles:computer.surgeryCharles

Half baked idea for a new pair of builtins: builtins.restrictNamespace and builtins.restrictedNamespace (feel free to suggest a different color for the bikeshed). Here's the basic idea:

Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + 1);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in 6. Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + foo);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in an eval error about foo being inaccessible in a restricted namespace. Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + foo);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

hits the builtins.throw case.

Not sure how this would/should interact with builtins.scopedImport.

Motivation for wanting this is that it allows you to restrict the names available to some expression without forcing that expression to be moved into a different file. Good idea, bad idea, thoughts?

01:02:23
@charles:computer.surgeryCharles *

Half baked idea for a new pair of builtins: builtins.restrictNamespace and builtins.restrictedNamespace (feel free to suggest a different color for the bikeshed). Here's the basic idea:

Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + 1);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in 6. Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + foo);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in an eval error about foo being inaccessible in a restricted namespace. Evaluating this:

let
  foo = 4;
  bar = x: x + foo;
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

hits the builtins.throw case.

Not sure how this would/should interact with builtins.scopedImport.

Motivation for wanting this is that it allows you to restrict the names available to some expression without forcing that expression to be moved into a different file. Good idea, bad idea, thoughts?

01:03:10
@charles:computer.surgeryCharles *

Half baked idea for a new pair of builtins: builtins.restrictNamespace and builtins.restrictedNamespace (feel free to suggest a different color for the bikeshed). Here's the basic idea:

Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + 1);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in 6. Evaluating this:

let
  foo = 4;
  bar = builtins.restrictNamespace (x: x + foo);
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

results in an eval error about foo being inaccessible in a restricted namespace. Evaluating this:

let
  foo = 4;
  bar = x: x + foo;
in

if !(builtins.restrictedNamespace bar)
  then builtins.throw "bar's namespace is required to be restricted"
  else bar 5

hits the builtins.throw case.

Not sure how this would/should interact with builtins.scopedImport.

Motivation for wanting this is that it allows you to restrict the names available to some expression (in this case a function, but ideally this'd work for any expression) without forcing that expression to be moved into a different file. Good idea, bad idea, thoughts?

01:03:50
@raitobezarius:matrix.orgraitobezariusstatic analysis doesn't work anymore :(01:14:43
@raitobezarius:matrix.orgraitobezarius it's a with-style construct 01:14:48
@raitobezarius:matrix.orgraitobezariusit could even be said this is anti with01:14:54
@charles:computer.surgeryCharlesyeah basically lol01:15:20
@raitobezarius:matrix.orgraitobezariuswhy do you need so hard to restrict names?01:15:44
@charles:computer.surgeryCharles hm why not? to me this seems sort of similar to mod in rust except you don't get use 01:15:46
@raitobezarius:matrix.orgraitobezariusstatic analyzers needs to keep track if they have entered into a restricted scope01:16:11
@raitobezarius:matrix.orgraitobezariusso you cannot just go brrrrrrr and look at every scopes and collect variables01:16:31
@charles:computer.surgeryCharlesyeah, that's true01:16:39
@raitobezarius:matrix.orgraitobezariusyour analyzer for call expressions needs to keep track of entering restrictions and exiting restrictions01:16:48
@charles:computer.surgeryCharlesdoing this is a builtin is probably Wrong and it should really be some kind of language construct01:16:51
@raitobezarius:matrix.orgraitobezariusalso01:16:57
@raitobezarius:matrix.orgraitobezariusimagine01:16:58
@raitobezarius:matrix.orgraitobezarius head (map (_: builtins.restrictNamespace) [ foo ]) 01:17:12
@raitobezarius:matrix.orgraitobezarius * head (map builtins.restrictNamespace [ foo ]) 01:17:28
@charles:computer.surgeryCharlesyikes01:17:29
@charles:computer.surgeryCharlessee also lol01:17:41
@raitobezarius:matrix.orgraitobezariusthis is what I mean by static analyzers are completely fucked in front of this01:17:43
@raitobezarius:matrix.orgraitobezarius yeah, feels like to me you want { } 01:17:54
@raitobezarius:matrix.orgraitobezarius
let

   {
      fucking around
    }
    x = 3;
in
 { ... }
01:18:11
@raitobezarius:matrix.orgraitobezariusbut basically you can always scope things01:18:40
@raitobezarius:matrix.orgraitobezariuswith attrsets?01:18:43
@raitobezarius:matrix.orgraitobezarius
let
  scope = _: { foo = 4 };
  bar = (x: x + foo);
in bar 5
01:19:53
@raitobezarius:matrix.orgraitobezariuslike i have trouble finding cases where you cannot structure your code that way01:20:26
@raitobezarius:matrix.orgraitobezariusif your let bindings are the most locals to what you need01:20:33
@raitobezarius:matrix.orgraitobezariusthere's no global pollution01:20:36
@raitobezarius:matrix.orgraitobezariusyou can always thunk things in function scopes to avoid the problem01:20:44

Show newer messages


Back to Room ListRoom Version: 10