views:

354

answers:

2

I'm trying to translate some Common Lisp code into Scheme code. The Common Lisp code has a deftype. Are deftypes in Scheme the same as deftypes in Common Lisp? How do you translate a deftype in Common Lisp into equivalent code in Scheme?

A: 

Common 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.

Anton Tykhyy
Are you thinking of `defstruct`?
Doug Currie
I wasn't thinking about anything specific. If you only need simple record types, you can throw together a macro for array-based records in half an hour.
Anton Tykhyy
+1  A: 

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!).

Doug Currie