Re: [racket-users] How to check for existing definitions
On May 24, 2015, at 3:20 AM, Michael Tiedtke michael.tied...@o2online.de wrote: 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. I was just re-reading this, and for your particular use case this has been answered already by Laurent, but: One way to do this kind of thing for normal identifiers is to use this: http://www.greghendershott.com/2014/06/fallback-when-required-function-not-available.html -- 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.
Re: [racket-users] How to check for existing definitions
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.
Re: [racket-users] How to check for existing definitions
On May 27, 2015, at 6:13 AM, Michael Tiedtke michael.tied...@o2online.de wrote: 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. Here’s a fairly useless macro that can tell if a given identifier is defined or not: #lang racket (require (for-syntax racket/base syntax/parse)) (define-syntax defined? (syntax-parser [(defined? x:id) (if (identifier-binding #'x) #'#t #'#f)])) (defined? x) (define y 3) (defined? y) (let ([x 4]) (defined? x)) Where compile time sound to me like put all the interned things together, call it byte code and dump it into a file. Well, there’s expansion time, which is the part of “compile time” in which macros expand, and in racket that’s often what people are talking about when they say compile time. Racket is a lot more useful because you would never get an error about an unbound identifier at runtime, because it can always tell during compile time whether it’s bound or not. And this makes things like `defined?` fairly useless at runtime, because that information is useful during expansion time instead. That’s why functions like identifier-binding and syntax-local-value are provided. -- 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.
Re: [racket-users] How to check for existing definitions
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.
Re: [racket-users] How to check for existing definitions
Il giorno 27/mag/2015, alle ore 13.08, Alexander D. Knauth ha scritto: On May 27, 2015, at 6:13 AM, Michael Tiedtke michael.tied...@o2online.de wrote: 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. Here’s a fairly useless macro that can tell if a given identifier is defined or not: #lang racket (require (for-syntax racket/base syntax/parse)) (define-syntax defined? (syntax-parser [(defined? x:id) (if (identifier-binding #'x) #'#t #'#f)])) (defined? x) (define y 3) (defined? y) (let ([x 4]) (defined? x)) Where compile time sound to me like put all the interned things together, call it byte code and dump it into a file. Well, there’s expansion time, which is the part of “compile time” in which macros expand, and in racket that’s often what people are talking about when they say compile time. The reader stage does the compilation. It pulls in different parts into one collection or compilation in memory with the mentioned expansion time. It interns symbols, constants and definitions probably after doing some text processing. Then there might be an on-the-fly optimization stage and at some point one might want to create an executable file. All of this - not specific to Racket - might be called compilation. To load the executable it needs to have all the system level dependencies on board because of some previous linking stage or the linker prepared it for dynamic linking. That's because todays systems are based on UNIX / C calling conventions and application binary interfaces when it comes to linking. Again with the evolution to message passing there was little change but all in all it's not very s-exp Read-Eval-Dump/Link friendly ... even todays system runtime evironment is a lot of UNIX process management with the addition of kernel servers, DRM, sandboxing, code signing (where I do not know or trust the certificate authorities) and intellectual property management. Up to that point that I can't load and edit my own recording of me playing my own music anymore because of some Logic IP thing in GarageBand? Some might think the Hurdle of Servers or NT-based systems were better - but I havn't touched those in a long time. Racket is a lot more useful because you would never get an error about an unbound identifier at runtime, because it can always tell during compile time whether it’s bound or not. And this makes things like `defined?` fairly useless at runtime, because that information is useful during expansion time instead. That’s why functions like identifier-binding and syntax-local-value are provided. I see ... the other link (http://stackoverflow.com/questions/20076868/how-to-know-whether-a-racket-variable-is-defined-or-not) proposed an if-defined macro/syntax-object. That's all you ever need, I guess. Racket's so called compile time checks are really useful and I hope they are available as a library to check existing source trees algorithmically? But sometimes I know better than the compiling stage and defined? ... Thank you and regards, Michael -- 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.
[racket-users] How to check for existing definitions
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.
Re: [racket-users] How to check for existing definitions
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.