I'm trying to translate some Common Lisp code into Scheme code. The Common Lisp code has a deftype
. Are deftype
s in Scheme the same as deftype
s in Common Lisp? How do you translate a deftype
in Common Lisp into equivalent code in Scheme?
views:
354answers:
2Common Lisp deftype
doesn't have an exact Scheme equivalent. You will have to translate type definitions by hand, or write a deftype
macro in terms of whatever Scheme record library is available in your system.
Bare Scheme doesn't have user-defined types at all. In an R5RS system, you will have to look up the relevant SRFIs (e.g. SRFI-9 (Record types), SRFI-57 Records, SRFI-99 ERR5RS records) and also see what SRFIs and language extensions does your particular Scheme system implement; Scheme systems generally aren't very consistent in their implementations of anything beyond the minimal Scheme standard. R6RS Scheme has records in its standard library.
As Anton says, there is no exact Scheme equivalent to Common Lisp deftype
. See CLHS:Type Specifiers for a description of what a type specifier can be in Common Lisp. These are used in declarations, array type specifications, struct and CLOS slot specifications, generic function argument specialization, and on and on. Porting this to Scheme generally will be a monumental challenge. Your best hope is that the types defined by deftype
are used only trivially (or not at all!).