Skip to content

каррирование#2

Open
dfdf11-cpu wants to merge 1 commit intomainfrom
curry_uncurry
Open

каррирование#2
dfdf11-cpu wants to merge 1 commit intomainfrom
curry_uncurry

Conversation

@dfdf11-cpu
Copy link
Owner

в файле содержится программа, которая реализует функцию каррирования(curry) и обратную к ней (uncurry).

@dfdf11-cpu dfdf11-cpu requested a review from chernishev October 26, 2025 19:43
Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

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

Добавьте корректную обработку ошибок: arity должно быть int, неотрицательным и не превышать реальное количество аргументов функции.

c = int(input("z: "))

if a < 0 or b < 0 or c < 0:
print("ОШИБКА: числа не могут быть отрицательными.")
Copy link

Choose a reason for hiding this comment

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

А почему числа не могут быть отрицательными?...

Да и ошибки надо выводить не через print

Comment on lines +1 to +14
def curry(func, arity):
def curried(*args):
if len(args) == arity:
return func(*args)
return lambda x: curried(*args, x)
return curried

def uncurry(curried_func, arity):
def uncurried(*args):
result = curried_func
for arg in args:
result = result(arg)
return result
return uncurried
Copy link

Choose a reason for hiding this comment

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

Не проверяется правильность количества аргументов, передаваемых функциям. Нужно это проверять и кидать соответствующие исключения, используя ключевое слово raise.

Comment on lines +19 to +30
a = int(input("x: "))
b = int(input("y: "))
c = int(input("z: "))

if a < 0 or b < 0 or c < 0:
print("ОШИБКА: числа не могут быть отрицательными.")
else:
sum3_curry = curry(sum3, 3)
sum3_uncurry = uncurry(sum3_curry, 3)

print("curry:", sum3_curry(a)(b)(c))
print("uncurry:", sum3_uncurry(a, b, c)) No newline at end of file
Copy link

Choose a reason for hiding this comment

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

По возможности оборачивать такое в if __name__ == "__main__"

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.

2 participants