How to println(something) but doesn't print anything to the console

Showing 1-17 of 17 messages
How to println(something) but doesn't print anything to the console Minh Triet Pham Tran 9/21/12 1:04 AM
I have a requirement to println(something) but doesn't println anything and no new line printed, how can I do that in Scala?
What should 'something' above in println be so that it satisfies my requirement?
Re: [scala-user] How to println(something) but doesn't print anything to the console Dennis Haupt 9/21/12 1:09 AM
huh?

-------- Original-Nachricht --------
> Datum: Fri, 21 Sep 2012 01:04:46 -0700 (PDT)
> Von: Minh Triet Pham Tran <minhtrie...@gmail.com>
> An: scala...@googlegroups.com
> Betreff: [scala-user] How to println(something) but doesn\'t print anything to the console
Re: [scala-user] How to println(something) but doesn't print anything to the console Torsten Uhlmann 9/21/12 1:17 AM
println in Scala is like the System.out.println in Java, it requires a String as input.

println("something") would print something (the string 'something') to the console. You could also do:

println("My phone number: "+phoneNumber) which does call toString on "phoneNumber" if it's not a String already, then concatenates the two and finally passes one String into println.

Torsten.

-- 
AGYNAMIX(R). Passionate Software.
Inh. Torsten Uhlmann | Buchenweg 5 | 09380 Thalheim
Phone:       +49 3721 273445
Fax:             +49 3721 273446
Mobile:       +49 151 12412427
Web:           http://www.agynamix.de

Am 21.09.2012 um 10:04 schrieb Minh Triet Pham Tran <minhtrie...@gmail.com>:

I have a requirement to println(something) but doesn't println anything and no new line printed, how can I do that in Scala?
What should 'something' above in println be so that it satisfies my requirement?

Re: How to println(something) but doesn't print anything to the console pagoda_5b 9/21/12 1:19 AM
println(throw new Exception)

does it fulfill the requirements?


On Friday, September 21, 2012 10:04:46 AM UTC+2, Minh Triet Pham Tran wrote:
I have a requirement to println(something) but doesn't println anything and no new line printed, how can I do that in Scala?
What should 'something' above in println be so that it satisfies my requirement?
Re: How to println(something) but doesn't print anything to the console pagoda_5b 9/21/12 1:20 AM
also

println(System.exit(0))
Re: How to println(something) but doesn't print anything to the console Minh Triet Pham Tran 9/21/12 4:57 AM
I'm afraid not, it throws out an exception and the program could not continue :( .
Re: How to println(something) but doesn't print anything to the console pagoda_5b 9/21/12 5:28 AM
Sorry to be fussy, but you didn't specify as a requirement that the program flow couldn't be interrupted.
Just to make things clearer: is it a theoretical exercise or whatever?

Bye,
Ivano
Re: [scala-user] Re: How to println(something) but doesn't print anything to the console Dennis Haupt 9/21/12 5:39 AM
i assume he just wants no linebreak and is using bad english so we don't get it

-------- Original-Nachricht --------
> Datum: Fri, 21 Sep 2012 05:28:07 -0700 (PDT)
> Von: pagoda_5b <ivano....@gmail.com>
> An: scala...@googlegroups.com
> Betreff: [scala-user] Re: How to println(something) but doesn\'t print anything to the console
Re: How to println(something) but doesn't print anything to the console pagoda_5b 9/21/12 5:40 AM
with continuation plugin enabled (-p:continuations:enable)


import scala.util.continuations._

def f() = {
    reset {
        println( shift { k: (Unit => Unit) => } )
    }
}


ivano


On Friday, September 21, 2012 10:04:46 AM UTC+2, Minh Triet Pham Tran wrote:
I have a requirement to println(something) but doesn't println anything and no new line printed, how can I do that in Scala?
What should 'something' above in println be so that it satisfies my requirement?
Re: [scala-user] Re: How to println(something) but doesn't print anything to the console Dennis Haupt 9/21/12 5:51 AM
maybe he just wants to disable logging?

