在python我可以这样做:
In [1]: x = ["a", "b", "c"]
In [2]: "--".join(x)
Out[2]: 'a--b--c'
Run Code Online (Sandbox Code Playgroud)
d中是否有相同的技巧?
我遇到了一个名为princexml的工具,它可以将html + css转换成pdf精美(参见此视频).有了它,甚至可以使用完全html + css编写博士论文,最后得到一个不错的pdf输出.但似乎它不能很好地处理mathjax.我想这是因为mathjax部分首先在浏览器中渲染.
所以我有一个像这样的简单html文件:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>test math</title>
<style type="text/css">
</style>
<script src='http://cdn.mathjax.org/mathjax/latest/MathJax.js' type='text/javascript'>
MathJax.Hub.Config({
HTML: ["input/TeX","output/HTML-CSS"],
TeX: { extensions: ["AMSmath.js","AMSsymbols.js"],
equationNumbers: { autoNumber: "AMS" } },
extensions: ["tex2jax.js"],
jax: ["input/TeX","output/HTML-CSS"],
tex2jax: { inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true },
"HTML-CSS": { availableFonts: ["TeX"],
linebreaks: { automatic: true } }
});
</script>
</head>
<body>
$x^2 + y^2 = 1$
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
使用princexml转换后:
prince --javascript x.html -o …Run Code Online (Sandbox Code Playgroud) 这是Big Nerd Ranch指南中的一个例子:
package com.example.geoquiz;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class QuizActivity extends ActionBarActivity {
private Button mTrueButton;
private Button mFalseButton;
private Button mNextButton;
private TextView mQuestionTextView;
private TrueFalse[] mQuestionBank = new TrueFalse[] {
new TrueFalse(R.string.question_africa, true),
new TrueFalse(R.string.question_americas, false),
new TrueFalse(R.string.question_asia, false),
new TrueFalse(R.string.question_mideast, true),
new TrueFalse(R.string.question_oceans, true)
};
private int mCurrentIndex = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
mTrueButton = (Button)findViewById(R.id.true_button);
mFalseButton = …Run Code Online (Sandbox Code Playgroud) 在python中,您可以执行以下操作:
def f():
return 1, 2, 3
(foo, bar, baz) = f()
Run Code Online (Sandbox Code Playgroud)
在Java中是否有等效项?
从了解你是一个很好的Haskell:
class Eq1 a where
(==) :: a -> a -> Bool
(/=) :: a -> a -> Bool
x == y = not (x /= y)
x /= y = not (x == y)
data TrafficLight = Red | Yellow | Green
instance Eq1 TrafficLight where
Red == Red = True
Green == Green = True
Yellow == Yellow = True
_ == _ = False
Run Code Online (Sandbox Code Playgroud)
当我加载它时ghci,我收到一个错误:
baby.hs:213:9:
Ambiguous occurrence ‘==’
It could refer to …Run Code Online (Sandbox Code Playgroud) 我正在尝试这个图示例:
funs = map (flip (^)) [2..6]
visualize f = stroke' (with & vertexNames .~ [[0 .. 6 :: Int]] )
(regPoly 7 1)
# lw none
# showLabels
# fontSize (Local 0.6)
<> star (StarFun f) (regPoly 7 1)
# stroke # lw thick # lc red
example = center . hcat' (with & sep .~ 0.5) $ map visualize funs
Run Code Online (Sandbox Code Playgroud)
这是结果:

一切看起来都像预期的那样,一些数字(或更确切地说,这些数字的中心)位于图像边缘附近,所以最后它们看起来像被切断了.
有办法解决这个问题吗?
> let loeb fs = xs where xs = fmap ($ xs) fs
> loeb [length, (!! 0)]
[2,2]
Run Code Online (Sandbox Code Playgroud)
在xs这里是递归定义的,以及如何勒布终止我是无法理解.
来自?dotsMethods:
Beginning with version 2.8.0 of R, S4 methods can be dispatched
(selected and called) corresponding to the special argument “...”.
Currently, “...” cannot be mixed with other formal arguments:
either the signature of the generic function is “...” only, or it
does not contain “...”. (This restriction may be lifted in a
future version.)
Run Code Online (Sandbox Code Playgroud)
以下是EBImage包中的一些代码:
## image IO, display
setGeneric ("image", function (x, ...) standardGeneric("image") )
## statistics
setGeneric ("hist", function (x, ...) standardGeneric("hist") )
Run Code Online (Sandbox Code Playgroud)
这显然违反了“...” …
这是一个例子:
(defn f1 [] (lazy-seq (cons 0 (f2))))
(defn f2 [] (lazy-seq (cons 1 (f3))))
(defn f3 [] (lazy-seq (cons 2 (f1))))
Run Code Online (Sandbox Code Playgroud)
在Haskell中,上述示例的等价物将生成[0,1,2,0,1,2,...]的惰性序列,但在clojure中,这将导致CompilerException,因为f2无法解析.
有没有办法解决?
这是代码:
int i = 200;
byte b = (byte) 200;
System.out.println(b);
System.out.println((short) (b));
System.out.println((b & 0xff));
System.out.println((short) (b & 0xff));
Run Code Online (Sandbox Code Playgroud)
这是输出:
-56
-56
200
200
Run Code Online (Sandbox Code Playgroud)
与0xff的按位AND不应该改变任何东西b,但显然它确实有效果,为什么?