Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I think it's a shame Python didn't follow this design

I mean python's regex module was added in 1997 and hasn't fundamentally changed since. I don't think that concept was super common in '97.



I meant the design of f-strings, not of regexes. I must've written my comment very badly since almost all of these replies seem to take this misinterpretation.

(E did have this concept back in '97, iirc, though yeah I wasn't expecting Guido to have run into it then, that wasn't when I meant.)


I think the issue is that f-strings have nothing specifically to do with regex specifically, or parsing generally. They're a formatting API. So the complaint that you wish the formatting API made regexes a first class citizen is odd and suggests a misunderstanding somewhere.


Evidently I was still unclear:

An f-string fills holes in a format string to build a string.

A template literal parses a template with holes to produce any datatype you like, filling it with arguments of any appropriate type.

This does for Javascript what f-strings do for Python (with similar syntax and simplicity), but also more. Besides the greater expressiveness, it can catch bugs, in the same way that Lisp macros are safer than C macros. It's not hardwiring regexes, it's not hardwiring any datatype: it calls a function that you name in the tag, which you can define to do whatever parsing and filling is proper.

Lisp's quasiquotation is similar in spirit though different in appearance.

This is my last try to explain here. I guess this thread shows that tagged template strings are much less well known on HN than I thought. (Yes it also shows me I was unusually bad at communicating.)

> the complaint that you wish the formatting API made regexes a first class citizen is odd

That was not what I was trying to say. The template literal mechanism knows nothing about regexes. Regexes are just one particular type and one particular syntax.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: