在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
最满意答案
在版本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 forIEnumerable<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 anIEnumerable<char>
, so you can do LINQ operations on the string..First()
returns the first element of thatchar
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 anIEnumerable<char>
with one element in it. CallingConsole.WriteLine()
on anIEnumerable<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 passingIEnumerable<char>
toConsole.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.
相关问答
更多-
我认为不可能像这样从字符串执行LINQ的where子句。 由于您只想在where子句中添加&& criteria,您可以使用扩展方法链样式以这种方式动态添加条件: EnumerableRowCollection query = from contact in dtContacts.AsEnumerable() where contact["FirstName"].ToString().StartsWith(SearchText) select contact; if(!string.IsNullOrEmp ...
-
显然你有一个DirectoryInfo对象和一串文件扩展名作为字符串。 您需要一个查询,只保留目录中具有与某个文件扩展名匹配的扩展名的文件。 DirectoryInfo _dirInfo = ... IEnumerable
fileExtensions = ... IEnumerable filesWithDesiredExtensions = _dirInfo.EnumerateFiles() .Where(fileInfo => fileExtensions ... -
在Word中,超链接不是字符串,而是字段代码。 字段代码是特殊对象。 因此,不可能将多个超链接对象作为字符串的一部分传递。 您甚至无法将一个超链接对象作为字符串的一部分传递... 您可以将多个超链接字符串作为分隔字符串传递,然后将字符串“拆分”为一个数组,循环该数组以创建多个超链接对象。 如果你想从代码中打开一个超链接或超链接,我会记得一个FollowHyperlink方法(我现在在移动设备上,所以不能仔细检查)。 您可以将字符串传递给它。 In Word, a hyperlink is not a str ...
-
在版本3中, select x返回与您的标准匹配的字符串序列 ; 它恰好是一个有一个项目的序列。 Console.WriteLine内部调用.ToString() ,无论你传入它。 由于IEnumerable
没有有意义的字符串表示,因此.NET中的默认值是打印该类型的字符串名称。 根据你的措词,我认为你的困惑的一部分确实来自误解为什么版本2的工作方式。 在版本2中, select x.First()实际上是一个怪癖/巧合,因为一个字符串也是一个IEnumerable ,因此您可以对该字符串 ... -
这应该是你: SELECT DISTINCT substring( (SELECT DISTINCT ' + ' + t2.Outcomedestination FROM #CVtableforallyears t2 WHERE t2.TimeDimensionDatefromCV = t1.TimeDimensionDatefromCV FOR XML Path ('') ) ,4,1000) --just to omit the firs ...
-
您可以创建多个复选框,为它们添加multiple选项,这样您就可以: <%= f.check_box :answer, { multiple: true }, 'first', false %>First <%= f.check_box :answer, { multiple: true }, 'second', false %>Second <%= f.check_box :answer, { multiple: true }, 'third', false %>Third 请注意,您还需要指定fals ...
-
如果您知道只有一个结果,请使用.Single选择唯一的结果: string parseCode = (from x in xml.Descendants("LogType") where x.Attribute("ID").Value == string)ddlHistoryLogDefinitions.SelectedValue select x.Attribute("ParseCode").Value).Single(); 使 ...
-
你的array_push意思是 使用$ key => $ value推送到数组新元素 因此,在这种情况下的解决方案是删除array_push并尝试 $result['tags'][] = $row['tags']; Your array_push mean Push to your array new element with $key => $value So solution in this case is remove array_push and try $result['tags'][] = $ ...
-
使用Object.ToString()方法: Text = t.Element("Text")?.Value?.ToString(); Use the Object.ToString() method: Text = t.Element("Text")?.Value?.ToString();
-
它应该是相反的: site1.Contains(x.DisplayName) 。 此外,与列表相比, HashSet
对于多个查找更有效,随着项目数量的增加,这变得显着。 var sites1 = new HashSet (Sitecore.Configuration.Settings.Sites .Select(x => x.StartItem.TrimStart('/'))); var items1 = Sitecore.Context.Database.S ...