level 3
Exercise 8.4: Can you find any value for f such that the call pcall(pcall, f) returns false as its first result?
2015年09月09日 16点09分
1
level 14
print( pcall(pcall, ...) )
falsebad argument #1 to '?' (value expected)
2015年09月11日 05点09分
5
人家题目要的是找出函数f,不是让你返回false。你下面的回复也不符号题目的要求。我认为世界上没有函数f可以使得pcall(pcall,f)的第一个返回值为false,不然pcall就自己打自己的脸了。
2015年09月11日 08点09分
@qqirisit ...不是value,是个表达式,f()也不是value,是函数调用。不要以为可以a = ...或a = f()就说...和f()是个value好不好。
2015年09月12日 03点09分
level 14
local function f()
end
print( pcall(pcall, f()) )
这样也可以
false
bad argument #1 to '?' (value expected)
2015年09月11日 06点09分
6
level 3
Hello, Mr Ierusalimschy
Exercise 8.4: Can you find any value for f such that the call pcall(pcall, f) returns false as its first result?
I don't know clearly the purpose of Exercise 8.4.
Does it want readers understand that 'pcall' only catches the error message and return it but raise an error so that such 'f' doesn't exist?
Or want really readers to find a 'value' for f?
I find two 'forms' for f that make the call 'pcall(pcall, f)' returns false as the first result:
1. print(pcall(pcall, ...))
2. function f() return end; print(pcall(pcall, f()))
But I'm not sure whether '...' and 'f()' are values in Lua. That's why I use 'form' instead.
And I have some other questions while doing Exercise 8.4:
Why the following two code snippets get different results?
1. function f() return end; print(pcall(pcall, f()))
2. function f() return nil end; print(pcall(pcall, f()))
Why the following two code snippets get different results?
1. function f() return end; print(f())
2. function f() return nil end; print(f())
Why the following two code snippets get the same result?
1. function f() return end; a = f(); print(a)
2. function f() return nil end; a = f(); print(a)
Are 'no value' and 'nil' different? And how to distinguish them?
How to make 'type()' in 'function f() return end; print(type(f()))' safe?
Thank you for your book!
2015年09月12日 07点09分
7
这是我刚才发给作者的邮件
2015年09月12日 07点09分
@chaosink 其实你完全可以用中文在这里问我......
2015年09月12日 07点09分
@chaosink ,,,你那个pcall(f())=pcall(false) 一旦出现()就是调用,所以嘛,,,你下面的都是废话,,,而且你可以直接调试看看嘛
2015年09月12日 12点09分