For loops

39 views
Skip to first unread message

David Waller

unread,
Mar 13, 2012, 3:58:42 PM3/13/12
to scala...@googlegroups.com

Hello,

          A question from a beginner.

Why is it if I enter the following for statement into the scala interpreter it fails, (with pages of error messages),

while if I enter it via a file and run it through scala it works as I expect.

 

for (i <- 1 to 10) println(i)

 

Am I expecting too much from the interpreter?

 

 

Yours

David Waller

 

image001.gif

√iktor Ҡlang

unread,
Mar 14, 2012, 11:28:59 AM3/14/12
to David Waller, scala...@googlegroups.com
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> for (i <- 1 to 10) println(i)
1
2
3
4
5
6
7
8
9
10

scala> 
--
Viktor Klang

Akka Tech Lead
Typesafe - The software stack for applications that scale

Twitter: @viktorklang

image001.gif

AGYNAMIX Torsten Uhlmann

unread,
Mar 14, 2012, 11:29:52 AM3/14/12
to David Waller, scala...@googlegroups.com
Which Scala version do you use? Works for me:

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> for (i <- 1 to 10) println(i)
1
2
3
4
5
6
7
8
9
10


-- 
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

Alex Repain

unread,
Mar 14, 2012, 11:40:51 AM3/14/12
to AGYNAMIX Torsten Uhlmann, David Waller, scala...@googlegroups.com
it also works on Scala 2.8  (try it in simplyscala.com )

2012/3/14 AGYNAMIX Torsten Uhlmann <T.Uh...@agynamix.de>
Message has been deleted
Message has been deleted

Razvan Cojocaru

unread,
Mar 14, 2012, 3:48:07 PM3/14/12
to David Waller, scala...@googlegroups.com

It’s always helpful to include the interpreter’s error messages…

image002.gif

HamsterofDeath

unread,
Mar 14, 2012, 4:12:19 PM3/14/12
to scala...@googlegroups.com
MY EYES!!!11
Message has been deleted

David Waller

unread,
Mar 14, 2012, 2:43:39 PM3/14/12
to scala-user
I am very puzzled now. When I try the for loop I get the following:

Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server
VM, Java 1.
6.0_30).
Type in expressions to have them evaluated.
Type :help for more information.

scala> for (i<-1 to 10) println(i)
java.lang.Error: Unknown type: <notype>, <notype> [class
scala.tools.nsc.symtab.
Types$NoType$, class scala.tools.nsc.symtab.Types$NoType$] TypeRef?
false
at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:
34)
at scala.tools.nsc.backend.icode.TypeKinds
$class.toTypeKind(TypeKinds.sc
ala:390)
at
scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:25)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala
$tools$nsc$bac
kend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:736)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala
$tools$nsc$bac
kend$icode$GenICode$ICodePhase$$genStat(GenICode.scala:163)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$genStat$1.
apply(GenICode.scala:143)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$genStat$1.
apply(GenICode.scala:143)
at scala.collection.LinearSeqOptimized
$class.foldLeft(LinearSeqOptimized
.scala:111)
at scala.collection.immutable.List.foldLeft(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.genStat(GenICode.sc
ala:143)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala
$tools$nsc$bac
kend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1052)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
114)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$gen$1.appl
y(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$gen$1.appl
y(GenICode.scala:69)
at scala.collection.LinearSeqOptimized
$class.foreach(LinearSeqOptimized.
scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
69)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
136)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
88)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$gen$1.appl
y(GenICode.scala:69)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun
$gen$1.appl
y(GenICode.scala:69)
at scala.collection.LinearSeqOptimized
$class.foreach(LinearSeqOptimized.
scala:59)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
69)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
79)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.gen(GenICode.scala:
65)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.apply(GenICode.scal
a:61)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:
329)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run
$1.apply(Global.scala:
297)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run
$1.apply(Global.scala:
297)
at scala.collection.Iterator$class.foreach(Iterator.scala:660)
at scala.collection.mutable.ListBuffer$$anon
$1.foreach(ListBuffer.scala:
316)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:297)
at scala.tools.nsc.backend.icode.GenICode
$ICodePhase.run(GenICode.scala:
54)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
at scala.tools.nsc.interpreter.IMain
$ReadEvalPrint.compileAndSaveRun(IMa
in.scala:756)
at scala.tools.nsc.interpreter.IMain
$ReadEvalPrint.compile(IMain.scala:7
31)
at scala.tools.nsc.interpreter.IMain
$Request.compile(IMain.scala:873)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:
576)
at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:
543)
at scala.tools.nsc.interpreter.ILoop.reallyInterpret
$1(ILoop.scala:694)
at
scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:7
45)
at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:651)
at scala.tools.nsc.interpreter.ILoop.processLine$1(ILoop.scala:
542)
at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:550)
at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:822)
at scala.tools.nsc.MainGenericRunner.runTarget
$1(MainGenericRunner.scala
:67)
at
scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:80)

at scala.tools.nsc.MainGenericRunner
$.main(MainGenericRunner.scala:89)
at
scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

That entry seems to have slain the compiler. Shall I replay
your session? I can re-run each line except the last one.
[y/n]

Thanks for any advice. At least I now know the interpreter should
work.

On Mar 14, 3:40 pm, Alex Repain <alex.rep...@gmail.com> wrote:
> it also works on Scala 2.8  (try it in simplyscala.com )
>
> 2012/3/14 AGYNAMIX Torsten Uhlmann <T.Uhlm...@agynamix.de>
>
>
>
>
>
>
>
> > Which Scala version do you use? Works for me:
>
> > Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM,
> > Java 1.6.0_29).
> > Type in expressions to have them evaluated.
> > Type :help for more information.
>
> > scala> for (i <- 1 to 10) println(i)
> > 1
> > 2
> > 3
> > 4
> > 5
> > 6
> > 7
> > 8
> > 9
> > 10
>
> > --
> > 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 13.03.2012 um 20:58 schrieb David Waller:
>
> > Hello,****
> >           A question from a beginner.****
> > Why is it if I enter the following for statement into the scala
> > interpreter it fails, (with pages of error messages),****
> > while if I enter it via a file and run it through scala it works as I
> > expect.****
> > ** **
> > for (i <- 1 to 10) println(i)****
> > ** **
> > Am I expecting too much from the interpreter?****
> > ** **
> > ** **
> > *Yours*
> > *David Waller*
> > ** **
Reply all
Reply to author
Forward
0 new messages