https://docs.python.org/3/whatsnew/3.10.html#pep-634-structural-pattern-matching

"PEP 636 -- Structural Pattern Matching: Tutorial"
https://www.python.org/dev/peps/pep-0636/

"Computational Fairy Tales: Computer science concepts as told through fairy
tales." http://computationaltales.blogspot.com/

There's a book:
https://www.goodreads.com/en/book/show/15891129-computational-fairy-tales

On Sat, Nov 20, 2021, 13:17 kirby urner <kirby.ur...@gmail.com> wrote:

>
> I've since done it in hoon, taught as "martian computing" at University of
> Illinois.
>
> https://github.com/davis68/martian-computing
>
> Hoon version:
> https://flic.kr/p/2mKTPas
>
> (base) Kirbys-MacBook-Pro:base mac$ cd gen
> (base) Kirbys-MacBook-Pro:gen mac$ cat crystalball.hoon
> !:
> ::  Crystal Ball Numbers
> ::  https://oeis.org/A005902
> ::
> |=  n=@ud
> ^-  @ud
> ?:  =(n 0)
>   1
> (add (add (mul 10 (mul n n)) 2) $(n (dec n)))
> (base) Kirbys-MacBook-Pro:gen mac$
>
> In my world, it's the crystal ball sequence that's front and center,
> orthogonal to the computer language.  Maybe that's because OEIS
> https://oeis.org/A005901 and https://oeis.org/A005902 both link back to
> my website and I tend to use my own websites to teach my stuff (imagine
> that).
>
> I don't think my Hoon version is tail recursive, but it could be, by a
> more experienced hand.  I just heard of Hoon a couple days ago.  Hoon is a
> functional system language that compiles to a LISP (nock) and does know the
> difference between tail call vs stack deepening.  Python doesn't.
>
> Python points out you often don't need recursion at all (including in this
> case) and that recursion isn't maybe as super cool as it thinks it is.
> I've got the non-recursive versions on REPL.
>
> Anyway, the computer science angle is important, not just the Blender /
> CAD / CAM.
>
> Kirby
>
>
> On Tue, Nov 16, 2021 at 5:58 PM kirby urner <kirby.ur...@gmail.com> wrote:
>
>>
>> So are we encouraged to use match-case in recursion instead of if-else?
>>
>> It's more readable this way maybe:
>>
>> cubocta310.py:
>>
>> def cubocta(n):
>>     """
>>     https://oeis.org/A005902
>>     """
>>     match n:
>>         case 0: return 1
>>         case _: return (10*n*n + 2) + cubocta(n - 1)
>>
>> print([cubocta(i) for i in range(10)])
>>
>> (py310) Kirbys-MacBook-Pro:School_of_Tomorrow mac$ python cubocta310.py
>> [1, 13, 55, 147, 309, 561, 923, 1415, 2057, 2869]
>>
>> https://flic.kr/p/2mKh2nd
>> (image version)
>>
>> Kirby
>>
>> _______________________________________________
> Edu-sig mailing list -- edu-sig@python.org
> To unsubscribe send an email to edu-sig-le...@python.org
> https://mail.python.org/mailman3/lists/edu-sig.python.org/
> Member address: wes.tur...@gmail.com
>
_______________________________________________
Edu-sig mailing list -- edu-sig@python.org
To unsubscribe send an email to edu-sig-le...@python.org
https://mail.python.org/mailman3/lists/edu-sig.python.org/
Member address: arch...@mail-archive.com

Reply via email to