Hi Chongkai - <br><br>thanks for the helpful answers. I am reading up on the links right now and try to digest it. <br><br>At first I thought struct doesn't have custom constructor for validation logic until I saw guard-proc - so that should solve the data validation problem. So now the question is - should the parse/validation logic reside in readtable as well? Or is it okay to let readable construct the object, but only receive an error from the construction?
<br><br>Thanks,<br>yinso <br><br><div><span class="gmail_quote">On 5/8/07, <b class="gmail_sendername">Chongkai Zhu</b> <<a href="mailto:czhu@cs.utah.edu">czhu@cs.utah.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> You can do it in Scheme: define "ssn" as a structure in PLT Scheme, and<br>> then use Readtable (chapter 11.2.8 of MzScheme) and the built-in<br>> prop:custom-write structure type property to do read/write.
<br><br>To make "equal?" work is a little tricky. Normally you will need to<br>re-define "equal?":<br><br>(define (my-equal? p1 p2)<br> (if (and (ssn? p1)<br> (ssn? p2))<br> ;your code to tell whether two ssn equal?
<br> (equal? p1 p2)))<br><br>If you use modules, than you can creat your own language as a extension of<br>MzScheme: export "my-equal?" as "equal?", and everything else from MzScheme.<br><br>> Chongkai
<br>><br>> ----- Original Message -----<br>> From: YC<br>> To: mzscheme Mailing List<br>> Sent: Tuesday, May 08, 2007 1:44 PM<br>> Subject: [plt-scheme] how to creating a new "primitve type"<br>
><br>><br>> Hi all -<br>><br>> say that I want to create a new primitive type (something like path or<br>> string) so it has the first class status (for the lack of a better term)<br>> as the other primitive types. How is this done, and Is this doable only
<br>> in scheme or does it involve working on C code?<br>><br>> Example - social security number.<br>><br>>> (define s1 #ssn"123-45-6789")<br>>> s1<br>> #ssn"123-45-6789"<br>
>> (ssn->string s1)<br>> "123-45-6789"<br>>> (ssn? s1)<br>> #t<br>>> (equal? s1 #ssn"123-45-6789")<br>> #t<br>>> (equal? s1 #ssn"987-65-4321")<br>> #f<br>
><br>> Any pointer is appreciated ;) Thanks,<br>> yinso<br>><br>><br>><br>><br>><br>> _________________________________________________<br>> For list-related administrative tasks:<br>>
<a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>> _________________________________________________<br>> For list-related administrative tasks:
<br>> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>><br><br></blockquote></div><br>