why 'n = 5 is the valid syntax?[Scala]










0














object solution extends App 
'n = 5



It gives the compile time Error: value update is not a member of object Symbol
println('n = 'n)
which is understandable. Because literals are the fixed values in the source code. But what is the reason the above syntax is valid?










share|improve this question





















  • If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
    – jwvh
    Nov 11 at 6:38










  • that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
    – Raman Mishra
    Nov 11 at 7:00















0














object solution extends App 
'n = 5



It gives the compile time Error: value update is not a member of object Symbol
println('n = 'n)
which is understandable. Because literals are the fixed values in the source code. But what is the reason the above syntax is valid?










share|improve this question





















  • If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
    – jwvh
    Nov 11 at 6:38










  • that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
    – Raman Mishra
    Nov 11 at 7:00













0












0








0







object solution extends App 
'n = 5



It gives the compile time Error: value update is not a member of object Symbol
println('n = 'n)
which is understandable. Because literals are the fixed values in the source code. But what is the reason the above syntax is valid?










share|improve this question













object solution extends App 
'n = 5



It gives the compile time Error: value update is not a member of object Symbol
println('n = 'n)
which is understandable. Because literals are the fixed values in the source code. But what is the reason the above syntax is valid?







scala syntax literals






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 6:00









Raman Mishra

1,0231416




1,0231416











  • If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
    – jwvh
    Nov 11 at 6:38










  • that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
    – Raman Mishra
    Nov 11 at 7:00
















  • If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
    – jwvh
    Nov 11 at 6:38










  • that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
    – Raman Mishra
    Nov 11 at 7:00















If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
– jwvh
Nov 11 at 6:38




If I try to compile it without the surrounding object, the IntelliJ IDE worksheet gives a different error: identifier expected but symbol literal found
– jwvh
Nov 11 at 6:38












that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
– Raman Mishra
Nov 11 at 7:00




that error is more specific then this one but don't you think this should not be valid syntax? @jwvh
– Raman Mishra
Nov 11 at 7:00












2 Answers
2






active

oldest

votes


















6














The reason the syntax is valid is … well … because it is:



implicit class UpdateableSymbol(val s: Symbol.type) extends AnyVal 
def update[A](s: String, v: A) = println(s"`Symbol.update` called with s = $s and v = $v")


'n = 5
// `Symbol.update` called with s = n and v = 5


As you can see, there is absolutely nothing wrong with the syntax, so why should it be invalid? The error message tells you what the problem is: you are calling Symbol.update but that doesn't exist. A missing method is not a syntactic error, it is a semantic error.






