-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix bug in nested quote and nested $ with splatting
In general, the outermost quote evaluates the innermost $: ``` julia> y = 2 2 julia> x = :y :y julia> :(:(f($$x))) :($(Expr(:quote, :(f($(Expr(:$, :y))))))) julia> eval(ans) :(f(2)) julia> :(:(f($x))) :($(Expr(:quote, :(f($(Expr(:$, :x))))))) julia> eval(ans) :(f(y)) ``` I triple-checked that this is how lisp works. For splatting, you generally want to put extra `$`s inside the `...`. E.g. `:(:(f($(($x)...))))` will cause the elements of `x` to be splatted after two evaluations: ``` julia> x = [:a,:b]; julia> :(:(f($(($x)...)))) :($(Expr(:quote, :(f($(Expr(:$, :(([:a,:b]...,))))))))) julia> eval(ans) :(f(a,b)) ``` This commit also fixes printing expressions with nested quote. The problem is that printing works by surrounding an expression with `:( )` and using `$` inside for Exprs that don't have surface syntax. However, if the expression contains quotes, those quotes "capture" any `$` expressions inside, preventing them from being evaluated by the printer's outermost `:( )`. For now I fixed this by reserving `quote`, `:( )`, and `$` only for the outermost expression, and using `Expr` for inner quotes. This works but leads to really ugly output. I believe the only way to improve it is to introduce surface syntax for Exprs with arbitrary head symbols, and for non-interpolating quote.
- Loading branch information
1 parent
fddc978
commit 9ef1720
Showing
4 changed files
with
32 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters