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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:00:20+00:00 2026-05-26T04:00:20+00:00

scala> val input = readLine(hello %s%n, world) hello WrappedArray(world) input: String = scala> val

  • 0
scala> val input = readLine("hello %s%n", "world")
hello WrappedArray(world)
input: String = ""

scala> val input = Console.readLine("hello %s%n", "world")
hello world
input: String = ""

What’s the reason for the difference here? (I tried it compiled as well, so it’s not a REPL thing.)

Scala version 2.9.0-1

  • 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-26T04:00:21+00:00Added an answer on May 26, 2026 at 4:00 am

    It seems like a bug in Predef:

    def readLine(text: String, args: Any*) = Console.readLine(text, args)
    

    When I think it should be:

    def readLine(text: String, args: Any*) = Console.readLine(text, args: _*)
    

    The first version you use is calling Prefef.readLine. Because of the missing _* type ascription, the function is called with args as the single first argument of the repeated argument args of Console.readLine.

    In the uncurry compilation phase, this single argument is wrapped into a WrappedArray so that it it can be treated as a Seq[Any]. The WrappedArray is then converted using the toString method and this is what is used for %s in "hello %s%n". I think that is what happens.

    In the second version args is treated from the start as a Seq[Any] and no conversion happens.

    The whole thing is a bit funny, because in general the compiler does not let you do this:

    scala> def f(s: Int*) = s foreach println
    f: (s: Int*)Unit
    
    scala> def g(s: Int*) = f(s)
    <console>:8: error: type mismatch;
     found   : Int*
     required: Int
           def g(s: Int*) = f(s)
    

    With Any, you get past the typer phase.

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

Sidebar

Related Questions

In scala I can write: val pf: PartialFunction[String, Unit] = {case s => println(s)}
In Scala REPL: val input = <outerTag xmlns=http://xyz> <innerTag> </innerTag> </outerTag> input\\@innerTag => <innerTag
Suppose I have import scala.collection.immutable.TreeMap val tree = new TreeMap[String, List[String]] Now after above
Consider this simple Scala class: class A(val d: Int) Is there a difference in
I have two packrat parsers in scala: val symbols : PackratParser[String] = { |
So I have a Map in Scala like this: val m = Map[String, String](
Given the following Scala List: val l = List(List(a1, b1, c1), List(a2, b2, c2),
scala> val l = List((1,2), (2,3)) l: List[(Int, Int)] = List((1,2), (2,3)) I can
scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala>
I am generating the scala AST using the following code: val setting = new

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.