这是一个非常特别的例子描述Not in scope: isOne了我的错误:
ignoreFirstOnes :: [Int] -> [Int]
ignoreFirstOnes (1:xs) = dropWhile isOne xs
ignoreFirstOnes xs = xs
where isOne = (== 1)
Run Code Online (Sandbox Code Playgroud)
奇怪的是,isOne函数已定义where,但编译器一直在抱怨.我可以使用警卫甚至改写它,dropWhile (== 1)但我想了解如何使工作成为当前的例子.
好的,这是情况:
var vowels = ['a', 'i', 'y', 'e', 'o', 'u'];
String.prototype.isVowel = function () {
return vowels.indexOf(this) !== -1;
};
alert('a'.isVowel());
Run Code Online (Sandbox Code Playgroud)
它会提醒"假",因为this引用不是'a'它的原型.为了使它工作,我们需要做一点改变.
String.prototype.isVowel = function () {
return vowels.indexOf(this[0]) !== -1;
};
alert('a'.isVowel());
Run Code Online (Sandbox Code Playgroud)
这将起作用,因为String.prototype包含原始字符串的所有字符.实际上这是一个黑客,我不喜欢它.
但是,我们需要做些什么来使这个代码工作?
Number.prototype.is5 = function () { return this === 5; }
alert((5).is5()); //will alert 'false'
Run Code Online (Sandbox Code Playgroud)
或者我们只是不需要触摸原型?
我正在玩lagrest prime divisor,我遇到了这段代码的麻烦:
lpd :: Integer -> Integer
lpd n = helper n (2:[3,5..ceiling])
where
helper n divisors@(d:ds)
| n == d = n
| n `rem` d == 0 = helper (n `div` d) divisors
| otherwise = helper n ds
ceiling = truncate $ sqrt n
Run Code Online (Sandbox Code Playgroud)
错误消息是:
problems.hs:52:15:
No instance for (RealFrac Integer)
arising from a use of `truncate'
Possible fix: add an instance declaration for (RealFrac Integer)
In the expression: truncate
In the expression: truncate $ sqrt …Run Code Online (Sandbox Code Playgroud) 我现在正在学习 Python,我想编写一些有助于我工作的脚本。这个想法是:while True:从剪贴板读取一些字符串,修改它然后将它返回到剪贴板然后sleep。所以我可以将修改后的数据粘贴到任何地方。
现在我被困在使用win32clipboard模块。我正在使用此代码:
import win32clipboard
def openClipboard():
win32clipboard.OpenClipboard()
def closeClipboard():
try:
win32clipboard.CloseClipboard()
except Exception as e:
print(e)
def getClipboardData():
if win32clipboard.IsClipboardFormatAvailable(win32clipboard.CF_TEXT):
return win32clipboard.GetClipboardData()
else:
return None
def setClipboardData(data):
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(win32clipboard.CF_TEXT, data)
#assume that I copied '000'
openClipboard()
data = getClipboardData()
print(data) //output: 000, so it's ok
closeClipboard()
openClipboard()
win32clipboard.EmptyClipboard()
setClipboardData(data + '123')
closeClipboard()
openClipboard()
data = getClipboardData()
print(data) //output: 0 0 0 1 2 3, but wtf? o_0
closeClipboard()
Run Code Online (Sandbox Code Playgroud)
我不明白为什么第二个输出中有空格?