I'm writing a Lisp variant in Go and want to define constants for Nil
and EmptyList
. These will be referenced throughout the codebase, but I want to prevent them from being accidentally re-defined.
// Representation of the empty list
var EmptyList = (*List)(nil)
I can't use a const
here for two reasons:
-
const
definitions cannot benil
-
const
definitions cannot be pointers
What options do I have to ensure EmptyList
is always the nil pointer?