我最近发现了这个使用monads的名为Simple interpreter的scala示例:
object simpleInterpreter {
case class M[A](value: A) {
def bind[B](k: A => M[B]): M[B] = k(value)
def map[B](f: A => B): M[B] = bind(x => unitM(f(x)))
def flatMap[B](f: A => M[B]): M[B] = bind(f)
}
def unitM[A](a: A): M[A] = M(a)
def showM(m: M[Value]): String = m.value.toString();
type Name = String
trait Term;
case class Var(x: Name) extends Term
case class Con(n: int) extends Term
case class Add(l: Term, r: Term) extends Term …Run Code Online (Sandbox Code Playgroud) 我创建了文件"hello.clj"
(ns clojure.examples.hello
(:gen-class))
(defn -main
[greetee]
(println (str "Hello " greetee "!")))
并尝试编译
clojurec hello.clj
但我得到了这个错误
Exception in thread "main" java.io.FileNotFoundException: Could not locate hello/clj__init.class or hello/clj.clj on classpath:
at clojure.lang.RT.load(RT.java:398)
at clojure.lang.RT.load(RT.java:367)
at clojure.core$load__5058$fn__5061.invoke(core.clj:3734)
at clojure.core$load__5058.doInvoke(core.clj:3733)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$load_one__5010.invoke(core.clj:3578)
at clojure.core$compile__5065$fn__5067.invoke(core.clj:3744)
at clojure.core$compile__5065.invoke(core.clj:3743)
at clojure.lang.Var.invoke(Var.java:346)
at clojure.lang.Compile.main(Compile.java:56)
我也尝试将它放在文件中并运行clojore hello.clj
(compile 'clojure.examples.hello)
但得到了同样的错误.
我有角度1.0.6(我知道它是旧的)我有带表达式的style属性:
<li style="background-color: {{item.color}}">
<span style="color: {{item.color | contrastColor}}">{{item.label}}</span>
</li>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但不适用于IE(应用程序需要工作> IE10).当我打开Developer工具时,style属性不存在.我试图创建自定义样式指令(因为我认为IE在Angular可以读取它之前删除无效属性)但是使用这个简单的代码,我TypeError: Cannot read property 'replace' of undefined从jquery(在谷歌浏览器上测试)得到了一个错误,因为在我的案例中.颜色可以为null
.directive("logStyle", function() {
// logStyle directive
return {
restrict: 'A',
link: function(scope, element, attrs) {
element.css(scope.$eval(attrs.logStyle));
}
};
});
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它发挥作用.我知道有ngStyle,但它不是我需要的.
我有带jquery终端的网页和隐藏的textarea(触发Android虚拟键盘),我可以输入字符但是当我输入几个命令时,内容隐藏在虚拟键盘后面.终端内容滚动到底部,因为当我输入更多命令时它会滚动.当我在手机中使用硬件键盘时,滚动是正确的(触摸滚动还没有工作).
我添加了这个CSS
.terminal textarea { top: 0; width:0; margin-left: -8px; pointer-events: none; }
Run Code Online (Sandbox Code Playgroud)
对于prevoius
.terminal .clipboard {
position: absolute;
bottom: 0;
left: 0;
opacity: 0.01;
filter: alpha(opacity = 0.01);
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0.01);
width: 2px;
}
.cmd > .clipboard {
position: fixed;
}
Run Code Online (Sandbox Code Playgroud)
并在插件中使用此代码(textarea用于剪贴板).
self.click(function() {
self.find('textarea').focus();
});
Run Code Online (Sandbox Code Playgroud)
我的问题是:javascript可以检测出虚拟键盘的大小吗?或者也许还有其他方法来改变网页的大小,所以它只是在视觉部分(不是键盘的位置)?或者我的代码可能有问题,它不适用于移动设备.即使用户安装了不同的键盘,键盘的大小也始终相同吗?
我想将所有Array函数包装在数组对象中,但是在控制台中
>>> Array.prototype
[]
>>> [].prototype
undefined
Run Code Online (Sandbox Code Playgroud)
但是当我输入Array.prototype控制台时它显示自动填充中的所有功能,我该如何获得这些功能?他们藏在哪里?
我有这样的代码(取消ajax调用):
if (requests.length) {
for (i=requests.length; i--;) {
var r = requests[i];
if (4 !== r.readyState) {
try {
r.abort();
} catch(e) {
self.error('error in aborting ajax');
}
}
}
requests = [];
// only resume if there are ajax calls
self.resume();
}
Run Code Online (Sandbox Code Playgroud)
和jshint显示错误:
Value of 'e' may be overwritten in IE 8 and earlier.
Run Code Online (Sandbox Code Playgroud)
在} catch(e) {什么样的错误呢?
我想编写一个函数,将当前缓冲区的文件名插入到kill环中,这样我就可以将它放到另一个窗口的终端中.如何以编程方式将字符串插入kill ring?
(<SOME FUNCTION> (buffer-file-name))
Run Code Online (Sandbox Code Playgroud)
是否有(内置)函数或者我需要将我想要的字符串插入缓冲区然后将其删除?
我试过这样的事情:
(defun path ()
(interactive)
(save-excursion
(let ((begin (mark)))
(insert (buffer-file-name))
(kill-region begin (mark)))))
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
尝试使用节点安装pty.js时遇到了一个不寻常的问题:
如果我运行npm install pty.js我收到此错误:
> node-gyp rebuild
CXX(target) Release/obj.target/pty/src/unix/pty.o
../src/unix/pty.cc:487:10: error: use of undeclared identifier 'openpty'
return openpty(amaster, aslave, name, (termios *)termp, (winsize *)winp);
^
../src/unix/pty.cc:533:10: error: use of undeclared identifier 'forkpty'
return forkpty(amaster, name, (termios *)termp, (winsize *)winp);
^
2 errors generated.
make: *** [Release/obj.target/pty/src/unix/pty.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack at ChildProcess.emit (events.js:98:17)
gyp ERR! stack at …Run Code Online (Sandbox Code Playgroud) 我正在研究一些代码,这些代码将搜索字符串并返回缺少的字母表中的任何字母.这就是我所拥有的:
function findWhatsMissing(s){
var a = "abcdefghijklmnopqrstuvwxyz";
//remove special characters
s.replace(/[^a-zA-Z]/g, "");
s = s.toLowerCase();
//array to hold search results
var hits = [];
//loop through each letter in string
for (var i = 0; i < a.length; i++) {
var j = 0;
//if no matches are found, push to array
if (a[i] !== s[j]) {
hits.push(a[i]);
}
else {
j++;
}
}
//log array to console
console.log(hits);
}
Run Code Online (Sandbox Code Playgroud)
但是使用测试用例:findWhatsMissing("dab c");
在将d添加到缺失数组之前的所有字母中的结果.
任何帮助将不胜感激.
我想这样定义jsx:
<table style={{'--length': array.lenght}}>
<tbody>
<tr>{array}</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
并且我在CSS中使用--length,也有一些单元格具有--count,它们使用css伪选择器(使用Counter hack)显示计数。
但打字稿显示错误:
TS2326: Types of property 'style' are incompatible.
Type '{ '--length': number; }' is not assignable to type 'CSSProperties'.
Object literal may only specify known properties, and ''--length'' does not exist in type 'CSSProperties'.
Run Code Online (Sandbox Code Playgroud)
是否可以更改样式属性的类型以接受CSS变量(自定义属性),或者是否可以对样式对象进行强制?