Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:01:56+00:00 2026-05-25T22:01:56+00:00

The May 24, 2011 Scala Language Specification has a typo in section 6.12.3 as

  • 0

The May 24, 2011 Scala Language Specification has a typo in section 6.12.3 as discovered here. This was acknowledged on the mailing list.

What is the actual precedence for the infix operators?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:01:57+00:00Added an answer on May 25, 2026 at 10:01 pm

    I thought it would be fun figuring it out by testing it, I wrote the following code to be executed in the REPL. Given:

    val ops = List(
      "letter", "|", "^", 
      "&", "<", ">", "!", 
      "+", "-", "*", "/", "%", "?", 
      "=?", // add ? to prevent assignment
      ":?"  // add ? to prevent right-association
    )
    

    First generate an intermediate scala file that use and test the operators.

    import java.io._
    
    // generate a class with all ops operators defined
    // where operator combines in a way we can figure out the precedence
    val methods = ops.map("""def %s(o: Op) = Op("["+o.v+v+"]")""".format(_))
    val body = methods.mkString("\n")
    val out = new PrintWriter(new FileWriter("Op.scala"))
    out.println("case class Op(v: String) {\n%s\n}".format(body))
    
    // generate tests for all combinations and store in comps
    // Op(".") op1 Op(".") op2 Op(".") v returns "[[..].]" when op2 > op1
    // returns "[.[..]]" when op1 <= op2
    def test(op1: String, op2:String) = {
      """("%s","%s") -> (Op(".") %s Op(".") %s Op(".")).v.startsWith("[[")""".
        format(op1, op2, op1, op2)
    }
    val tests = for (op1 <- ops; op2 <- ops) yield { test(op1, op2) }
    out.println("val comps = Map[(String, String), Boolean](%s)".format(
      tests.mkString(",\n")))
    out.close
    

    Then Load Op class, run tests and load comps

    :load Op.scala
    
    // order operators based on tests
    val order = ops.sortWith((x,y) => comps(x -> y))
    
    // if op1 or op2 don't have higher precedence, they have the same precedence
    def samePrecedence(op1: String, op2: String) = 
      !comps(op1 -> op2) && !comps(op2 -> op1)
    
    def printPrecedenceGroups(list: List[String]): Unit = {
      if (list != Nil) {
        val (same, rest) = list.span(op => samePrecedence(op, list.head))
        println(same.mkString(" "))
        printPrecedenceGroups(rest)
      }
    }
    
    printPrecedenceGroups(order)
    

    This prints:

    letter
    |
    ^
    &
    ! =?
    < >
    :?
    + -
    * / %
    ?
    

    So the main difference with the spec is < > needs to be switched with = !.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

DateTime date = DateTime.Parse(2011-05-04 14:33:41); //4 may 2011 How do I convert this date
I am sending validly formatted HTTP response Expired headers (e.g. Wed, 04 May 2011
I have a table Table1 with a column Column1 like this: Column1 Dec-2010 Dec-2011
I have the below xml, Updated added symptoms <EBF> <EBFINFO> <EBFNUM>EBF262323</EBFNUM> <RELEASEDATETIME>May 06, 2011</RELEASEDATETIME>
How i could convert datetime 5/8/2011 12:00:00 AM (m/d/yyyy) to dd-MMM-yyyy like 08-May-2011 in
this question may have been asked many times, but could not find any suitable
I have a date picker for text field which puts in format of 5-MAY-2011
DateTime? billDateFrom = string.IsNullOrWhiteSpace(txtBillDateFrom.Text) ? null : (DateTime?)DateTime.Parse(txtBillDateFrom.Text); txtBillDateFrom.Text equals 05/26/2011. (26 may 2011)
Update 2011-12-28: Here's a blog post with a less vague description of the problem
This shouldn't be that hard that one may think, if I got it right.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.