[ANN] KeywordStrings.jl --- A fun and convenient string macro for interpolations

Hi all, I have written my first package and pushed it here: GitHub - adienes/KeywordStrings.jl: Flexible and convenient string formatting for the Julia language. It is not yet registered but I thought I’d share.

It is very short: only 150 lines in src and the dependencies are only Base Julia. It exports the string macro kw" ... " which has some nice properties, most notably that undefined variables can be interpreted at a later time, e.g.

julia> struct User
           name
           value
       end

julia> me = User("Andy", 14)
User("Andy", 14)

julia> s = kw"Hello, $name ! Your value is $value"; # a KeywordString object

julia> s % me # a regular Julia String
"Hello, Andy! Your value is 14"

julia> s % (; name="Bob", value=0) # format with any obj with a `get` method
"Hello, Bob! Your value is 0"

For more examples check out the README! I mostly did this as a learning experience so any critiques or suggestions welcome.

5 Likes

See also