有没有人知道在实际尝试在REPL(或编译器)中编译之前如何获取(仅Scala部分)desgoared for for/comprehension表达式?
到目前为止,我唯一发现的是编译器"-print"标志,但它为您提供了完整的Scala转换...
寻找ldbb等效的gdb" directory "命令来添加搜索路径以查找缺少的源代码(或者xcode中可能的类似功能)?
提前致谢!
对Scala for-loop理解的NumericRange Int大小限制背后的原因是什么?是否有可能(没有太多头痛)扩展"for/Seqs"NumericRange以使用Long(或任何大于Int.MaxValue的东西)?
scala>for (i: Long <- 0L to 10000000000) {}
Run Code Online (Sandbox Code Playgroud)java.lang.IllegalArgumentException: 0 to 10000000000L by 1: "seqs cannot contain more than Int.MaxValue elements." at scala.collection.immutable.NumericRange$.count(NumericRange.scala:227) at scala.collection.immutable.NumericRange.numRangeElements(NumericRange.scala:53) at scala.collection.immutable.NumericRange.length(NumericRange.scala:55) at scala.collection.immutable.NumericRange.foreach(NumericRange.scala:73) at .<init>(<console>:19) at .<clinit>(<console>) at .<init>(<console>:11) at .<clinit>(<console>) at $print(<console>) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:704) at scala.tools.nsc.interpreter.IMain$Request$$anonfun$14.apply(IMain.scala:920) at scala.tools.nsc.interpreter.Line$$anonfun$1.apply$mcV$sp(Line.scala:43) at scala.tools.nsc.io.package$$anon$2.run(package.scala:25) at java.lang.Thread.run(Thread.java:680)
-
提前谢谢!
从应用程序开发团队的角度来看,处理整数溢出(如999999*999999(结果> Integer.MAX_VALUE))的常见做法是什么?
人们可以BigInt强制要求并禁止使用Integer,但这是一个好/坏的想法?
为什么"for/comprehension"表达式的数值类型的desugaring和隐式转换与(!)赋值操作相比不一致?
我相信对此有很多一般性的观点,但我无法找出当前行为的简明和合理的解释.[参考:"Scala for/comprehension的行为......" ]为了正确起见,下面的所有翻译都是使用scala编译器生成的("scalac -Xprint:typer -e")
例如,在隐式数字赋值转换期间,Destination类型占主导地位:
来源:var l:Long = 0
结果:val l: Long = 0L
来源:var l:Long = 0.toInt
结果:var l: Long = 0.toInt.toLong
在"for/comprehension"表达式的隐式转换期间,Source类型占主导地位:
来源:for (i:Long <- 0 to 1000000000L) { }
结果:0.to(1000000000L).foreach(((i: Long) => ()))
来源:for (i <- 0L to 1000000000L) { }
结果:scala.this.Predef.longWrapper(0L).to(1000000000L).foreach[Unit](((i: Long) => ()))
numerical types scala list-comprehension implicit-conversion
我试图理解Scala for-loop隐式盒子/拆箱"数字"类型的行为.为什么这两个首先失败但其余的失败?
1)失败:
scala> for (i:Long <- 0 to 10000000L) {}
<console>:19: error: type mismatch;<br>
found : Long(10000000L)
required: Int
for (i:Long <- 0 to 10000000L) {}
^
Run Code Online (Sandbox Code Playgroud)
scala> for (i <- 0 to 10000000L) {}
<console>:19: error: type mismatch;
found : Long(10000000L)
required: Int
for (i <- 0 to 10000000L) {}
^
Run Code Online (Sandbox Code Playgroud)
scala> for (i:Long <- 0L to 10000000L) {}
scala> for (i <- 0L to 10000000L) {} scala> for (i:Long <- 0 to 10000000L) {}
<console>:19: error: type …Run Code Online (Sandbox Code Playgroud) scala ×5
numerical ×2
types ×2
autoboxing ×1
biginteger ×1
debugging ×1
for-loop ×1
gdb ×1
lldb ×1
restriction ×1
xcode ×1