我正在尝试在Clojure中实现这个逻辑(只是一个例子):
a = 1 + 5
b = a + 3
c = a + 4
d = c + a
return f(a, b, c, d)
到目前为止,我写的最好的代码如下:
(let [a (+ 1 5) b (+ a 3) c (+ a 4) d (+ c a)] (f a b c d))
这看起来相当麻烦,主要是因为在我的实际案例中,这些“添加”操作要复杂得多,可能需要几行代码。我更喜欢这样写(Lisp风格):
(set a (+ 1 5))
(set b (+ a 3))
(set c (+ a 4))
(set d (+ c a))
(f
我现在用C#编程谋生,但在此之前,我用python编程了5年。我发现我写的C#和我在网上看到的大多数例子非常不同。而不是写这样的东西:
foreach (string bar in foo)
{
//bar has something doen to it here
}
我写的代码看起来像这样。
foo.ForEach( c => c.someActionhere() )
或
var result = foo.Select( c =>
{
//Some code here to transform th
所以我们写:
Customer c = new Customer();
为什么设计不像我们写的那样:
c = new Customer();
c.CreditLimit = 1000;
编译器可以计算出客户的c点,并允许在c上调用客户的成员?
我知道我们可能想写:
IPerson c = new Customer();
IPerson e = new Employee();
以便能够写:
public string GetName(IPerson object)
{
return object.Name
}
string name = GetName(c); // or GetNam
我试着在它的Scanner类上使用Java的方法来做一些简单的解析。基本上,每一行都是由“|”分隔的记录,例如:
2 | John Doe
3 | Jane Doe
4 | Jackie Chan
该方法接受要匹配的正则表达式作为参数。谁能提供给我的正则表达式,将匹配| (一个竖条分隔由一个空格在两边)。
谢谢,我真的很感激!
我在写一个蜘蛛。在这个爬行器中,我需要产生不同参数的请求。就像这样,
for i in xrange(0, len(products), k):
some_ids = ','.join([a_product['id'] for a_product in products[i: i + k]])
for a_condition in ['c1', 'c2', 'c3']:
yield CustomRequest(url='api:endpoint',