Typechecking Mutual Recursion

47 views
Skip to first unread message

Dallin Dahl

unread,
Jul 22, 2025, 9:16:07 AMJul 22
to Shen
First of all, thank you all very much for some wonderful technology and ideas.

Is there some way to forward declare types?  I'm having trouble typechecking the even? and odd? functions from The Book of Shen.

--Dallin

dr.mt...@gmail.com

unread,
Jul 22, 2025, 2:15:48 PMJul 22
to Shen
If you are running Shen with stlib, you may have a problem with that
example, because odd? and even? are stlib functions.  So rename them
my-odd? and my-even?   TBoS, in main, was written long before stlib
evolved.  If you are working with the shen kernel alone, you'll have no
problem.

That said, you can't paste mutually recursive functions into the REPL
if you want to type check them, but need to put them in a file and load
the file.

M.

Dallin Dahl

unread,
Jul 22, 2025, 4:44:45 PMJul 22
to qil...@googlegroups.com
That confirms my suspicions. It looks like it also works if you put both
inside a package. I wrote a macro to support that. I tend to work back
and forth between a buffer and a live repl, so this seems to work better.

(defmacro mutual-recursion
[mutual | Body] ->
[package null [] | (map (/. X (cons define X)) Body)])

Thanks again for your help!

--Dallin
Reply all
Reply to author
Forward
0 new messages