我已经编写了几年,没有太复杂.C++是我最熟悉的.我最近偶然发现了保罗格雷厄姆的网站,编码恐怖,现在在这里.
我学到了什么?"通过函数式编程的方式来启发自己"?Haskell,Scheme还是CLisp?
lisp scheme haskell functional-programming language-comparisons
我正在研究一个Rails模板,并试图编写一些代码,允许我填充一个表或多列ul标签"从上到下"和"从左到右"跨越我指定的许多列.我刚刚掌握了Ruby,所以我无法理解这一点.我也对这个有用的片段的惯用Haskell版本感到好奇.对Clojure版本的改进表示赞赏:
(defn table [xs & {:keys [cols direction]
:or {cols 1 direction 'right}}]
(into []
(condp = direction
'down (let [c (count xs)
q (int (/ c cols))
n (if (> (mod c q) 0) (inc q) q)]
(apply map vector (partition n n (repeat nil) xs)))
'right (map vec (partition cols cols (repeat nil) xs)))))
Run Code Online (Sandbox Code Playgroud)
有了这段代码,我就可以做到以下几点:
(table (range 10) :cols 3)
Run Code Online (Sandbox Code Playgroud)
打印出来的情况如下:
0 1 2
3 4 5
6 7 8
9
Run Code Online (Sandbox Code Playgroud)
更棘手的一个:
(table (range 10) :cols 3 :direction …Run Code Online (Sandbox Code Playgroud) .NET有用于模拟浏览器请求的HttpWebRequest和WebClient类.
我会谷歌,但我不确定使用什么关键字.
我想在applet或本地编写执行HTTP GET和POST以及cookie的代码,并.jar在文本字符串或其他一些可解析的结构中返回响应.
可能重复:
php字符串转义为python的""""""?
python中的三引号包含其中包含的所有引号和换行符.例如,
""" this
is all
just one string. I can even tell you "I like pi".
Notice that the single quotes are escaped - they don't end the string; and the newlines become part of the string
"""
Run Code Online (Sandbox Code Playgroud)
有人知道PHP是否具有与python相同的功能
""" <form><h1>PUT HTML HERE</h1> </form> """
enter code here
Run Code Online (Sandbox Code Playgroud)
编辑:对于那些将来看这个问题的人,我已经回答了,这是一个例子:
$heading = "Heading Gettizburgz";
print <<< END
<p><h1>$heading</h1> "in quotes" 'in single'
Four score and seven years ago<br/>
our fathers set onto this continent<br/>
(and so on ...)<br/>
</p> …
pythonistas如何将数字作为单词打印,就像Common Lisp代码的等价物一样:
[3]> (format t "~r" 1e25)
nine septillion, nine hundred and ninety-nine sextillion, nine hundred and ninety-nine quintillion, seven hundred and seventy-eight quadrillion, one hundred and ninety-six trillion, three hundred and eight billion, three hundred and sixty-one million, two hundred and sixteen thousand
Run Code Online (Sandbox Code Playgroud) Java是否具有C++的默认复制构造函数?如果它有一个 - 如果我明确地声明另一个构造函数(不是复制构造函数),它是否仍然可用?
c++ java language-comparisons copy-constructor object-construction
我不想开始另一个"谁拥有更大的成员"VB vs C#辩论(/sf/ask/11076061/似乎已经覆盖了那个虽然我对可能影响一个人与另一个人的发展的间接差异感兴趣.我所有的商业.NET开发都是VB中的桌面应用程序,直到最近3个月我有一个Web项目,并认为这是一个强迫自己学习C#的好机会.在这样做的过程中,我注意到了一些非技术性差异:
C#中提供了比VB 更成熟的开源应用程序和完整示例.
用于重构和文档之类的加载项的第三方供应商往往比VB支持C#(如果有的话),VB支持类似的C#版本的类似功能,往往落后或缺席.
针对C#的ASP.NET作业平均支付比VB中其他相同作业多15-20%(至少在澳大利亚,查看seek.com.au和careerone.com.au作为参考).
跳转到ASP.NET,MVC和C#同时提供了很多速度提升,但我认为非常值得.我现在需要做出的决定是,是否要为将来的.NET开发投入更多的精力去追求C#,或者我是否还要坚持使用VB.在这种情况下,应该考虑的语言(已经涵盖的直接语言特征比较除外)之间是否存在其他任何不同点?
在C#中,如果你想要字面意思地使用String,即忽略转义字符,你可以使用:
string myString = @"sadasd/asdaljsdl";
Run Code Online (Sandbox Code Playgroud)
但是Java中没有相应的东西.有没有什么理由Java没有包含类似的东西?
编辑:
在回顾了一些答案并思考之后,我真正要问的是:
是否有任何令人信服的论据反对在Java中添加这种语法?一些消极的,我只是没有看到?
我想用我可以插入类的方法创建轻量级接口.这是Scala中的一个简短示例:
class DB {
def find(id: String) = ...
}
trait Transformation extends DB {
def transform(obj: String): String
override def find(id: String) =
transform(super.find(id))
}
trait Cache extends DB {
val cache = Cache()
override def find(id: String) = {
...
if (cache.contains(id))
cache.find(id)
else {
cache.set(id, super.find(id))
cache.get(id)
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用这些类(特征),我们可以使用Transformation,使用Cache或两者来实例化DB类.请注意,Transformation有一个抽象方法转换,仍然需要在具体类中实现.
new DB() with Transformation {
def transform(obj: String): obj.toLower()
}
new DB() with Cache
new DB() with Transformation with Cache {
def transform(obj: String): obj.toLower()
} …Run Code Online (Sandbox Code Playgroud) 我是Haskell的新手,并尝试制作拼字游戏解算器.它接收您当前拥有的字母,查找它们的所有排列并过滤掉那些字典单词.代码非常简单:
import Data.List
main = do
dict <- readFile "words"
letters <- getLine
let dictWords = words dict
let perms = permutations letters
print [x | x <- perms, x `elem` dictWords]
Run Code Online (Sandbox Code Playgroud)
然而,与我使用Python的非常类似的实现相比,它的速度非常慢.有什么根本我做错了吗?
*编辑:这是我的Python代码:
from itertools import permutations
letters = raw_input("please enter your letters (without spaces): ")
d = open('words')
dictionary = [line.rstrip('\n') for line in d.readlines()]
d.close()
perms = ["".join(p) for p in permutations(letters)]
validWords = []
for p in perms:
if p in dictionary: validWords.append(p)
for validWord in …Run Code Online (Sandbox Code Playgroud) python ×4
haskell ×3
java ×3
c# ×2
.net ×1
asp.net ×1
c++ ×1
clojure ×1
codeigniter ×1
comparison ×1
formatting ×1
heredoc ×1
lisp ×1
nlp ×1
optimization ×1
php ×1
ruby ×1
scala ×1
scheme ×1
vb.net ×1