{"id":2226,"date":"2019-07-13T18:08:43","date_gmt":"2019-07-13T17:08:43","guid":{"rendered":"http:\/\/fiber-space.de\/wordpress\/?p=2226"},"modified":"2022-10-12T12:02:31","modified_gmt":"2022-10-12T11:02:31","slug":"recursions-in-python-3-8","status":"publish","type":"post","link":"http:\/\/fiber-space.de\/wordpress\/2019\/07\/13\/recursions-in-python-3-8\/","title":{"rendered":"Recursions in Python 3.8"},"content":{"rendered":"<p>In Python 3.8 we can finally write short recursive functions:<\/p>\n<pre lang=\"python\">  \r\n>>> (fac := lambda n: (1 if n&lt;2 else n*fac(n-1)))\r\n at 0x000001AFD258D550>;\r\n>>> fac(4)\r\n24\r\n<\/pre>\n<p>In the same way we can define the notorious fixed point combinator<\/p>\n<pre lang=\"python\">>>> (Y:= lambda f: lambda *args: f(Y(f))(*args))\r\n at 0x000001AFD257E0D0>;\r\n>>> fac = lambda f: lambda n: (1 if n&lt;2 else n*f(n-1)) # fac in non recursive form \r\n>>> Y(fac)(4)\r\n24\r\n<\/pre>\n<p>Life is good again!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python 3.8 we can finally write short recursive functions: >>> (fac := lambda n: (1 if n&lt;2 else n*fac(n-1))) at 0x000001AFD258D550>; >>> fac(4) 24 In the same way we can define the notorious fixed point combinator >>> (Y:= lambda &hellip; <a href=\"http:\/\/fiber-space.de\/wordpress\/2019\/07\/13\/recursions-in-python-3-8\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/2226"}],"collection":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/comments?post=2226"}],"version-history":[{"count":28,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/2226\/revisions"}],"predecessor-version":[{"id":2318,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/posts\/2226\/revisions\/2318"}],"wp:attachment":[{"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/media?parent=2226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/categories?post=2226"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/fiber-space.de\/wordpress\/wp-json\/wp\/v2\/tags?post=2226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}