我正在使用我的python应用程序作为命令行工具,功能docopt库.使用该库实现命令很容易.但是,目前我无法找到完成以下要求的方法:
文档字符串是:
"""
aTXT tool
Usage:
aTXT <source>... [--ext <ext>...]
Options:
--ext message
"""
Run Code Online (Sandbox Code Playgroud)
从shell,我想写这样的东西:
atxt a b c --ext e f g
Run Code Online (Sandbox Code Playgroud)
docopt输出的结果字典如下:
{'--ext': True,
'<ext>': [],
'<source>': ['a', 'b', 'c', 'e', 'f']}
Run Code Online (Sandbox Code Playgroud)
但是,我需要具备以下条件:
{'--ext': True,
'<ext>': ['e', 'f', 'g'],
'<source>': ['a', 'b', 'c']}
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
很多时候,我写了如下的查询:
pony.orm.select(u for u in User if u.available and u.friends > 0 and ...)
Run Code Online (Sandbox Code Playgroud)
所以,我想编写自己的版本select,替代它.有些事情是为了避免我每次写出谓词的第一部分,if u.available and u.friends > 0.
我的问题更为笼统:如何编写一个函数,就像select它接受select方法或count方法可以接受的参数一样.
我有很多方法在其定义中有样板代码,请看上面的例子.
replace:: Term -> Term -> Formula -> Formula
replace x y (Not f) = Not $ replace x y f
replace x y (And f g) = And (replace x y f) (replace x y g)
replace x y (Or f g) = Or (replace x y f) (replace x y g)
replace x y (Biimp f g) = Biimp (replace x y f) (replace x y g)
replace x y (Imp f g) = Imp (replace x y …Run Code Online (Sandbox Code Playgroud) 有没有办法在Haskell中有一个没有相同类型的对的列表,并使函数遍历它.例如:
a = [(1, "uno"), (2, True), (3, 5)]
Run Code Online (Sandbox Code Playgroud)
想要根据第二个值的类型应用函数,类似于评估对的组合的函数 f :: [(Int, #)] -> [a].
我通常将自然数定义为:
data Nat : Set where
zero : Nat
succ : Nat ? Nat
Run Code Online (Sandbox Code Playgroud)
即第一名应该是
one : Nat
one = succ zero
Run Code Online (Sandbox Code Playgroud)
稍后,我们可以定义image数据类型,
data Image_?_ {A B : Set} (f : A ? B) : B -> Set where
im : (x : A) ? Image f ? (f x)
Run Code Online (Sandbox Code Playgroud)
为了证明类似"一个在继承函数的形象中",我写道:
one-succ : Image succ ? one
one-succ = im zero
Run Code Online (Sandbox Code Playgroud)
我想有以下内容.
Run Code Online (Sandbox Code Playgroud)pred : Nat ? Nat pred zero = zero pred (succ n) = n