是否可以从Silverlight/C#调用matlab函数?
我写了一个像这样的Lisp函数:
(defun power (base exponent)
(if (= exponent 0)
1
(* base (power (- exponent 1)))))
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试调用它时,我会遇到一些错误:
CL-USER 2 > (power 2 3)
Error: POWER got 1 arg, wanted at least 2.
1 (abort) Return to level 0.
2 Return to top loop level 0.
Type :b for backtrace or :c <option number> to proceed.
Type :bug-form "<subject>" for a bug report template or :? for other options.
CL-USER 3 : 1 > (power 2)
Error: POWER got 1 arg, …Run Code Online (Sandbox Code Playgroud) void func() {assert(0);}
int main () {void func();}
Run Code Online (Sandbox Code Playgroud)
上面的代码不调用func(),或者至少没有达到断言.不是我真的需要知道,但我只是好奇,这里发生了什么?
我想要的是一个工具,能够告诉我哪些函数调用特定函数A()(在C项目中),以及哪些函数调用这些函数等,以便我可以有一个函数列表,我知道当它们被调用,有可能会调用函数A().
例如,我们在项目中分散了以下功能:
void A()
{ /*does something*/ }
void B()
{
A();
/*and more stuff*/
}
void C()
{
if(unlikely_to_be_false)
A()
/* moar stoff */
}
void D()
{
/* code that does not refer to A() at all */
}
void E()
{
C()
}
Run Code Online (Sandbox Code Playgroud)
当使用参数A运行真棒工具时,它将以某种方式返回函数BC和E.
接近这一点,但不完全是我想要实现这一点:给定项目中的某个变量,找到所有读/写操作(直接或间接).
例如:
void A()
{
char* c; // this is our little variable
B(c); // this is in the resulting list
}
void B(char* x)
{
printf("%c", x); // this is definately in …Run Code Online (Sandbox Code Playgroud) 拥有我认为应该是一个相对容易的问题来处理成为一个主要的痛苦......我正在尝试做:
a.b("param", function(data)
{
logger.debug("a.b(" + data.toString() + ")");
if (data.err == 0)
{
// No error, do stuff with data
}
else
{
// Error :( Redo the entire thing.
}
});
Run Code Online (Sandbox Code Playgroud)
我的方法是尝试:
var theWholeThing = function() {return a.b("param", function(data)
{
logger.debug("a.b(" + data.toString() + ")");
if (data.err == 0)
{
// No error, do stuff with data
}
else
{
// Error :( Redo the entire thing.
theWholeThing();
}
})};
Run Code Online (Sandbox Code Playgroud)
上面的问题是前者确实有效(除非发生错误时没有处理),后者根本不打印日志消息......就好像“theWholeThing()”调用没有像我认为的那样工作(再次调用整个事情)。
这里一定有什么微妙的错误,有什么提示吗?
谢谢!
我有一个像这样的小功能:
void Bar(string s)
{
*/ do somthing with the string here.*/
}
void Foo()
{
Bar("Hello");
}
Run Code Online (Sandbox Code Playgroud)
如果我看一下IL输出,它给了我以下内容:
.method private hidebysig instance void Foo() cil managed
{
.maxstack 8
L_0000: ldarg.0
L_0001: ldstr "Hello"
L_0006: call instance void TestApp.MainWindow::Bar(string)
L_000b: ret
}
Run Code Online (Sandbox Code Playgroud)
现在我以为我会替换它的const string字段.
const string str= "Hello";
void Foo()
{
Bar(str);
}
Run Code Online (Sandbox Code Playgroud)
转换为完全相同的 IL片段.
现在我的问题是使用哪一个?
Foo("Hello"); 要么 Foo(cHello);
谢谢您的帮助!
--------------编辑-------------------
更具体地说,我将此用于记录目的以添加前缀消息:它只会在代码中出现一次!
所以它看起来更像是这样的:
void LogDebug(string msg)
{
Log("[DEBUG]", msg)
}
void Log(string pre, string msg)
{ …Run Code Online (Sandbox Code Playgroud) 我试图在另一个函数中声明一个函数.所以这是我的代码的一部分:ViewController.m
- (void)updatedisplay{
[_displayText setText:[NSString stringWithFormat:@"%d", counter]];
}
- (IBAction)minus1:(id)sender {
counter--;
updatedisplay();
}
Run Code Online (Sandbox Code Playgroud)
ViewController.h
- (IBAction)minus1:(id)sender;
- (void)updatedisplay;
Run Code Online (Sandbox Code Playgroud)
其中返回了"隐式声明功能"的错误......"在C99中无效".
结果:http://i.imgur.com/rsIt6r2.png
我发现人们遇到了类似的问题,但作为一个新手,我真的不知道接下来该做什么.谢谢你的帮助!:)
代码_0:
(foo不带括号调用)
function foo(){
console.log('hello world');
}
setTimeout(foo, 2000);
Run Code Online (Sandbox Code Playgroud)
这是如何code_0执行的:
start -> wait for 2 seconds -> 'hello world' displayed -> end
Run Code Online (Sandbox Code Playgroud)
代码_1:
(foo用括号调用)
function foo(){
console.log('hello world');
}
setTimeout(foo(), 2000);
Run Code Online (Sandbox Code Playgroud)
这就是code_1执行的方式:
start -> 'hello world' displayed immediately -> wait for 2 seconds -> end
Run Code Online (Sandbox Code Playgroud)
当我用括号调用函数时,为什么程序的执行会如此不同?其根本机制是什么?
抱歉,如果这个问题太琐碎了。但我找不到任何针对初学者的 javascript 教程的解释。
我有一些小的软件,计算出每个三角形数因子的数量,看看有什么是他们的第一个比的因素X号(是的,这是一个欧拉计划的问题,更多数量的12 ,,虽然我没解决这个问题还)......因为我试图拍X一些随机值,看看代码的功能和多少时间,我发现了一些奇怪的(至少对我来说):直到X = 47明显正常的方式执行时间增加,但是当X = 48时它比正常情况增加更多,并且函数调用远大于速率,它(爆炸),如果我会这样说..为什么它会这样做?
代码:
def fac(n):
c=0
for i in range (1,n+1):
if n%i==0:
c=c+1
return c
n=1
while True:
summ=0
for i in range (1,n+1):
summ=summ+i
if fac(summ)>X:
break
n=n+1
print summ
Run Code Online (Sandbox Code Playgroud)
并在分析时:
when X=45 : 314 function calls in 0.027 CPU seconds
when X=46 : 314 function calls in 0.026 CPU seconds
when X=47 : 314 function calls in 0.026 CPU seconds
when X=48 : 674 function calls in 0.233 CPU seconds
when X=49 …Run Code Online (Sandbox Code Playgroud) 我在使用click事件处理程序执行函数时遇到问题。如果我摆脱了函数numberCheck()并将代码直接发布到事件处理程序中,那么它将正常工作。我在这里缺少基本的东西吗?
这是我的代码:
jQuery(document).ready(function(){
var scopedVariable;
var number = Math.floor(Math.random()*11);
function numberCheck() {
$(this).closest('#outsideContainer').find('.hotter').addClass('hideStuff');
$(this).closest('#outsideContainer').find('.colder').addClass('hideStuff');
var guess = $(this).closest('#guessContainer').find('.value').val();
if( +guess === number)
{
$(this).closest('#outsideContainer').find('.gotIt').removeClass('hideStuff');
}
else {
$(this).closest('#guessContainer').find('.value').val('Please guess again');
if(Math.abs(guess - number) < Math.abs(scopedVariable - number)) {
$(this).closest('#outsideContainer').find('.hotter').removeClass('hideStuff');
}
else if(Math.abs(guess - number) > Math.abs(scopedVariable - number)) {
$(this).closest('#outsideContainer').find('.colder').removeClass('hideStuff');
}
scopedVariable = guess;
}
}
$('.query').on('click', function() {
numberCheck();
});
});
Run Code Online (Sandbox Code Playgroud)
如果需要,这是我的HTML:
<body>
<div id="outsideContainer">
<div id="guessContainer">
<h3> Guess a number between 1 and 10 </h3>
<input id="txtfield" name="txtfield" …Run Code Online (Sandbox Code Playgroud) function-calls ×10
javascript ×3
c ×1
c# ×1
c++ ×1
const ×1
emacs ×1
function ×1
html ×1
jquery ×1
lisp ×1
loops ×1
matlab ×1
objective-c ×1
parameters ×1
parentheses ×1
parsing ×1
python ×1
silverlight ×1
string ×1
time ×1
void ×1