好吧,所以我使用命令下载了SpiderMonkey源代码wget http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz并将其解压缩.然后我通过执行以下命令成功构建了包含文件和静态库:
autoconf2.13./configure --prefix=~/js --disable-shared-jsmakemake install现在我尝试使用以下命令编译以下代码g++ -I/home/aaditmshah/js/include/js -L/home/aaditmshah/js/lib -lmozjs185-1.0 -ldl -lm -ldl helloworld.cpp -o helloworld:
/*
* This define is for Windows only, it is a work-around for bug 661663.
*/
#ifdef _MSC_VER
# define XP_WIN
#endif
/* Include the JSAPI header file to get access to SpiderMonkey. */
#include "jsapi.h"
/* The class of the global object. */
static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, …Run Code Online (Sandbox Code Playgroud) 我看到有人救第四源代码文件与扩展.4th,.fth,.frt和.f.哪个是Forth源代码文件最常用的文件扩展名?
今天,我经历的源代码简街的Core_kernel模块,我碰上了的compose功能:
(* The typical use case for these functions is to pass in functional arguments
and get functions as a result. For this reason, we tell the compiler where
to insert breakpoints in the argument-passing scheme. *)
let compose f g = (); fun x -> f (g x)
Run Code Online (Sandbox Code Playgroud)
我会将compose函数定义为:
let compose f g x = f (g x)
Run Code Online (Sandbox Code Playgroud)
他们给定义的原因compose,他们做的方式是"因为compose是需要的功能的功能f和g作为参数和返回功能fun x …
我知道该.ascii指令不会在字符串的末尾添加空字符.该.asciz指令用于此目的.但是,我不知道该.string指令是否在字符串的末尾放置一个空字符.如果确实如此,那么指令.asciz和.string指令之间的区别是什么?对我来说,同时具有.ascii和.string似乎是多余的.
在Haskell中,我们可以编写以下数据类型:
data Fix f = Fix { unFix :: f (Fix f) }
Run Code Online (Sandbox Code Playgroud)
类型变量f具有种类* -> *(即它是未知类型的构造函数).因此,Fix有那种(* -> *) -> *.我想知道Fix在Hindley Milner类型系统中是否是一个有效的类型构造函数.
从我在维基百科上看到的内容来看,它似乎Fix不是Hindley Milner类型系统中的有效类型构造函数,因为HM中的所有类型变量必须是具体的(即必须具有类型*).确实如此吗?如果HM中的类型变量并不总是具体,那么HM会变得不可判断吗?
ocaml haskell functional-programming type-inference hindley-milner
我想将以下Haskell代码转换为Agda:
import Control.Arrow (first)
import Control.Monad (join)
safeTail :: [a] -> [a]
safeTail [] = []
safeTail (_:xs) = xs
floyd :: [a] -> [a] -> ([a], [a])
floyd xs [] = ([], xs)
floyd (x:xs) (_:ys) = first (x:) $ floyd xs (safeTail ys)
split :: [a] -> ([a], [a])
split = join floyd
Run Code Online (Sandbox Code Playgroud)
这使我们能够有效地将列表拆分为两个:
split [1,2,3,4,5] = ([1,2,3], [4,5])
split [1,2,3,4,5,6] = ([1,2,3], [4,5,6])
Run Code Online (Sandbox Code Playgroud)
所以,我试图将此代码转换为Agda:
floyd : {A : Set} ? List A ? List A ? List …Run Code Online (Sandbox Code Playgroud) haskell functional-programming theorem-proving agda floyd-cycle-finding
我试图global在一行中用JavaScript 定义对象,如下所示:
var global = this.global || this;
Run Code Online (Sandbox Code Playgroud)
以上陈述属于全球范围.因此,在浏览器中,this指针是window对象的别名.假设它是在当前网页的上下文中执行的第一行JavaScript,其值global将始终与this指针或window对象的值相同.
在CommonJS实现中,例如RingoJS和node.js,this指针指向当前ModuleScope.但是,我们可以global通过上面global定义的属性访问该对象ModuleScope.因此,我们可以通过this.global酒店访问它.
因此,此代码段适用于所有浏览器以及至少RingoJS和node.js,但我还没有测试过其他CommomJS实现.因此,我想知道当在任何其他CommonJS实现上运行时,此代码是否不会产生正确的结果,如果是,我将如何解决它.
最后,我打算在lambda表达式中使用它来实现我的实现独立JavaScript框架,如下所示(来自jQuery的想法):
(function (global) {
// javascript framework
})(this.global || this);
Run Code Online (Sandbox Code Playgroud) 我使用以下函数从一组参数创建JavaScript中的函数实例:
var instantiate = function (instantiate) {
return function (constructor, args, prototype) {
"use strict";
if (prototype) {
var proto = constructor.prototype;
constructor.prototype = prototype;
}
var instance = instantiate(constructor, args);
if (proto) constructor.prototype = proto;
return instance;
};
}(Function.prototype.apply.bind(function () {
var args = Array.prototype.slice.call(arguments);
var constructor = Function.prototype.bind.apply(this, [null].concat(args));
return new constructor;
}));
Run Code Online (Sandbox Code Playgroud)
使用上面的函数,您可以按如下方式创建实例(请参阅小提琴):
var f = instantiate(F, [], G.prototype);
alert(f instanceof F); // false
alert(f instanceof G); // true
f.alert(); // F
function F() { …Run Code Online (Sandbox Code Playgroud) 我在块范围中定义函数时遇到了问题.考虑以下程序:
try {
greet();
function greet() {
alert("Merry Christmas!");
}
} catch (error) {
alert(error);
}
Run Code Online (Sandbox Code Playgroud)
我希望这个程序能够提醒Merry Christmas!.但是在Firefox中给了我以下内容ReferenceError:
ReferenceError: greet is not defined
Run Code Online (Sandbox Code Playgroud)
在Opera和Chrome上,它会像我预期的那样提醒问候语.
显然,Firefox会将块范围内的功能视为一段FunctionExpression时间,而Opera和Chrome将其视为一个FunctionDeclaration.
我的问题是为什么Firefox表现不同?哪种实现更符合逻辑?哪一个符合标准?
我理解JavaScript中的声明是悬而未决的,因此如果在同一范围内的两个或多个不同的块中声明相同的函数,那么就会出现名称冲突.
但是,每次声明函数时重新声明函数都不是更合乎逻辑,这样你就可以做到这样的事情:
greet(); // Merry Christmas!
function greet() {
alert("Merry Christmas!");
}
greet(); // Happy New Year!
function greet() {
alert("Happy New Year!");
}
Run Code Online (Sandbox Code Playgroud)
我认为除了解决上面描述的块范围问题之外,这将非常有用.
我在Haskell中实现了传感器,如下所示:
{-# LANGUAGE RankNTypes #-}
import Prelude hiding (foldr)
import Data.Foldable
type Reducer b a = a -> b -> b
type Transducer a b = forall t. Reducer t b -> Reducer t a
class Foldable c => Collection c where
insert :: a -> c a -> c a
empty :: c a
reduce :: Collection c => Transducer a b -> c a -> c b
reduce f = foldr (f insert) empty
mapping :: (a -> …Run Code Online (Sandbox Code Playgroud) haskell transducer monomorphism-restriction higher-rank-types
haskell ×4
javascript ×4
ocaml ×2
agda ×1
assembly ×1
c++ ×1
commonjs ×1
conventions ×1
directive ×1
forth ×1
gcc ×1
global ×1
header-files ×1
jquery ×1
node.js ×1
ocaml-core ×1
prototype ×1
scope ×1
spidermonkey ×1
transducer ×1
x86 ×1