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 8390299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:56:47+00:00 2026-06-09T18:56:47+00:00

I am a beginning practitioner in Scala and I saw a few different syntax

  • 0

I am a beginning practitioner in Scala and I saw a few different syntax for calling a method. Some are nice, as ignoring parenthesis for a parameterless method, or ignoring the dot as in

1 to 10

but some really puzzle me. for instance:

breakable { ... }

this is simply a method call right? Can I also do that for more than one parameter or a parameter which is not a parameterless function?

Thanks

  • 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-06-09T18:56:49+00:00Added an answer on June 9, 2026 at 6:56 pm

    There are two standard ways of calling methods:

    obj.method(params)   // dot notation
    obj method (params)  // operator notation
    

    The above can be modified in the following ways:

    1. If params is a single parameter, you can replace () with {}.
    2. If params is a single parameter and you are using operator notation, you can drop the parenthesis.
    3. If method doesn’t take parameters, you can drop (params) (that is, drop the empty ()).
    4. If method ends with :, then it actually binds to the right in operator notation. That is, (params) method_: obj is equivalent to obj.method_:(params).
    5. Either way, spaces are optional as long as identifiers can be told apart. So one can add spaces to the dot notation, like obj . method ( params ) or write .method(params) on the next line — as often happens with call chaining –, as well as remove spaces from the operator notation, as in a+b.

    There’s also some stuff with tuple inference, but I try to avoid it, so I’m not sure of the exact rules.

    None of these will explain the example you are confused about, however. Before I explain it, however, I’d like to show some syntactic sugars that can also be used to call methods:

    obj(params) // equivalent to obj.apply(params)
    obj.x = y   // equivalent to obj.x_=(y), if obj.x also exists
    obj(x) = y  // equivalent to obj.update(x, y)
    obj op= y   // equivalent to obj = obj op y, if op is symbolic
    ~obj        // equivalent to obj.unary_~; also for !, + and -, but no other symbol
    

    Ok, now to the example you gave. One can import members of stable values. Java can do it for static methods with its static import, but Scala has a more general mechanism: importing from packages, objects or common instances is no different: it brings both type members and value members. Methods fall in the latter category.

    So, imagine you have val a = 2, and you do import a._. That will bring into scope all of Int methods, so you can call them directly. You can’t do +(2), because that would be interpreted as a call to unary_+, but you could call *(4), for example:

    scala> val a = 2
    a: Int = 2
    
    scala> import a._
    import a._
    
    scala> *(4)
    res16: Int = 8
    

    Now, here’s the rule. You can call

    method(params)
    

    If:

    1. method was imported into scope.
    2. You keep the parenthesis (even if there’s only one parameter)

    Note that there’s a precedence issue as well. If you write obj method(params), Scala will presume method belongs to obj, even if it was imported into scope.

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

Sidebar

Related Questions

Since beginning to use VB.NET some years ago I have become slowly familiar with
Im beginning in my journey of learning WPF. After a few days of coding
I'm beginning Haskell... I tried to write the following trivial function in two different
I'm just beginning with C++, so I'm looking some code to learn. I found
I'm beginning Scala. Am I correct understanding that I should define a class as
I'm just beginning this nice hashkell beginners tutorial: http://learnyouahaskell.com on this page on lists
Beginning in Scala and reading about Either I naturally comparing new concepts to something
I'm beginning a large scale javascript application with Marionette. A Marionette application has a
I am a beginning at nhibernate and I am trying to connect to a
I am beginning Facebook App development and am following the Recipe Box App Tutorial

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.