Hack Forums
[Python] Scheme code to python (Von Neumann Natural Numbers) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Scheme code to python (Von Neumann Natural Numbers) (/showthread.php?tid=6194134)



Scheme code to python (Von Neumann Natural Numbers) - simmer - Feb 18, 2022

Hi guys!

I have this code in scheme:

Code
(define von-neumann
  (lambda (n)
    (if (zero? n)
        '()
        (let ((n-1 (von-neumann (- n 1))))
          (append n-1 (list n-1))))))


1 ]=> (for-each
(lambda (n)
  (newline)
  (display n)
  (display (length n)))
(map von-neumann (iota 5 0 1)))
()0
(())1
(() (()))2
(() (()) (() (())))3
(() (()) (() (())) (() (()) (() (()))))4
;Unspecified return value

That I would like to see in python

Help out?

Thanks,
Oliver