[plt-scheme] Defining structures

From: Stephen Bloch (sbloch at adelphi.edu)
Date: Wed Feb 18 11:22:59 EST 2009

On Feb 17, 2009, at 9:21 PM, aditya shukla wrote:

> So in other words can i say that define-struct will define the data  
> type and (define phonebook (make-entry 'PeterLee 15270 '606-7771))  
> would create a variable named phonebook of the data type entry?

Yes, pretty much, aside from the issue, already mentioned, that  
variables don't have data types; change your last few words to "would  
create a variable named phonebook containing a value of the data type  
entry."

In class, I use the analogy of an inventor and a factory.  If you  
invent a new kind of cell phone, or video game, or whatever, what you  
actually produce is not a cell phone but the BLUEPRINTS or PLANS for  
a cell phone.  Only once the plans have been written down can  
somebody build a factory that churns out thousands of cell phones to  
your plan.

"define-struct" is an INVENTOR.  It doesn't produce phonebook  
entries, but one of the things it produces is a FACTORY (named "make- 
entry") which can then be used to churn out as many phonebook entries  
as you wish.


Stephen Bloch
sbloch at adelphi.edu



Posted on the users mailing list.