Re: [racket-dev] class implementation and make-primitive-class
If a function takes 28 arguments, you probably overlooked a dozen or so. -- freely paraphrasing Perlis And you just made the best case for Typed Racket and the documentation argument :-) -- freely paraphrasing my own TR talk On Apr 17, 2014, at 2:49 PM, dfel...@ccs.neu.edu wrote: > For a course project I've been working on adding generators to contracts for > use with contract-random-generate, and I've been trying to construct classes > and objects from simple object/c contracts. When trying to find a way to > functionally create a class at runtime, I came across the > `make-primitive-class` function in class-internal.rkt. > > This function is exported, and available at a plain racket repl, but has no > documentation that I have been able to find and the comments about it in > class-internal.rkt seem to be incorrect. > > Trying to call it from the repl has problems also, for example (ignoring for > a moment that the arguments aren't of the expected types) > > -> (make-primitive-class #f #f 'foo object% null #f null null null null) > ; compose-class: arity mismatch; > ; the expected number of arguments does not match the given number > ; expected: 28 > ; given: 27 > > The definition is in terms of compose-class and is just missing a `null` > argument for the abstract-names, but even after fixing that in my local > branch there is a discrepancy with the comments regarding it's first argument > `make-struct:prim`. > > ; The `make-struct:prim' function takes prop:object, a class, > ; a preparer, a dispatcher function, an unwrap property, > ; an unwrapper, and a property assoc list, and produces: > ;* a struct constructor (must have prop:object) > ;* a struct predicate > ;* a struct type for derived classes (mustn't have prop:object) > ; > ; The supplied preparer takes a symbol and returns a num. > ; > ; The supplied dispatcher takes an object and a num and returns a method. > ; > ; The supplied unwrap property is used for adding the unwrapper > ; as a property value on new objects. > ; > ; The supplied unwrapper takes an object and returns the unwrapped > ; version (or the original object). > ; > ; When a primitive class has a superclass, the struct:prim maker > ; is responsible for ensuring that the returned struct items match > ; the supertype predicate. > > This suggests that make-struct:prim should take 7 arguments, but passing a > function of 7 arguments to it from the repl produces: > > -> (make-primitive-class (lambda (a b c d e f g) (values #f #f #f)) #f 'foo > object% null #f null null null null) > ; #: arity mismatch; > ; the expected number of arguments does not match the given number > ; expected: 7 > ; given: 5 > > Also as far as I can tell `make-primitive-class` is never used in the code > base, it is defined in class-internal.rkt, but can be commented out without > seeming to break anything else. Does anyone know if there is a purpose for > this function, or if there is documentation somewhere on the functions I need > to pass it in order to construct a class. I think I'm starting to get a > better idea of how it might work from reading more of class-internal.rkt and > how the class* macro expands, but any guidance would be appreciated. > > Thanks > Dan > > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] class implementation and make-primitive-class
That wouldn't work for this project because I need to be able to generate an object that satisfies a given Racket contract and can be passed to user functions that expect such an object so I need to use Racket's class system. I have a working prototype that builds class syntax then calls eval-syntax on it, I was just trying to figure out if there was an easy way to avoid using eval. Thanks again Dan - Original Message - From: "Neil Van Dyke" To: dfel...@ccs.neu.edu Cc: dev@racket-lang.org Sent: Thursday, April 17, 2014 4:17:54 PM GMT -05:00 US/Canada Eastern Subject: Re: [racket-dev] class implementation and make-primitive-class For purposes of your course project, couldn't you make your own class-instance object system, atop structs or hashes, that gives you whatever dynamic programming features you want? It's very-very easy to do a basic one (with single inheritance and single dispatch), until you get into speed optimizations. Or, if Swindle has a MOP, you could use that. Neil V. _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] class implementation and make-primitive-class
For purposes of your course project, couldn't you make your own class-instance object system, atop structs or hashes, that gives you whatever dynamic programming features you want? It's very-very easy to do a basic one (with single inheritance and single dispatch), until you get into speed optimizations. Or, if Swindle has a MOP, you could use that. Neil V. _ Racket Developers list: http://lists.racket-lang.org/dev
Re: [racket-dev] class implementation and make-primitive-class
The `make-primitive-class` function is a leftover from pre-v5.1 days, where the problem was to turn a C++ object into a Racket object. I'm not surprised that it has rotted away, it should be removed entirely, and I doubt that it's what you would want even if it worked. At Thu, 17 Apr 2014 14:49:40 -0400 (EDT), dfel...@ccs.neu.edu wrote: > For a course project I've been working on adding generators to contracts for > use with contract-random-generate, and I've been trying to construct classes > and objects from simple object/c contracts. When trying to find a way to > functionally create a class at runtime, I came across the > `make-primitive-class` function in class-internal.rkt. > > This function is exported, and available at a plain racket repl, but has no > documentation that I have been able to find and the comments about it in > class-internal.rkt seem to be incorrect. > > Trying to call it from the repl has problems also, for example (ignoring for > a > moment that the arguments aren't of the expected types) > > -> (make-primitive-class #f #f 'foo object% null #f null null null null) > ; compose-class: arity mismatch; > ; the expected number of arguments does not match the given number > ; expected: 28 > ; given: 27 > > The definition is in terms of compose-class and is just missing a `null` > argument for the abstract-names, but even after fixing that in my local > branch > there is a discrepancy with the comments regarding it's first argument > `make-struct:prim`. > > ; The `make-struct:prim' function takes prop:object, a class, > ; a preparer, a dispatcher function, an unwrap property, > ; an unwrapper, and a property assoc list, and produces: > ;* a struct constructor (must have prop:object) > ;* a struct predicate > ;* a struct type for derived classes (mustn't have prop:object) > ; > ; The supplied preparer takes a symbol and returns a num. > ; > ; The supplied dispatcher takes an object and a num and returns a method. > ; > ; The supplied unwrap property is used for adding the unwrapper > ; as a property value on new objects. > ; > ; The supplied unwrapper takes an object and returns the unwrapped > ; version (or the original object). > ; > ; When a primitive class has a superclass, the struct:prim maker > ; is responsible for ensuring that the returned struct items match > ; the supertype predicate. > > This suggests that make-struct:prim should take 7 arguments, but passing a > function of 7 arguments to it from the repl produces: > > -> (make-primitive-class (lambda (a b c d e f g) (values #f #f #f)) #f 'foo > object% null #f null null null null) > ; #: arity mismatch; > ; the expected number of arguments does not match the given number > ; expected: 7 > ; given: 5 > > Also as far as I can tell `make-primitive-class` is never used in the code > base, it is defined in class-internal.rkt, but can be commented out without > seeming to break anything else. Does anyone know if there is a purpose for > this > function, or if there is documentation somewhere on the functions I need to > pass it in order to construct a class. I think I'm starting to get a better > idea of how it might work from reading more of class-internal.rkt and how the > class* macro expands, but any guidance would be appreciated. > > Thanks > Dan > > _ > Racket Developers list: > http://lists.racket-lang.org/dev _ Racket Developers list: http://lists.racket-lang.org/dev
[racket-dev] class implementation and make-primitive-class
For a course project I've been working on adding generators to contracts for use with contract-random-generate, and I've been trying to construct classes and objects from simple object/c contracts. When trying to find a way to functionally create a class at runtime, I came across the `make-primitive-class` function in class-internal.rkt. This function is exported, and available at a plain racket repl, but has no documentation that I have been able to find and the comments about it in class-internal.rkt seem to be incorrect. Trying to call it from the repl has problems also, for example (ignoring for a moment that the arguments aren't of the expected types) -> (make-primitive-class #f #f 'foo object% null #f null null null null) ; compose-class: arity mismatch; ; the expected number of arguments does not match the given number ; expected: 28 ; given: 27 The definition is in terms of compose-class and is just missing a `null` argument for the abstract-names, but even after fixing that in my local branch there is a discrepancy with the comments regarding it's first argument `make-struct:prim`. ; The `make-struct:prim' function takes prop:object, a class, ; a preparer, a dispatcher function, an unwrap property, ; an unwrapper, and a property assoc list, and produces: ;* a struct constructor (must have prop:object) ;* a struct predicate ;* a struct type for derived classes (mustn't have prop:object) ; ; The supplied preparer takes a symbol and returns a num. ; ; The supplied dispatcher takes an object and a num and returns a method. ; ; The supplied unwrap property is used for adding the unwrapper ; as a property value on new objects. ; ; The supplied unwrapper takes an object and returns the unwrapped ; version (or the original object). ; ; When a primitive class has a superclass, the struct:prim maker ; is responsible for ensuring that the returned struct items match ; the supertype predicate. This suggests that make-struct:prim should take 7 arguments, but passing a function of 7 arguments to it from the repl produces: -> (make-primitive-class (lambda (a b c d e f g) (values #f #f #f)) #f 'foo object% null #f null null null null) ; #: arity mismatch; ; the expected number of arguments does not match the given number ; expected: 7 ; given: 5 Also as far as I can tell `make-primitive-class` is never used in the code base, it is defined in class-internal.rkt, but can be commented out without seeming to break anything else. Does anyone know if there is a purpose for this function, or if there is documentation somewhere on the functions I need to pass it in order to construct a class. I think I'm starting to get a better idea of how it might work from reading more of class-internal.rkt and how the class* macro expands, but any guidance would be appreciated. Thanks Dan _ Racket Developers list: http://lists.racket-lang.org/dev