小编jon*_*eto的帖子

包含多个带docopt的参数列表

我正在使用我的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)

我该怎么办?

python command-line-interface command-line-arguments docopt

8
推荐指数
1
解决办法
1822
查看次数

为自定义Pony编写选择函数

很多时候,我写了如下的查询:

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方法可以接受的参数一样.

python python-2.7 ponyorm

5
推荐指数
1
解决办法
531
查看次数

Haskell函数中的模式匹配

我有很多方法在其定义中有样板代码,请看上面的例子.

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 pattern-matching

2
推荐指数
1
解决办法
228
查看次数

不同类型的元组

有没有办法在Haskell中有一个没有相同类型的对的列表,并使函数遍历它.例如:

a = [(1, "uno"), (2, True), (3, 5)]
Run Code Online (Sandbox Code Playgroud)

想要根据第二个值的类型应用函数,类似于评估对的组合的函数 f :: [(Int, #)] -> [a].

haskell

1
推荐指数
2
解决办法
430
查看次数

关于succ函数的图像

我通常将自然数定义为:

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)

我想有以下内容.

  • 将不允许零作为输入的前驱函数定义为其后继函数.所以下一个是无效的.
pred : Nat ? Nat
pred zero  = zero
pred (succ n) = n
Run Code Online (Sandbox Code Playgroud)
  • 我想有一个名为Z⁺的变量代表正数但在其定义中使用后继函数的图像(上面定义的Image_∋_数据类型).

agda

1
推荐指数
1
解决办法
167
查看次数