Skip to content

QuoteNodes and Symbol literals #20

@fcard

Description

@fcard

Currently symbol literals in patterns don't really count as literals, but rather as a binding inside a QuoteNode, which could be a gotcha. e.g.

@macromethod m(:sym1) 0
@macromethod m(:sym2) 1

# Intended: Different methods for specific symbols.
@m(:sym1) == 0
@m(:sym2) == 1

# Actual: Both are the same method, so second overwrites first.
@m(:sym1) == 1
@m(:sym2) == 1

# Since
@macromethod mtruth(:x) [x]
@mtruth(:a) == [:a]

# You have to:
@macromethod m1(:L{:sym1}) 0
@macromethod m1(:L{:sym2}) 1

# or:
@macromethod m2(:E{:(:sym1)}) 0
@macromethod m2(:E{:(:sym2)}) 1

@m1(:sym1) == @m2(:sym1) == 0
@m1(:sym2) == @m2(:sym2) == 1

This behaviour may be useful for capturing whole nested expressions (@mtruth(:(x+y)) == [:(x+y)]) and changing it would make it inconsistent with capturing with nested expressions (@letds :(x+y) = :(:(1+2)) (x,y)), but I don't know if these cases are common enough to keep this. Hmm.... Oh well, at least if Julia's 12139 happens this won't be a problem anymore!

I am gonna keep this one around until I do an overall update for Julia 0.5, but if you're a lost soul that somehow came across this and has opinions about it, feel free to share them!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy