Just as a side comment, the more usual OO way (less 'hacky') to do that kind of things is to define a specific interface that contains a set of method declarations, and make the class implement this interface (or none actually, in which case the interface is used only as a tag). Then you can test whether a given object is of this interface with `is-a?`. Several methods can be of course be declared in the same interface. I would suspect that some people believe that using `defined?` reveals a design issue, in general. For your particular needs here, I wouldn't really know what's best. Tagging your classes or code with version numbers (not the Racket ones, ones defined by you) could be another solution.
On Wed, May 27, 2015 at 11:13 AM, Michael Tiedtke < michael.tied...@o2online.de> wrote: > Thank you very much! That was exactly what I needed. > > (define (reset-flowers flowers) > *[when (method-in-interface? **'snap-back-after-regions? card<%>)* > ;; See Animations in the README file and see also > ;; "mred/15064" in Racket's bug database. This is > ;; conditional for compatibility with Rkt < 6.2.1 > *(broadcast flowers snap-back-after-regions? #t)]* > (broadcast* flowers > (face-down) > (dim #f) > (user-can-flip #f) > (snap-back-after-move #t) > (user-can-move #f)) > > I'm a little bit astonished that Racket doesn't offer a *defined?* > primitve when it's not > possible to implement it with macros because of the strange compile-time > behavior. > Where *compile time* sound to me like put all the interned things > together, call it > byte code and dump it into a file. > > Il giorno 24/mag/2015, alle ore 10.14, Laurent ha scritto: > > This may be of interest to you: > > http://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-variable-is-defined-or-not > > For methods, you can use this instead: > > http://docs.racket-lang.org/reference/objectutils.html?q=method-in#%28def._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._method-in-interface~3f%29%29 > > For fields you can use: > > http://docs.racket-lang.org/reference/objectutils.html?q=method-in#%28def._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._field-names%29%29 > > On the contrary to undefined identifiers, using an inexistant method will > not cause any error until it is called. > > Laurent > > On Sun, May 24, 2015 at 8:20 AM, Michael Tiedtke < > michael.tied...@o2online.de> wrote: > >> I'm used to check for the presence of a definition of a given symbol with >> (defined? symbol) >> >> Probably I still remember that from GNU Guile Scheme but I was not able >> to find an equivalent in Racket. >> >> I need something like that to check during runtime or at least at start-up >> for the existence of a definition before using it. In particular I will >> need to >> *check for the presence of a given field or method by name/symbol* in >> an interface / class definition imported via require. >> >> Any ideas on how to do this with Racket? >> >> Then I'm afraid that Racket is going to lament the usage of an undefined >> symbol even though that part of code might never be reached because >> I had already checked for the presence of its definition. >> >> Example: >> In version 6.7 the /card-table/ class features a flag >> /call-handlers-after-snap-back/ >> but version 6.5 does not have that flag. When the flag and its >> corresponding accessors >> are available it should use them, i.e. branch into parts of the code that >> can use them. If >> not they're not available it should ignore some parts / branches of the >> code. >> >> I can of course use /version/ to check for Racket's version but this >> doesn't take >> patches or third party libraries/modules into account. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Racket Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to racket-users+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > > > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.