Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure formula in Sequence is callable #52

Merged
merged 7 commits into from
Feb 15, 2019
Merged

Make sure formula in Sequence is callable #52

merged 7 commits into from
Feb 15, 2019

Conversation

william-song-shy
Copy link
Contributor

函数规格

def (x) # 返回第x个

@lin714093880

函数规格 
```python
def (x) # 返回第x个
@william-song-shy
Copy link
Contributor Author

其实就是把lambda 变成def

@william-song-shy
Copy link
Contributor Author

这样支持成块的函数(可能没啥用)

@moesoha
Copy link
Member

moesoha commented Feb 14, 2019

It's a breaking change. You'd better not to do so.

@william-song-shy
Copy link
Contributor Author

这是一个突破性的变化。你最好不要这样做。

why?

def __get_one(self, i):
if i in self.values:
return self.values[i]

self.values[i] = self.formula(i, self.__get_one)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove this argument here?

@@ -17,11 +19,12 @@ def __init__(self, formula, initial_values=()):
else:
raise Exception("Initial_values must be either a list/tuple or a dict.")


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra blank line

@william-song-shy
Copy link
Contributor Author

我删了空行

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

@william-song-shy Here is still a review left. PTAL.

@william-song-shy
Copy link
Contributor Author

您能说中文吗?

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

我在第 24 行的改动上还有一个 review。你这个改动打破了现有的 API 行为。

@william-song-shy
Copy link
Contributor Author

所以呢?

@william-song-shy
Copy link
Contributor Author

好的,我改成这样可以吧。 @moesoha

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

@william-song-shy 为什么要放弃第二个参数

@william-song-shy
Copy link
Contributor Author

看下新的吧(保持了lambda+第二个参数,对于使用def的只有一个参数)

@laosb
Copy link

laosb commented Feb 15, 2019

@william-song-shy 对于 lamda 保留参数也不影响的话,就不要做这个不必要的判断。

@william-song-shy
Copy link
Contributor Author

大佬觉得该怎样? @laosb

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

这里返回函数是用于像斐波那契这种递归定义的数列,所以返回的是 __get_one。就算是想传 def 定义的函数也是需要用的啊

@william-song-shy
Copy link
Contributor Author

我的想法

def f (x)
     return f(x-1)+f(x-2)

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

__get_one 有针对重复计算进行处理

@william-song-shy
Copy link
Contributor Author

就当我只加了一句异常和一个工具

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

@william-song-shy 判断lambda基本不需要,以及你把缩进都改了,还有code style也不一致

@moesoha
Copy link
Member

moesoha commented Feb 15, 2019

@william-song-shy 算了我来改吧

@moesoha moesoha changed the title 将序列的函数改为自定义函数 Make sure formula in Sequence is callable Feb 15, 2019
@moesoha moesoha merged commit fe4bfe8 into luogu-dev:master Feb 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants