首页 \ 问答 \ 在Devel Machine上同时使用Scala 2.10-M1和2.9?(Scala 2.10-M1 and 2.9 same time on Devel Machine?)

在Devel Machine上同时使用Scala 2.10-M1和2.9?(Scala 2.10-M1 and 2.9 same time on Devel Machine?)

编辑:
排序后,SCALA_HOME + / bin到PATH设置默认解释器; 即从bash提示符键入“scala”在我的情况下调用2.9.1。 刚刚下载了2.10.0.M1。 从bash调用/path/to/2.10/bin/scala会调出2.10 REPL。

我只是为2.10添加一个终端别名,所以我不必手动输入路径。

原版的:
我是否需要客户虚拟机来关闭它,或者在Linux中,我可以以某种方式并排运行2.10和2.9吗?

基本上,我想试验2.10-M1反射,看看在继续进行一般2.9.1开发的同时,我可以对案例类造成什么样的运行时破坏。

如果没有,Kotlin式的网络演示肯定会在2.10演变期间搞砸...


Edit:
Got it sorted, SCALA_HOME + /bin to PATH sets the default interpreter; i.e. typing "scala" from bash prompt invokes 2.9.1 in my case. Just downloaded 2.10.0.M1. Invoking /path/to/2.10/bin/scala from bash brings up 2.10 REPL.

I'll just add a terminal alias for 2.10 so I don't have to type out the path manually.

Original:
Do I need a guest VM to pull this off, or in Linux, can I somehow run 2.10 and 2.9 side-by-side?

Basically, I'd like to experiment with 2.10-M1 reflection and see what runtime havoc I can wreak on case classes while continuing with general 2.9.1 development.

If not, a Kotlin-esque web demo sure would be nice to mess around with during the 2.10 evolution...


原文:https://stackoverflow.com/questions/9093535
更新时间:2022-06-07 16:06

最满意答案

在版本3中, select x返回与您的标准匹配的字符串序列 ; 它恰好是一个有一个项目的序列。

Console.WriteLine内部调用.ToString() ,无论你传入它。 由于IEnumerable<T>没有有意义的字符串表示,因此.NET中的默认值是打印该类型的字符串名称。

根据你的措词,我认为你的困惑的一部分确实来自误解为什么版本2的工作方式。 在版本2中, select x.First()实际上是一个怪癖/巧合,因为一个字符串也是一个IEnumerable<char> ,因此您可以对该字符串执行LINQ操作。 .First()返回该char序列的第一个元素,用于符合条件的每个结果。 所以你说:

“对于符合我的标准的每个元素,请选择第一个字符,然后返回匹配的所有第一个字符的序列。”

因此,实际上,版本2中的item是一个IEnumerable<char> ,其中包含一个元素。 在IEnumerable<char>上调用Console.WriteLine()将按顺序打印字符。 所以你得到“我”。

(注意:在我回答这个问题后,我看到问题被编辑为在投影内部和结果中调用.First() ,所以关于将IEnumerable<char>传递给Console.WriteLine一点不再完全相关)

请记住,LINQ几乎是关于使用集合,直到你明确地减少它们。 例如, Select只是一个投影或转换。 它返回传递给它的相同数量的项目,进行转换。 Where减少了集合,但它仍然是一个集合。


In version 3, select x is returning a sequence of strings that match your critera; it just happens to be a sequence with one item in it.

Console.WriteLine internally calls .ToString() on whatever you pass into it. Since there is no meaningful string representation for IEnumerable<T>, the default in .NET is to print the string name of the type.

Based on your wording, I think part of your confusion does come from a misunderstanding of why version 2 works the way it does. In version 2, select x.First() is actually a bit of a quirk/coincidence, because a string is also an IEnumerable<char>, so you can do LINQ operations on the string. .First() returns the first element of that char sequence, for each result that matches your criteria. So you're saying:

"For each element which matches my criteria, select the first character, and then return the sequence of all the first characters for the matches."

So in fact, item in version 2 is an IEnumerable<char> with one element in it. Calling Console.WriteLine() on an IEnumerable<char> will just print the chars in order. So you get "i".

(note: I see after I answered this, the question was edited to call .First() both inside the projection and on the result, so the bit about passing IEnumerable<char> to Console.WriteLine isn't totally relevant anymore)

Keep in mind LINQ is pretty much about working with sets until you explicitly reduce them down. For example, Select is simply a projection or transformation. It returns the same number of items that were passed to it, transformed. Where reduces down the set, but it's still a set.

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)