←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.206s | source
Show context
runekaagaard ◴[] No.43749575[source]
It feels a bit like "cheating" that new x-string features are built-in only. It would be cool to be able to do:

    from foo import bar
    bar"zoop"
replies(7): >>43749594 #>>43749601 #>>43749709 #>>43750748 #>>43751130 #>>43752217 #>>43757083 #
1. cb321 ◴[] No.43750748[source]
This is exactly how Nim is. The f-string like equivalent uses a macro called "fmt" which has a short alias "&". So you can say:

    import std/strformat
    let world = "planet"
    echo &"hello {world}"
The regular expression module does a similar thing with a `re"regular expression"` syntax or std/pegs with peg"parsing expression grammar" and so on. There are probably numerous other examples.

In general, with user-defined operators and templates and macros, Nim has all kinds of Lisp-like facilities to extend the language, but with a more static focus which helps for both correctness and performance.