share|improve this answer




























    0














    Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
    Type in expressions for evaluation. Or try :help.

    scala> import reflect.runtime.universe._
    import reflect.runtime.universe._

    scala> reify('n)
    res0: reflect.runtime.universe.Expr[Symbol] = Expr[Symbol](Symbol.apply("n"))

    scala> val a = 'n
    a: Symbol = 'n

    scala> a = 5
    <console>:15: error: reassignment to val
    a = 5
    ^

    scala> a.update(5)
    <console>:16: error: value update is not a member of Symbol
    a.update(5)
    ^


    Desugar it, and you will find the answer.



    In Scala, operators are methods.



    For Symbol, see https://github.com/scala/scala/blob/2.13.x/src/library/scala/Symbol.scala






    share|improve this answer




















    • I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
      – Raman Mishra
      Nov 11 at 6:09











    • Operators are methods. I've updated my answer just now.
      – sadhen
      Nov 11 at 6:10










    • @RamanMishra It is a good idea that the compiler finds bugs in compile time.
      – sadhen
      Nov 11 at 6:17











    • Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
      – Raman Mishra
      Nov 11 at 6:25







    • 1




      The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
      – Jörg W Mittag
      Nov 11 at 9:22











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246257%2fwhy-n-5-is-the-valid-syntaxscala%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    The reason the syntax is valid is … well … because it is:



    implicit class UpdateableSymbol(val s: Symbol.type) extends AnyVal 
    def update[A](s: String, v: A) = println(s"`Symbol.update` called with s = $s and v = $v")


    'n = 5
    // `Symbol.update` called with s = n and v = 5


    As you can see, there is absolutely nothing wrong with the syntax, so why should it be invalid? The error message tells you what the problem is: you are calling Symbol.update but that doesn't exist. A missing method is not a syntactic error, it is a semantic error.






    share|improve this answer

























      6














      The reason the syntax is valid is … well … because it is:



      implicit class UpdateableSymbol(val s: Symbol.type) extends AnyVal 
      def update[A](s: String, v: A) = println(s"`Symbol.update` called with s = $s and v = $v")


      'n = 5
      // `Symbol.update` called with s = n and v = 5


      As you can see, there is absolutely nothing wrong with the syntax, so why should it be invalid? The error message tells you what the problem is: you are calling Symbol.update but that doesn't exist. A missing method is not a syntactic error, it is a semantic error.






      share|improve this answer























        6












        6








        6






        The reason the syntax is valid is … well … because it is:



        implicit class UpdateableSymbol(val s: Symbol.type) extends AnyVal 
        def update[A](s: String, v: A) = println(s"`Symbol.update` called with s = $s and v = $v")


        'n = 5
        // `Symbol.update` called with s = n and v = 5


        As you can see, there is absolutely nothing wrong with the syntax, so why should it be invalid? The error message tells you what the problem is: you are calling Symbol.update but that doesn't exist. A missing method is not a syntactic error, it is a semantic error.






        share|improve this answer












        The reason the syntax is valid is … well … because it is:



        implicit class UpdateableSymbol(val s: Symbol.type) extends AnyVal 
        def update[A](s: String, v: A) = println(s"`Symbol.update` called with s = $s and v = $v")


        'n = 5
        // `Symbol.update` called with s = n and v = 5


        As you can see, there is absolutely nothing wrong with the syntax, so why should it be invalid? The error message tells you what the problem is: you are calling Symbol.update but that doesn't exist. A missing method is not a syntactic error, it is a semantic error.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 9:31









        Jörg W Mittag

        288k62353546




        288k62353546























            0














            Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
            Type in expressions for evaluation. Or try :help.

            scala> import reflect.runtime.universe._
            import reflect.runtime.universe._

            scala> reify('n)
            res0: reflect.runtime.universe.Expr[Symbol] = Expr[Symbol](Symbol.apply("n"))

            scala> val a = 'n
            a: Symbol = 'n

            scala> a = 5
            <console>:15: error: reassignment to val
            a = 5
            ^

            scala> a.update(5)
            <console>:16: error: value update is not a member of Symbol
            a.update(5)
            ^


            Desugar it, and you will find the answer.



            In Scala, operators are methods.



            For Symbol, see https://github.com/scala/scala/blob/2.13.x/src/library/scala/Symbol.scala






            share|improve this answer




















            • I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
              – Raman Mishra
              Nov 11 at 6:09











            • Operators are methods. I've updated my answer just now.
              – sadhen
              Nov 11 at 6:10










            • @RamanMishra It is a good idea that the compiler finds bugs in compile time.
              – sadhen
              Nov 11 at 6:17











            • Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
              – Raman Mishra
              Nov 11 at 6:25







            • 1




              The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
              – Jörg W Mittag
              Nov 11 at 9:22
















            0














            Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
            Type in expressions for evaluation. Or try :help.

            scala> import reflect.runtime.universe._
            import reflect.runtime.universe._

            scala> reify('n)
            res0: reflect.runtime.universe.Expr[Symbol] = Expr[Symbol](Symbol.apply("n"))

            scala> val a = 'n
            a: Symbol = 'n

            scala> a = 5
            <console>:15: error: reassignment to val
            a = 5
            ^

            scala> a.update(5)
            <console>:16: error: value update is not a member of Symbol
            a.update(5)
            ^


            Desugar it, and you will find the answer.



            In Scala, operators are methods.



            For Symbol, see https://github.com/scala/scala/blob/2.13.x/src/library/scala/Symbol.scala






            share|improve this answer




















            • I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
              – Raman Mishra
              Nov 11 at 6:09











            • Operators are methods. I've updated my answer just now.
              – sadhen
              Nov 11 at 6:10










            • @RamanMishra It is a good idea that the compiler finds bugs in compile time.
              – sadhen
              Nov 11 at 6:17











            • Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
              – Raman Mishra
              Nov 11 at 6:25







            • 1




              The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
              – Jörg W Mittag
              Nov 11 at 9:22














            0












            0








            0






            Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
            Type in expressions for evaluation. Or try :help.

            scala> import reflect.runtime.universe._
            import reflect.runtime.universe._

            scala> reify('n)
            res0: reflect.runtime.universe.Expr[Symbol] = Expr[Symbol](Symbol.apply("n"))

            scala> val a = 'n
            a: Symbol = 'n

            scala> a = 5
            <console>:15: error: reassignment to val
            a = 5
            ^

            scala> a.update(5)
            <console>:16: error: value update is not a member of Symbol
            a.update(5)
            ^


            Desugar it, and you will find the answer.



            In Scala, operators are methods.



            For Symbol, see https://github.com/scala/scala/blob/2.13.x/src/library/scala/Symbol.scala






            share|improve this answer












            Welcome to Scala 2.12.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
            Type in expressions for evaluation. Or try :help.

            scala> import reflect.runtime.universe._
            import reflect.runtime.universe._

            scala> reify('n)
            res0: reflect.runtime.universe.Expr[Symbol] = Expr[Symbol](Symbol.apply("n"))

            scala> val a = 'n
            a: Symbol = 'n

            scala> a = 5
            <console>:15: error: reassignment to val
            a = 5
            ^

            scala> a.update(5)
            <console>:16: error: value update is not a member of Symbol
            a.update(5)
            ^


            Desugar it, and you will find the answer.



            In Scala, operators are methods.



            For Symbol, see https://github.com/scala/scala/blob/2.13.x/src/library/scala/Symbol.scala







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 11 at 6:05









            sadhen

            373312




            373312











            • I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
              – Raman Mishra
              Nov 11 at 6:09











            • Operators are methods. I've updated my answer just now.
              – sadhen
              Nov 11 at 6:10










            • @RamanMishra It is a good idea that the compiler finds bugs in compile time.
              – sadhen
              Nov 11 at 6:17











            • Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
              – Raman Mishra
              Nov 11 at 6:25







            • 1




              The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
              – Jörg W Mittag
              Nov 11 at 9:22

















            • I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
              – Raman Mishra
              Nov 11 at 6:09











            • Operators are methods. I've updated my answer just now.
              – sadhen
              Nov 11 at 6:10










            • @RamanMishra It is a good idea that the compiler finds bugs in compile time.
              – sadhen
              Nov 11 at 6:17











            • Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
              – Raman Mishra
              Nov 11 at 6:25







            • 1




              The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
              – Jörg W Mittag
              Nov 11 at 9:22
















            I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
            – Raman Mishra
            Nov 11 at 6:09





            I am not asking why it is giving me the compile time error, I am asking why this syntax is even valid? That i understand why it is giving me the error.
            – Raman Mishra
            Nov 11 at 6:09













            Operators are methods. I've updated my answer just now.
            – sadhen
            Nov 11 at 6:10




            Operators are methods. I've updated my answer just now.
            – sadhen
            Nov 11 at 6:10












            @RamanMishra It is a good idea that the compiler finds bugs in compile time.
            – sadhen
            Nov 11 at 6:17





            @RamanMishra It is a good idea that the compiler finds bugs in compile time.
            – sadhen
            Nov 11 at 6:17













            Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
            – Raman Mishra
            Nov 11 at 6:25





            Operators are methods ' (literal operator) calls the constructor of the Symbol class and creates a symbol, I am still not getting the point of reassigning value for a literal according to me that should not be the valid syntax.
            – Raman Mishra
            Nov 11 at 6:25





            1




            1




            The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
            – Jörg W Mittag
            Nov 11 at 9:22





            The reason this is valid syntax is that it is syntactic sugar for Symbol.update("n", 5), which is perfectly legal, valid, sensible syntax. The parser doesn't know, doesn't care, and shouldn't care whether a method call is legal or not, it should only care whether syntax is legal or not. Which it is.
            – Jörg W Mittag
            Nov 11 at 9:22


















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246257%2fwhy-n-5-is-the-valid-syntaxscala%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Darth Vader #20

            Ondo