Subject: Re: Free book for converting my C mind?
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 18 Feb 2004 02:44:32 -0600
Newsgroups: comp.lang.lisp
Message-ID: <Ts6dne2ZXIJtuK7dXTWc-g@speakeasy.net>
Marco Antoniotti  <marcoxa@cs.nyu.edu> wrote:
+---------------
| Since we are at it... :)
| What is the translation in Scheme of the Common Lisp
| 	(defstruct foo
| 	   (a 42 :type integer)
| 	   (b "foo" :type string))
+---------------

As in the other example, it depends on what you restrict yourself to:

1. For either IEEE Scheme [IEEE Std. 1178-1990 (R2002)] or
   R5RS Scheme (1998): There is no translation. Standard Schemes
   do not include structures.

2. Specific implementation extensions: Many, various, idiosyncratic,
   some with typing and some not.

   For example, PLT DrScheme/MzScheme provides both simple untyped-slot
   structures <URL:http://download.plt-scheme.org/doc/206p1/html/mzscheme/
   mzscheme-Z-H-4.html>, for which the translation would be as follows
   [not shown is the single-inheritance case, where the first arg is a
   two-element list]:

	(define-struct foo a b)

   and typed-slot structures <URL:http://download.plt-scheme.org/doc/
   206p1/html/mzscheme/mzscheme-Z-H-4.html> with some "property" stuff
   I really don't understand, but if you define your own accessors you
   can associate an optional "guard-proc", which:

	...is called by make-struct-type before attaching the property
	to a new structure type. ... To reject a property association
	(e.g., because the value supplied to make-struct-type is
	inappropriate for the property), the guard can raise an exception.
	...

   Maybe that can be used to enforce slot value typing, I dunno...


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607