这是我到目前为止(测试目的):
let string = "The quick BroWn fOX jumpS Over tHe lazY DOg"
for chr in string {
if isupper(String(chr)) {
print(String(chr).lowercaseString)
continue
}
print(chr)
}
Run Code Online (Sandbox Code Playgroud)
我该如何测试大写和小写字符?
我知道我可以从swift调用C函数,但这对我来说似乎不正确.我怎么能用swift做到这一点?
摘自 Haskell 主页https://www.haskell.org/
primes = filterPrime [2..]
where filterPrime (p:xs) =
p : filterPrime [x | x <- xs, x `mod` p /= 0]
Run Code Online (Sandbox Code Playgroud)
看了这个函数几分钟后,我意识到我不太明白这个函数实际上在做什么,我想知道发生了什么。
但首先,我相信这是正在发生的事情:
由于惰性评估,每次迭代中仅采用列表理解中的一个成员......如下所示:
第一次迭代
2 : filterPrime [x | x <- [3..], x `mod` p /= 0]
Run Code Online (Sandbox Code Playgroud)
第二次迭代
2 : 3 : filterPrime [x | x <- [4..], x `mod` p /= 0]
Run Code Online (Sandbox Code Playgroud)
第三次迭代
??? :(
Run Code Online (Sandbox Code Playgroud) 我一直在寻找一种正确的方法来关闭HTTP连接,但还没有找到任何东西.
require 'net/http'
require 'uri'
uri = URI.parse("http://www.google.com")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new("/")
http.start
resp = http.request request
p resp.body
Run Code Online (Sandbox Code Playgroud)
到目前为止一直很好,但是现在当我尝试关闭连接时猜测使用哪种方法:
http.shutdown # error
http.close # error
Run Code Online (Sandbox Code Playgroud)
当我检查时ri Net::HTTP.start,文档明确说
调用者负责在完成时关闭它(连接)
我不想使用块形式.
几天前我决定使用Vim文本编辑器......和vimtutor一起玩,我发现d操作员很少见; Vim会话:
之前:快速红色F ox跳过懒惰的棕色狗
后: 快速红色F Jumps Over the Lazy Brown Dog
results: as expected.
Placing the cursor in the last character of a word.
before: The Quick Red Fox跳通过惰性黄狗
后: 快速红佛Over the Lazy Brown Dog
results: de deletes the "x Jumps" substring.
Placing the cursor in the last character of the last word.
before: The Quick Red Fox Jumps Over the Lazy Brown Dog
之后: 快速的红狐狸跳过懒懒的棕色 …
我正在学习Scheme。我想为 Gimp 构建script-fu过滤器,所以我使用tinyscheme来执行我制作的脚本,但似乎tinyscheme的功能非常有限,缺少max、min和等功能even?。(我希望有人能在这里证明我错了:()
好吧,实际上,我只想用scheme48执行一个Scheme脚本。我怎么做?
例如,如何使用scheme48执行以下文件?
(define (addx inNum inX)
(if (> (* inNum inX) 999) 0
(+ (* inNum inX) (addx inNum (+ 1 inX)))))
(display
(- (+ (addx 3 1) (addx 5 1)) (addx 15 1)))
Run Code Online (Sandbox Code Playgroud) 我正在阅读 redis 的 SADD 命令帮助页面。http://redis.io/commands/sadd
然后我发现有人在问以下评论
我想知道对于添加的 N 个成员,这个操作复杂度如何成为 O(N)?如何执行唯一性检查?redis 是否存储了所有 SET 的所有成员的哈希表?
结果证明这是一个很好的问题,我很好奇为什么插入是 O(n) 和 SET?
object_id一个Fixnum是奇数:
i=0; i += 1 while i.object_id.odd?
# ^CIRB::Abort: abort then interrupt!
i # => 495394962
Run Code Online (Sandbox Code Playgroud)
而似乎object_id任何其他对象的是偶数(Bignum包括):
{}.object_id # => 70230978908220
true.object_id # => 20
false.object_id # => 0
nil.object_id # => 8
/regexp/.object_id # => 70230978711620
:symbol.object_id # => 391528
{/regexp/mou => Struct.new(:hello)}.object_id # => 70230987100840
Run Code Online (Sandbox Code Playgroud)
这是否与Ruby解释器中的一些模糊优化有关?
void main(){
/* This string needs to be printed without the '%' and in segments. */
char str[] = "Oct: %o Dec: %d Roman: %r";
int i = 0;
while (str[i] != '\0'){
/* When I run this nested loops, for some reason they don't stop at '\0'. */
while (str[i] != '%'){
printf("%c", str[i++]);
}
if (str[i] == '%')
i++;
}
}
Run Code Online (Sandbox Code Playgroud)