Skip to content

Commit 4456291

Browse files
committed
Add NEWS, doc for string and command macros
1 parent c6ac5bb commit 4456291

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

NEWS.md

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ Language changes
2424
This can be changed back to the original color by setting the environment variable `JULIA_INFO_COLOR` to `"blue"`.
2525
One way of doing this is by adding `ENV["JULIA_INFO_COLOR"] = :blue` to the `.juliarc.jl` file.
2626
For more information regarding customizing colors in the REPL, see this [manual section]( http://docs.julialang.org/en/latest/manual/interacting-with-julia/#customizing-colors).
27+
* Multiline and singleline command macros have been added. A command macro is
28+
like a string macro, but the syntax uses backquotes (<code>`</code>)
29+
instead of double quotes, and the resulting macro called is suffixed with
30+
`_cmd`. For instance, the syntax <code>q`xyz`</code> is equivalent to
31+
`@q_cmd "xyz"`.
32+
* String and command macros can now be qualified with their module. For
33+
instance, `Base.r"x"` is now parsed as `Base.@r_str "x"`. Previously, this
34+
syntax parsed as an implicit multiplication.
2735

2836
Breaking changes
2937
----------------

doc/manual/metaprogramming.rst

+15-1
Original file line numberDiff line numberDiff line change
@@ -864,13 +864,27 @@ majority of use cases, however, regular expressions are not constructed
864864
based on run-time data. In this majority of cases, the ability to write
865865
regular expressions as compile-time values is invaluable.
866866

867+
Like non-standard string literals, non-standard command literals exist using a
868+
prefixed variant of the command literal syntax. The command literal
869+
``custom`literal``` is parsed as ``@custom_cmd "literal"``. Julia itself does
870+
not contain any non-standard command literals, but packages can make use of
871+
this syntax. Aside from the different syntax and the ``_cmd`` suffix instead of
872+
the ``_str`` suffix, non-standard command literals behave exactly like
873+
non-standard string literals.
874+
875+
In the event that two modules provide non-standard string or command literals
876+
with the same name, it is possible to qualify the string or command literal
877+
with a module name. For instance, if both ``Foo`` and ``Bar`` provide
878+
non-standard string literal ``@x_str``, then one can write ``Foo.x"literal"``
879+
or ``Bar.x"literal"`` to disambiguate between the two.
880+
867881
The mechanism for user-defined string literals is deeply, profoundly
868882
powerful. Not only are Julia's non-standard literals implemented using
869883
it, but also the command literal syntax (```echo "Hello, $person"```)
870884
is implemented with the following innocuous-looking macro::
871885

872886
macro cmd(str)
873-
:(cmd_gen($shell_parse(str)))
887+
:(cmd_gen($(shell_parse(str)[1])))
874888
end
875889

876890
Of course, a large amount of complexity is hidden in the functions used

0 commit comments

Comments
 (0)