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

  • Home
  • SEARCH
  • 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 6130433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:29+00:00 2026-05-23T16:51:29+00:00

Possible Duplicate: Tuple parameter declaration and assignment oddity In python I can do >>>

  • 0

Possible Duplicate:
Tuple parameter declaration and assignment oddity

In python I can do

>>> (a,b) = (1,2)
>>> (b,a) = (a,b)
>>> (a,b)
(2, 1)

But in scala:

Welcome to Scala version 2.8.1.final (OpenJDK Server VM, Java 1.6.0_20).
Type in expressions to have them evaluated.
Type :help for more information.

scala> var (a,b) = (1,2)
a: Int = 1
b: Int = 2

scala> (a,b)=(b,a)
<console>:1: error: ';' expected but '=' found.
       (a,b)=(b,a)
            ^

So while I can initialise vars as a tuple, I cannot assign them as a tuple. Any way to get around this, other than using a tmp var?

  • 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-23T16:51:29+00:00Added an answer on May 23, 2026 at 4:51 pm

    Unfortunately, there’s no simple way. The expression (a,b) constructs an immutable object of type Tuple[Int, Int]. Within this tuple, the identities of a and b as mutable vars are lost. Two previous questions may give a little more information:

    Tuple parameter declaration and assignment oddity

    Is it possible to have tuple assignment to variables in Scala?

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

Sidebar

Related Questions

Possible Duplicate: Tuple parameter declaration and assignment oddity In Scala, one can do multiple-variable
Possible Duplicate: Can we change the device time using an application? is that possible
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: Direct casting vs 'as' operator? Anyone can give a comparison between as
Possible Duplicate: CompilerServices.Operators equivalent on C# I was looking for Microsoft.CSharp.CompilerServices.Operators but couldn't find
Possible Duplicate: Can we run Java applictions on iPhone? Does IPhone4 supports Java? Can
Possible Duplicate: Transform tuple to dict How do I change a list of tuples
Possible Duplicate: Python urllib2 Progress Hook I have a script which uploads a file
Possible Duplicate: Can you define “literal” tables in SQL? Occasionally I find myself in
Possible Duplicate: Detect if an outgoing call has been answered How can I know

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.