Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's a typecheck function in the standard library, but with no documentation in the Bel source anywhere it's hard to know what it does.

For people like me who want static typing and a powerful type system to catch errors, does lisp have anything to offer? My understanding is that it predates decent type systems and lisps will always be genealogically much closer to Python than, say, a Haskell or even a Kotlin.



What this

  (def typecheck ((var f) arg env s r m)
    (mev (cons (list (list f (list 'quote arg)) env)
               (fu (s r m)
                 (if (car r)
                     (pass var arg env s (cdr r) m)
                     (sigerr 'mistype s r m)))
               s)
         r
         m))
says is, first create a function call

  (list f (list 'quote arg))
in which the function describing the type (e.g. int) is called on the argument that came in for that parameter. Its value will end up on the return value stack, r. So in the next step you look at the first thing on the return value stack

  (car r)
If it's true, you keep going as if the parameter had been a naked one, with no type restriction

  (pass var arg env s (cdr r) m)
and if it's false, you signal an error

  (sigerr 'mistype s r m)


Yeah you can do optional static typing in common lisp: https://medium.com/@MartinCracauer/static-type-checking-in-t...

The typing discipline in strong. I think it also has type inference but I'm not 100% sure




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: