Hi!
I've been figuring out all the attributes available with define-type in Gambit. Testing and thanks to:
https://mercure.iro.umontreal.ca/pipermail/gambit-list/attachments/20090226/... https://mercure.iro.umontreal.ca/pipermail/gambit-list/2004-December/000043....
I could understand all but one: opaque. The ways to "learn" how things work with macros producing code is generally the trick (pp (lambda () (macro...)) 'asdf). But what about macros that produce macros? In that case you get an empty form with 'asdf, so no way to know what has been generated.
That of course applies to define-type. There is no difference in generated code with opaque: keyword, so I assume that it only affects non-generative types. Can I see the generated code in such case?
Reading Gambit's code in nonstd.scm doesn't clarify things either.
Thank you!
Afficher les réponses par date
On Apr 15, 2014, at 9:59 AM, Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com wrote:
Hi!
I've been figuring out all the attributes available with define-type in Gambit. Testing and thanks to:
https://mercure.iro.umontreal.ca/pipermail/gambit-list/attachments/20090226/... https://mercure.iro.umontreal.ca/pipermail/gambit-list/2004-December/000043....
I could understand all but one: opaque. The ways to "learn" how things work with macros producing code is generally the trick (pp (lambda () (macro...)) 'asdf). But what about macros that produce macros? In that case you get an empty form with 'asdf, so no way to know what has been generated.
That of course applies to define-type. There is no difference in generated code with opaque: keyword, so I assume that it only affects non-generative types. Can I see the generated code in such case?
Reading Gambit's code in nonstd.scm doesn't clarify things either.
Thank you!
Try:
(set! ##define-type-expansion-show? #t)
Marc
That's an awesome trick, Marc. Thanks!
But still.. I don't see any difference:
(define-type context
id: a0000000-0000-0000-0000-000000000000 constructor: macro-make-context macros:
;; opaque: WITHOUT OPAQUE unprintable: a)
(begin (##define-macro (macro-make-context p1) (##list '(let () (##declare (extended-bindings)) ##structure) ''#<type #19 context> p1)) (##define-macro (make-constant-context p1) (##define-type-construct-constant 'make-constant-context '#<type #19 context> p1)) (##define-macro (context? obj) `((let () (##declare (extended-bindings)) ##structure-direct-instance-of?) ,obj ,''##type-1-a0000000-0000-0000-0000-000000000000)) (##define-macro (context-a obj) (##list '(let () (##declare (extended-bindings)) ##direct-structure-ref) obj 1 ''#<type #19 context> #f)) (##define-macro (context-a-set! obj val) (##list '(let () (##declare (extended-bindings)) ##direct-structure-set!) obj val 1 ''#<type #19 context> #f)))
(define-type context
id: a0000000-0000-0000-0000-000000000000 constructor: macro-make-context macros: opaque: ;; WITH OPAQUE unprintable: a)
(begin (##define-macro (macro-make-context p1) (##list '(let () (##declare (extended-bindings)) ##structure) ''#<type #20 context> p1)) (##define-macro (make-constant-context p1) (##define-type-construct-constant 'make-constant-context '#<type #20 context> p1)) (##define-macro (context? obj) `((let () (##declare (extended-bindings)) ##structure-direct-instance-of?) ,obj ,''##type-1-a0000000-0000-0000-0000-000000000000)) (##define-macro (context-a obj) (##list '(let () (##declare (extended-bindings)) ##direct-structure-ref) obj 1 ''#<type #20 context> #f)) (##define-macro (context-a-set! obj val) (##list '(let () (##declare (extended-bindings)) ##direct-structure-set!) obj val 1 ''#<type #20 context> #f)))
There is no difference! I noticed that some attributes produce no difference in the output, but will somehow set some internal flag of Gambit. That's the case of :unprintable, which makes a difference when pretty-printing the object but produces no difference in the generated function/macros. If this is the case, what does opaque: actually do?
Thanks a lot!
Álvaro Castro-Castilla Digital Experiences. -- visit The Bloghttp://blog.fourthbit.com/
On Tue, Apr 15, 2014 at 4:57 PM, Marc Feeley feeley@iro.umontreal.cawrote:
On Apr 15, 2014, at 9:59 AM, Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com> wrote:
Hi!
I've been figuring out all the attributes available with define-type in
Gambit. Testing and thanks to:
https://mercure.iro.umontreal.ca/pipermail/gambit-list/attachments/20090226/...
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2004-December/000043....
I could understand all but one: opaque. The ways to "learn" how things
work with macros producing code is generally the trick (pp (lambda () (macro...)) 'asdf). But what about macros that produce macros? In that case you get an empty form with 'asdf, so no way to know what has been generated.
That of course applies to define-type. There is no difference in
generated code with opaque: keyword, so I assume that it only affects non-generative types. Can I see the generated code in such case?
Reading Gambit's code in nonstd.scm doesn't clarify things either.
Thank you!
Try:
(set! ##define-type-expansion-show? #t)
Marc
Hi,
Although this may seem a very obvious question, none of the obvious answers are true. I think many Gambit users would benefit of really knowing how to use this, since there is barely any code that you can use as reference, no documentation and no google results:
https://github.com/search?l=Scheme&q=opaque%3A&ref=advsearch&typ... https://www.google.es/search?q=gambit+opaque&oq=gambit+opa&aqs=chrom...
False hypothesis I could come up with:
* Opaque types make their fields not accessible to extending types so you can't access them using the parent type's procedures * Opaque types make the fields unprintable by default * Opaque types have R6RS semantics: [The opaque? flag must be a boolean. If true, the record type is opaque. If passed an instance of the record type, record? returns #f. Moreover, if record-rtd (see “Inspection” below) is called with an instance of the record type, an exception with condition type &assertion is raised. The record type is also opaque if an opaque parent is supplied. If opaque? is #f and an opaque parent is not supplied, the record is not opaque.] This doesn't hold true either for Gambit's types and you don't have such inspection procedures. * Opaque makes the predicates yield #f for instances of the type always * Opaque makes the predicates of the parent types yield #f for inherited types' instance * Opaque disables the generation of a type exhibitor * Opaque generates different code somehow. At least, I can't see a single difference. * Opaque types can't be serialized and deserialized with object->u8vector
Is there any other obvious possibility that I'm missing out?
Thank you
On Tue, Apr 15, 2014 at 8:54 PM, Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com> wrote:
That's an awesome trick, Marc. Thanks!
But still.. I don't see any difference:
(define-type context
id: a0000000-0000-0000-0000-000000000000 constructor: macro-make-context macros:
;; opaque: WITHOUT OPAQUE unprintable: a)
(begin (##define-macro (macro-make-context p1) (##list '(let () (##declare (extended-bindings)) ##structure) ''#<type #19 context> p1)) (##define-macro (make-constant-context p1) (##define-type-construct-constant 'make-constant-context '#<type #19 context> p1)) (##define-macro (context? obj) `((let () (##declare (extended-bindings)) ##structure-direct-instance-of?) ,obj ,''##type-1-a0000000-0000-0000-0000-000000000000)) (##define-macro (context-a obj) (##list '(let () (##declare (extended-bindings)) ##direct-structure-ref) obj 1 ''#<type #19 context> #f)) (##define-macro (context-a-set! obj val) (##list '(let () (##declare (extended-bindings)) ##direct-structure-set!) obj val 1 ''#<type #19 context> #f)))
(define-type context
id: a0000000-0000-0000-0000-000000000000 constructor: macro-make-context macros: opaque: ;; WITH OPAQUE unprintable: a)
(begin (##define-macro (macro-make-context p1) (##list '(let () (##declare (extended-bindings)) ##structure) ''#<type #20 context> p1)) (##define-macro (make-constant-context p1) (##define-type-construct-constant 'make-constant-context '#<type #20 context> p1)) (##define-macro (context? obj) `((let () (##declare (extended-bindings)) ##structure-direct-instance-of?) ,obj ,''##type-1-a0000000-0000-0000-0000-000000000000)) (##define-macro (context-a obj) (##list '(let () (##declare (extended-bindings)) ##direct-structure-ref) obj 1 ''#<type #20 context> #f)) (##define-macro (context-a-set! obj val) (##list '(let () (##declare (extended-bindings)) ##direct-structure-set!) obj val 1 ''#<type #20 context> #f)))
There is no difference! I noticed that some attributes produce no difference in the output, but will somehow set some internal flag of Gambit. That's the case of :unprintable, which makes a difference when pretty-printing the object but produces no difference in the generated function/macros. If this is the case, what does opaque: actually do?
Thanks a lot!
Álvaro Castro-Castilla Digital Experiences. -- visit The Blog<http://blog.fourthbit.com/>
On Tue, Apr 15, 2014 at 4:57 PM, Marc Feeley feeley@iro.umontreal.cawrote:
On Apr 15, 2014, at 9:59 AM, Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com> wrote:
Hi!
I've been figuring out all the attributes available with define-type in
Gambit. Testing and thanks to:
https://mercure.iro.umontreal.ca/pipermail/gambit-list/attachments/20090226/...
https://mercure.iro.umontreal.ca/pipermail/gambit-list/2004-December/000043....
I could understand all but one: opaque. The ways to "learn" how things
work with macros producing code is generally the trick (pp (lambda () (macro...)) 'asdf). But what about macros that produce macros? In that case you get an empty form with 'asdf, so no way to know what has been generated.
That of course applies to define-type. There is no difference in
generated code with opaque: keyword, so I assume that it only affects non-generative types. Can I see the generated code in such case?
Reading Gambit's code in nonstd.scm doesn't clarify things either.
Thank you!
Try:
(set! ##define-type-expansion-show? #t)
Marc
On Apr 21, 2014, at 6:38 AM, Álvaro Castro-Castilla alvaro.castro.castilla@gmail.com wrote:
Hi,
Although this may seem a very obvious question, none of the obvious answers are true. I think many Gambit users would benefit of really knowing how to use this, since there is barely any code that you can use as reference, no documentation and no google results:
https://github.com/search?l=Scheme&q=opaque%3A&ref=advsearch&typ... https://www.google.es/search?q=gambit+opaque&oq=gambit+opa&aqs=chrom...
False hypothesis I could come up with:
- Opaque types make their fields not accessible to extending types so you can't access them using the parent type's procedures
- Opaque types make the fields unprintable by default
- Opaque types have R6RS semantics: [The opaque? flag must be a boolean. If true, the record type is opaque. If passed an instance of the record type, record? returns #f. Moreover, if record-rtd (see “Inspection” below) is called with an instance of the record type, an exception with condition type &assertion is raised. The record type is also opaque if an opaque parent is supplied. If opaque? is #f and an opaque parent is not supplied, the record is not opaque.] This doesn't hold true either for Gambit's types and you don't have such inspection procedures.
- Opaque makes the predicates yield #f for instances of the type always
- Opaque makes the predicates of the parent types yield #f for inherited types' instance
- Opaque disables the generation of a type exhibitor
- Opaque generates different code somehow. At least, I can't see a single difference.
- Opaque types can't be serialized and deserialized with object->u8vector
Is there any other obvious possibility that I'm missing out?
Thank you
The opaque: flag causes a change in the behavior of equal? and equal?-hash . When the opaque: flag is not used, two structures are equal? if they have the same type and each field is equal? in both structures. When the opaque: flag is used, two structures are equal? only if they are eq? (i.e. the same instance).
Here’s an example:
(define-type foo opaque: a b )
(define x (make-foo 11 22)) (define y (make-foo 11 22))
(pp x) (pp y)
(pp (equal? x y))
(pp (equal?-hash x)) (pp (equal?-hash y))
;; prints: ;; #<foo #2 a: 11 b: 22> ;; #<foo #3 a: 11 b: 22> ;; #f ;; 2 ;; 3
;; without the opaque: flag prints: ;; #<foo #2 a: 11 b: 22> ;; #<foo #3 a: 11 b: 22> ;; #t ;; 206628681 ;; 206628681
Marc
The opaque: flag causes a change in the behavior of equal? and equal?-hash . When the opaque: flag is not used, two structures are equal? if they have the same type and each field is equal? in both structures. When the opaque: flag is used, two structures are equal? only if they are eq? (i.e. the same instance).
Awesome and very useful! So the code that checks for the opaque: flag in the Gambit sources is found in the equal? and equal-hash? definitions...
Thank you, Marc
Dear Alvaro, can you please write up your insights on define-type on the Wiki? I believe there's a page already somewhere so it's just about clarifying and adding. Mikael
2014-05-01 10:45 GMT+02:00 Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com>:
The opaque: flag causes a change in the behavior of equal? and equal?-hash . When the opaque: flag is not used, two structures are equal? if they have the same type and each field is equal? in both structures. When the opaque: flag is used, two structures are equal? only if they are eq? (i.e. the same instance).
Awesome and very useful! So the code that checks for the opaque: flag in the Gambit sources is found in the equal? and equal-hash? definitions...
Thank you, Marc
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Hi,
I've been working on the documentation for the object systems provided in SchemeSpheres here: http://www.schemespheres.org/guides/en/object-systems
I'll copy the meaning of the flag attributes and link to this documentation as well for reference.
Álvaro Castro-Castilla Digital Experiences. -- visit The Bloghttp://blog.fourthbit.com/
On Fri, May 2, 2014 at 11:31 AM, Mikael mikael.rcv@gmail.com wrote:
Dear Alvaro, can you please write up your insights on define-type on the Wiki? I believe there's a page already somewhere so it's just about clarifying and adding. Mikael
2014-05-01 10:45 GMT+02:00 Álvaro Castro-Castilla < alvaro.castro.castilla@gmail.com>:
The opaque: flag causes a change in the behavior of equal? and equal?-hash . When the opaque: flag is not used, two structures are equal? if they have the same type and each field is equal? in both structures. When the opaque: flag is used, two structures are equal? only if they are eq? (i.e. the same instance).
Awesome and very useful! So the code that checks for the opaque: flag in the Gambit sources is found in the equal? and equal-hash? definitions...
Thank you, Marc
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list