| 15 Nov 2025 |
K900 | nix-repl> builtins.match "a" "a"
[ ]
nix-repl> builtins.match "(a)" "a"
[ "a" ]
nix-repl> builtins.match "a" "b"
null
| 18:40:37 |
522 it/its ⛯ΘΔ | ah funny | 18:40:53 |
K900 | Not the word I'd use | 18:41:01 |
Katie | I was thinking you could pass /foo/ as the first argument to builtins.match, but I suppose if we continue looking at JavaScript, you could do builtins.match /foo/.source | 18:41:39 |
antifuchs | “Truthy” | 18:41:42 |
aloisw | More that it simply doesn't really have regexes at all and just offers some builtins that parse the regex at runtime. | 18:41:42 |
Katie | it could "compile" to an attrset | 18:41:50 |
K900 | But like, how would it be different from "foo" then | 18:42:09 |
antifuchs | Gotta love using a language made when truthiness and falsiness was still considered socially ok | 18:42:11 |
aloisw | What's so cursed about this? | 18:42:15 |
K900 | It returns a conventionally falsy value for both match and no match | 18:42:46 |
Katie | and have /foo/.match be essentially syntax sugar for builtins.match /foo/.source | 18:42:37 |
K900 | FOr one | 18:42:48 |
K900 | * For one | 18:42:50 |
aloisw | In what sense is the empty list "conventionally falsy"? | 18:43:22 |
K900 | In the any other language but Nix sense | 18:43:56 |
Katie | empty list is truthy in JS | 18:44:50 |
aloisw | That's straight up not going to work because /foo/.match is a path literal. And yes, you could make it work with a space, but at the cost of introducing another footgun if the user forgets that space. | 18:45:01 |
Katie | which I think why no match returns null | 18:45:05 |
K900 | I said language | 18:45:30 |
K900 | Not eldritch abomination | 18:45:30 |
Katie | MMMM... got it, yes, that is a problem | 18:45:37 |
Katie | maybe (/foo/).match | 18:45:50 |
Katie | or maybe a different bookend token | 18:46:10 |
Katie | |foo| | 18:46:18 |
antifuchs | Empty list is falsy in the originator of the meme, lisp (fixed in scheme though); still not sure I love it there | 18:46:21 |
aloisw | It's quite reasonable given how builtins.match semantics work. Unmatched capture groups give null, matched capture groups give the list of its submatches. | 18:46:31 |
aloisw | Same problem of being a footgun if the user leaves off the seemingly redundant parenthesis. | 18:47:00 |
Katie | Yeah, I don't love the parentheses idea | 18:47:24 |
aloisw | Like I don't see the point of syntactic sugar that makes an uncommon operation look slightly shorter at the cost of adding massive footguns. | 18:47:29 |