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?

- 8,576
- 33
- 117
- 202
2 Answers
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!).

- 40,708
- 1
- 95
- 119
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.

- 19,370
- 5
- 54
- 56
-
1Are you thinking of `defstruct`? – Doug Currie Aug 08 '09 at 00:34
-
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 Aug 08 '09 at 07:22