我正在学习Racket,而且我不知道如何在var child;
v1.on('write', function(param) {
if (param[0] == '1') {
child = exec('python /home/pi/startup/motion.py',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
writeVal = 'motion sensor ON';
}
else if (param[0] == '0') {
exec('kill '+ child.pid,
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
//
// child.kill()
//
writeVal = 'Motion OFF';
}
});
函数内部的函数中返回值:
andmap
如果我在(define iguales 0)
(andmap
(lambda (x y)
(cond
((eq? (last x) (last y))
(set! iguales (add1 iguales)))))
casos extension)
函数的末尾添加iguales
,我认为它将为每个lambda (x y)
和x
值返回一个值。
在该lambda函数中将返回值放在哪里的正确位置?
答案 0 :(得分:2)
主体返回最后一个表单的值。
此:
(cond ((eq? (last x) (last y))
(set! iguales (add1 iguales)))
返回#f
或set!
表单的结果。
无论如何要从lambda返回iguales
:
(lambda (x y)
(cond ((eq? (last x) (last y))
(set! iguales (add1 iguales))))
iguales)
然后,andmap
表单将返回#f
或casos
和extension
中较短者的长度(请参阅为什么?)。