Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/26.10.2025/curry_uncurry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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
Comment on lines +1 to +14
Copy link

Choose a reason for hiding this comment

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

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


def sum3(x, y, z):
return x + y + z

a = int(input("x: "))
b = int(input("y: "))
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

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))
Comment on lines +19 to +30
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__"