Quote-friendly way to express keyword Expr?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Quote-friendly way to express keyword Expr?

Penn Taylor
Is there a quote-friendly way to write the following keyword Expr, or must I directly manipulate raw Expr's to get this?

Expr(:kw, :foo, 2)


By "quote-friendly", I mean a form such as

:(stuff)

# or

quote
 stuff
end
Reply | Threaded
Open this post in threaded view
|

Re: Quote-friendly way to express keyword Expr?

Isaiah Norton
Not really clear what you are trying to do. These are inserted by the parser whenever keyword arguments are used in (function) call syntax. So:

julia> quote f(x= 10) end |> dump
Expr
  head: Symbol block
  args: Array{Any}((2,))
    1: Expr
      head: Symbol line
      args: Array{Any}((2,))
        1: Int64 1
        2: Symbol REPL[6]
      typ: Any
    2: Expr
      head: Symbol call
      args: Array{Any}((2,))
        1: Symbol f
        2: Expr
          head: Symbol kw
          args: Array{Any}((2,))
            1: Symbol x
            2: Int64 10
          typ: Any
      typ: Any
  typ: Any


On Sun, Oct 30, 2016 at 12:47 AM, Penn Taylor <[hidden email]> wrote:
Is there a quote-friendly way to write the following keyword Expr, or must I directly manipulate raw Expr's to get this?

Expr(:kw, :foo, 2)


By "quote-friendly", I mean a form such as

:(stuff)

# or

quote
 stuff
end

Reply | Threaded
Open this post in threaded view
|

Re: Quote-friendly way to express keyword Expr?

Penn Taylor
I'm manipulating keyword args inside a macro. Just wanted to check whether I was missing a syntax option for building those expressions.

On Sunday, October 30, 2016 at 8:55:32 PM UTC-5, Isaiah wrote:
Not really clear what you are trying to do. These are inserted by the parser whenever keyword arguments are used in (function) call syntax. So:

julia> quote f(x= 10) end |> dump
Expr
  head: Symbol block
  args: Array{Any}((2,))
    1: Expr
      head: Symbol line
      args: Array{Any}((2,))
        1: Int64 1
        2: Symbol REPL[6]
      typ: Any
    2: Expr
      head: Symbol call
      args: Array{Any}((2,))
        1: Symbol f
        2: Expr
          head: Symbol kw
          args: Array{Any}((2,))
            1: Symbol x
            2: Int64 10
          typ: Any
      typ: Any
  typ: Any


On Sun, Oct 30, 2016 at 12:47 AM, Penn Taylor <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="NhTZ2GcfAgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rpe...@...> wrote:
Is there a quote-friendly way to write the following keyword Expr, or must I directly manipulate raw Expr's to get this?

Expr(:kw, :foo, 2)


By "quote-friendly", I mean a form such as

:(stuff)

# or

quote
 stuff
end