检查a)&str b)String的字符串是空的还是空白的正确方法是什么?我过去常常这样做"aaa".len() == 0,但我的直觉告诉我应该采取另一种方式吗?
我不明白为什么他们说 Ruby按值传递所有参数,同时下面的代码证明了相反的情况:
class MyClass1
@var1 = 123
def get1
@var1
end
def set1=value
@var1 = value
end
end
c1 = MyClass1.new
c1.set1 = 444
p c1.get1 # 444
def test1 mc
mc.set1 = 999
end
test1 c1
p c1.get1 # 999
Run Code Online (Sandbox Code Playgroud)
如果按价值计算,它会打印出来444,而不是999.
为什么我不能这样做:
import Data.Char
getBool = do
c <- getChar
if c == 't'
then IO True
else IO False
Run Code Online (Sandbox Code Playgroud)
而不是使用return?
我有一个用Scala编写的Android应用程序.当我启动它时,日志窗口中会出现以下错误消息:
08-31 13:11:10.781 5398-5398/my.app.app123 E/linker? load_library(linker.cpp:759): library "libmaliinstr.so" not found
08-31 13:11:10.784 5398-5398/my.app.app123 E/? appName=my.app.app123, acAppName=com.android.cts.openglperf
08-31 13:11:10.784 5398-5398/my.app.app123 E/? 0
08-31 13:11:10.784 5398-5398/my.app.app123 E/? appName=my.app.app123, acAppName=com.android.browser
08-31 13:11:10.784 5398-5398/my.app.app123 E/? 0
Run Code Online (Sandbox Code Playgroud)
它是什么意思以及如何解决它?
我有一个由几个组成的Scala项目.我决定开始使用sbt 0.13.这是~/sbt/repositories:
[repositories]
local
sbt-releases-repo: http://repo.typesafe.com/typesafe/ivy-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
sbt-plugins-repo: http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/, [organization]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]
maven-central: http://repo1.maven.org/maven2/
Run Code Online (Sandbox Code Playgroud)
但我仍然得到一个错误:
Getting org.scala-sbt sbt 0.13 ...
:: problems summary ::
:::: WARNINGS
module not found: org.scala-sbt#sbt;0.13
==== local: tried
/home/alex/.ivy2/local/org.scala-sbt/sbt/0.13/ivys/ivy.xml
==== sbt-releases-repo: tried
http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt/0.13/ivys/ivy.xml
==== sbt-plugins-repo: tried
http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scala-sbt/sbt/0.13/ivys/ivy.xml
==== maven-central: tried
http://repo1.maven.org/maven2/org/scala-sbt/sbt/0.13/sbt-0.13.pom
::::::::::::::::::::::::::::::::::::::::::::::
:: UNRESOLVED DEPENDENCIES ::
::::::::::::::::::::::::::::::::::::::::::::::
:: org.scala-sbt#sbt;0.13: not found
::::::::::::::::::::::::::::::::::::::::::::::
:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
unresolved dependency: org.scala-sbt#sbt;0.13: not found
Error during sbt execution: Error retrieving required …Run Code Online (Sandbox Code Playgroud) 我有一个单一的.RS文件。当我编译它时rustc test1.rs,我收到一个错误:
error: linking with `cc` failed: exit code: 1
note: cc '-m64' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-o' 'test1' 'test1.o' '-Wl,-force_load,/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libmorestack.a' '-Wl,-dead_strip' '-nodefaultlibs' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libstd-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcollections-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libunicode-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/librand-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liballoc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/liblibc-4e7c5e5c.rlib' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib/libcore-4e7c5e5c.rlib' '-L' '/usr/local/Cellar/rust/1.0.0-alpha/lib/rustlib/x86_64-apple-darwin/lib' '-L' '/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin' '-L' '/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin' '-lSystem' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/.rust/lib/x86_64-apple-darwin'
ld: warning: directory not found for option '-L/Users/alex/Documents/projects/rust/lib/x86_64-apple-darwin'
ld: can't open output file for writing: test1, errno=21 for architecture x86_64
clang: error: linker command failed with exit code …Run Code Online (Sandbox Code Playgroud) 一个ruby文件:
gem "my-gem", git: "https://github.com/gem123.git", branch: "some-branch"
require "my-gem"
var1 = SomeGem::some_method123
puts var1
Run Code Online (Sandbox Code Playgroud)
它说Could not find 'my-gem' (>= 0) among 330 total gem(s) (Gem::LoadError).为什么不?我需要一个gem的特殊分支,不想克隆存储库.
我遇到了一个错误:
extern crate rustc_serialize; // 0.3.24
use rustc_serialize::base64::{self, FromBase64, ToBase64};
fn main() {
let a: [u8; 30] = [0; 30];
let b = a.from_base64().unwrap().as_slice();
println!("{:?}", b);
}
Run Code Online (Sandbox Code Playgroud)
错误:
error[E0597]: borrowed value does not live long enough
--> src/main.rs:7:13
|
7 | let b = a.from_base64().unwrap().as_slice();
| ^^^^^^^^^^^^^^^^^^^^^^^^ - temporary value dropped here while still borrowed
| |
| temporary value does not live long enough
8 | println!("{:?}", b);
9 | }
| - temporary value needs to live until …Run Code Online (Sandbox Code Playgroud) 是否有适用于Scala的Play Framework 2的脚手架生成器实用程序,如Ruby on Rails?我找到了一些关于这方面的话题,但没有弄清楚哪一个最受欢迎,或者哪个是最标准的?
你的意见?
更新:我的意思是脚手架用于生成控制器,视图,模型或其中任何一个.
我以这种方式检索XML文档:
import xml.etree.ElementTree as ET
root = ET.parse(urllib2.urlopen(url))
for child in root.findall("item"):
a1 = child[0].text # ok
a2 = child[1].text # ok
a3 = child[2].text # ok
a4 = child[3].text # BOOM
# ...
Run Code Online (Sandbox Code Playgroud)
XML看起来像这样:
<item>
<a1>value1</a1>
<a2>value2</a2>
<a3>value3</a3>
<a4>
<a11>value222</a11>
<a22>value22</a22>
</a4>
</item>
Run Code Online (Sandbox Code Playgroud)
我如何检查a4(在这种特殊情况下,但它可能是任何其他元素)是否有孩子?