-------- Original-Nachricht --------
> Datum: Fri, 21 Sep 2012 05:40:28 -0700 (PDT)
> Von: pagoda_5b <ivano....@gmail.com>
> An: scala...@googlegroups.com
> Betreff: [scala-user] Re: How to println(something) but doesn\'t print anything to the console

Re: How to println(something) but doesn't print anything to the console pagoda_5b 9/21/12 6:00 AM
Is it something like this acceptable?

case object PrintOff

def printlnSwitch(x: Any): Unit = if (x == PrintOff) () else println(x)



scala> switchPrintln(PrintOff)

scala> switchPrintln("Coool")
Coool

On Friday, September 21, 2012 10:04:46 AM UTC+2, Minh Triet Pham Tran wrote:
I have a requirement to println(something) but doesn't println anything and no new line printed, how can I do that in Scala?
What should 'something' above in println be so that it satisfies my requirement?
Re: How to println(something) but doesn't print anything to the console Minh Triet Pham Tran 9/21/12 6:11 AM
I'm having a language lexer assignment (lexer.scala) and I need to regconized and ignored the comments from the language but the main.scala forced to use println the regconized tokens, this is fixed by my teacher and the test case result is fixed by him too :( .
Re: [scala-user] Re: How to println(something) but doesn't print anything to the console som-snytt 9/21/12 6:23 AM
This is not as stylish as other suggestions:

val out = new java.io.ByteArrayOutputStream
Console.setOut(out)
println("Quiet.")
Re: [scala-user] Re: How to println(something) but doesn't print anything to the console Repain Alex 9/21/12 7:01 AM
You could redefine println in your project's package :

def println(s: String) = if (s startsWith "//") scala.Predef.println("") else scala.Predef.println(s)

It's a hack, but your teacher constraints are really weird, so ...

scala> def println(s: String) = if (s startsWith "//") scala.Predef.println("") else scala.Predef.println(s)
println: (s: String)Unit
scala> println("yo!")
yo!
scala> println("//yo!")




2012/9/21 Som Snytt <som....@gmail.com>

Re: [scala-user] Re: How to println(something) but doesn't print anything to the console Dennis Haupt 9/21/12 8:05 AM
may i talk to your teacher? i want to ask what this is all about. it really sounds like he meant something completely different than what all the guys here think it means

-------- Original-Nachricht --------
> Datum: Fri, 21 Sep 2012 16:01:14 +0200
> Von: Alex Repain <alex....@gmail.com>
> An: Som Snytt <som....@gmail.com>
> CC: Minh Triet Pham Tran <minhtrie...@gmail.com>, scala...@googlegroups.com
> Betreff: Re: [scala-user] Re: How to println(something) but doesn\'t print anything to the console
Re: [scala-user] How to println(something) but doesn't print anything to the console Seth Tisue 9/21/12 8:35 AM
If you post the same question to a mailing list and to Stack Overflow,
it's polite to link the two to each other so the community doesn't
waste effort writing redundant answer in two different places.

http://stackoverflow.com/questions/12526622/how-to-printlnsomething-but-doesnt-print-anything-to-the-console

--
Seth Tisue | Northwestern University | http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/
Re: [scala-user] Re: How to println(something) but doesn't print anything to the console Florian Hars 9/22/12 1:41 PM
Am 21.09.2012 15:11, schrieb Minh Triet Pham Tran:
> I'm having a language lexer assignment (lexer.scala) and I need to
> regconized and ignored the comments from the language but the main.scala
> forced to use println the regconized tokens, this is fixed by my teacher

Then write your lexer in a way that it ignores the comments. That seems
to be the real assignment, not to try to subvert println.

But that still looks slightly funny, the usual approach is to generate
lexer tokens for comments and deal with them in the parser.

- Florian.