Skip to content

Commit

Permalink
Add NEWS, doc for string and command macros
Browse files Browse the repository at this point in the history
  • Loading branch information
TotalVerb committed Sep 29, 2016
1 parent c6ac5bb commit 91ec697
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ Language changes
This can be changed back to the original color by setting the environment variable `JULIA_INFO_COLOR` to `"blue"`.
One way of doing this is by adding `ENV["JULIA_INFO_COLOR"] = :blue` to the `.juliarc.jl` file.
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).
* Multiline and singleline command macros have been added. A command macro is
like a string macro, but the syntax uses backquotes (<code>\`</code>)
instead of double quotes, and the resulting macro called is suffixed with
`_cmd`. For instance, the syntax <code>q\`xyz\`</code> is equivalent to
`@q_cmd "xyz"`.
* String and command macros can now be qualified with their module. For
instance, `Base.r"x"` is now parsed as `Base.@r_str "x"`. Previously, this
syntax parsed as an implicit multiplication.

Breaking changes
----------------
Expand Down
16 changes: 15 additions & 1 deletion doc/manual/metaprogramming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,27 @@ majority of use cases, however, regular expressions are not constructed
based on run-time data. In this majority of cases, the ability to write
regular expressions as compile-time values is invaluable.

Like non-standard string literals, non-standard command literals exist using a
prefixed variant of the command literal syntax. The command literal
``custom`literal``` is parsed as ``@custom_cmd "literal"``. Julia itself does
not contain any non-standard command literals, but packages can make use of
this syntax. Aside from the different syntax and the ``_cmd`` suffix instead of
the ``_str`` suffix, non-standard command literals behave exactly like
non-standard string literals.

In the event that two modules provide non-standard string or command literals
with the same name, it is possible to qualify the string or command literal
with a module name. For instance, if both ``Foo`` and ``Bar`` provide
non-standard string literal ``@x_str``, then one can write ``Foo.x"literal"``
or ``Bar.x"literal"`` to disambiguate between the two.

The mechanism for user-defined string literals is deeply, profoundly
powerful. Not only are Julia's non-standard literals implemented using
it, but also the command literal syntax (```echo "Hello, $person"```)
is implemented with the following innocuous-looking macro::

macro cmd(str)
:(cmd_gen($shell_parse(str)))
:(cmd_gen($(shell_parse(str)[1])))
end

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

0 comments on commit 91ec697

Please sign in to comment.