|
|
 |
 |
 |
 |
Scheme Programming Language
|
 |
 |
 |
 |
 |
 |
 |
 |
Is it possible to define-syntax "define-struct" ?
hi Is it possible to define-syntax "define-struct" ? Mit scheme don't have mzscheme type define-struct. thanks
On Mar 29, 2:08 am, "maina@gmail.com" <maina@gmail.com> wrote: > Is it possible to define-syntax "define-struct" ?
Do you mean the "define-struct" like the one described in the following URL? http://pre.plt-scheme.org/docs/html/beginning/define-struct.html To do that, you need two things: 1. A suitable representation for the struct types. 2. A macro system. > Mit scheme don't have mzscheme type define-struct.
I don't know much about MIT Scheme but here is the general idea. If your Scheme system provides the means for creating new record/ struct types, then you can use that as a basis for the representation of your structs. Otherwise, tagged vectors (i.e. vectors where the first element is a descriptor for the struct type) may work ok. If your want "define-struct" to construct the constructor, predicate, accessors and setters names for you, then you need a macro system that has that capability. A syntax-case system would work nicely. If all you have is syntax-rules, then you need to specify the names of all the procedures in the define-struct form. This would make define- struct forms look something like: (define-struct foo make-foo foo? (foo-bar set-foo-bar!) (foo-baz set-foo-baz!) ...) instead of the much shorter form: (define-struct foo (bar baz ...)) Does this answer your question? Let us know if you have any troubles. Aziz,,,
On Mar 29, 2:40 pm, "Abdulaziz Ghuloum" <aghul@gmail.com> wrote:
> On Mar 29, 2:08 am, "maina @gmail.com" <maina @gmail.com> wrote: > > Is it possible to define-syntax "define-struct" ? > Do you mean the "define-struct" like the one described in the > following URL? > http://pre.plt-scheme.org/docs/html/beginning/define-struct.html > To do that, you need two things: > 1. A suitable representation for the struct types. > 2. A macro system. > > Mit scheme don't have mzscheme type define-struct. > I don't know much about MIT Scheme but here is the general idea. > If your Scheme system provides the means for creating new record/ > struct types, then you can use that as a basis for the representation > of your structs. Otherwise, tagged vectors (i.e. vectors where the > first element is a descriptor for the struct type) may work ok. > If your want "define-struct" to construct the constructor, predicate, > accessors and setters names for you, then you need a macro system that > has that capability. A syntax-case system would work nicely. If all > you have is syntax-rules, then you need to specify the names of all > the procedures in the define-struct form. This would make define- > struct forms look something like: > (define-struct foo make-foo foo? > (foo-bar set-foo-bar!) > (foo-baz set-foo-baz!) > ...) > instead of the much shorter form: > (define-struct foo (bar baz ...)) > Does this answer your question? Let us know if you have any troubles.
Mit scheme don't have any define-struct. Do you know what's the last field "#f" mean in "(define-struct term (tag exprs) #f)"? the default value? Thanks. I will think about how to get around this.
maina @gmail.com writes: > Mit scheme don't have any define-struct. When I put to Google the three words "mit scheme record", I get back this: # MIT Scheme provides a record abstraction, which is a simple and # flexible mechanism for building structures with named # components. Records can be defined and ... It may be just referring to the same thing with a different name. Look for records.
On Mar 29, 12:08 am, "maina@gmail.com" <maina@gmail.com> wrote: > hi > Is it possible to define-syntax "define-struct" ? > Mit scheme don't have mzscheme type define-struct. > thanks
Teach yourself scheme in fixnum days shows a macro for define-struct, but it uses define-macro/defmacro instead of define-syntax. I don't know if MIT supports that. Brad
Abdulaziz Ghuloum wrote: > On Mar 29, 2:08 am, "maina @gmail.com" <maina @gmail.com> wrote: >> Is it possible to define-syntax "define-struct" ? > Do you mean the "define-struct" like the one described in the > following URL? > http://pre.plt-scheme.org/docs/html/beginning/define-struct.html > To do that, you need two things: > 1. A suitable representation for the struct types. > 2. A macro system. >> Mit scheme don't have mzscheme type define-struct. > I don't know much about MIT Scheme but here is the general idea. > If your Scheme system provides the means for creating new record/ > struct types, then you can use that as a basis for the representation > of your structs. Otherwise, tagged vectors (i.e. vectors where the > first element is a descriptor for the struct type) may work ok. > If your want "define-struct" to construct the constructor, predicate, > accessors and setters names for you, then you need a macro system that > has that capability. A syntax-case system would work nicely. If all > you have is syntax-rules, then you need to specify the names of all > the procedures in the define-struct form. This would make define- > struct forms look something like: > (define-struct foo make-foo foo? > (foo-bar set-foo-bar!) > (foo-baz set-foo-baz!) > ...) > instead of the much shorter form: > (define-struct foo (bar baz ...)) > Does this answer your question? Let us know if you have any troubles. > Aziz,,,
Another approach addressed here: http://okmij.org/ftp/Scheme/define-struct.html Basically, with plt/chez <<use define-record in chez>> (define-struct FOO ...) defines 3+ procedures: make-FOO, FOO-fieldname (1 for each field) and FOO?. The above link describes a syntax for define-struct in which (define-struct FOO ...) creates a new syntax FOO which works like this: (FOO make ...) (FOO fieldname ...) (FOO ? ...) The (FOO ...) form is then expanded to the proper procedure based on the first argument (using the term "argument" loosely). regards, Nate T.
|
 |
 |
 |
 |
|