[plt-scheme] how to creating a new "primitve type"
> You can do it in Scheme: define "ssn" as a structure in PLT Scheme, and
> then use Readtable (chapter 11.2.8 of MzScheme) and the built-in
> prop:custom-write structure type property to do read/write.
To make "equal?" work is a little tricky. Normally you will need to
re-define "equal?":
(define (my-equal? p1 p2)
(if (and (ssn? p1)
(ssn? p2))
;your code to tell whether two ssn equal?
(equal? p1 p2)))
If you use modules, than you can creat your own language as a extension of
MzScheme: export "my-equal?" as "equal?", and everything else from MzScheme.
> Chongkai
>
> ----- Original Message -----
> From: YC
> To: mzscheme Mailing List
> Sent: Tuesday, May 08, 2007 1:44 PM
> Subject: [plt-scheme] how to creating a new "primitve type"
>
>
> Hi all -
>
> say that I want to create a new primitive type (something like path or
> string) so it has the first class status (for the lack of a better term)
> as the other primitive types. How is this done, and Is this doable only
> in scheme or does it involve working on C code?
>
> Example - social security number.
>
>> (define s1 #ssn"123-45-6789")
>> s1
> #ssn"123-45-6789"
>> (ssn->string s1)
> "123-45-6789"
>> (ssn? s1)
> #t
>> (equal? s1 #ssn"123-45-6789")
> #t
>> (equal? s1 #ssn"987-65-4321")
> #f
>
> Any pointer is appreciated ;) Thanks,
> yinso
>
>
>
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>