
Is there anyway to generate something similar to C NDEBUG, where a macro will do something if a variable is defined but nothing otherwise. However, when nothing is done, no code is generated?

So the idea here is to track application event statistics. i.e. how long it’s taking to calculate this or to calculate that. So, each function records a start/end event within an interesting ‘area’ of execution. However, I don’t want these to do absolutely anything (no code generation) if I turn them off at compile time.

and as far as I understand it, if I do (define-syntax-rule (record-event name body ...)
(when (statistics-enabled?)
(add! (current-statistics) (make-start-event name (current-milliseconds)))
body ...

so, I do a couple of things there that should only happen when (statistics-enabled?) is true. However, this still issues code.

I would like a general method to set a variable at compile time that disables the code generation. Any suggestions?

@mark.warren has joined the channel

@pocmatos this is relatively easy to do with a macro — for a sophisticated version see https://github.com/racket/typed-racket/blob/master/typed-racket-lib/typed-racket/utils/utils.rkt#L119

@samth thanks for the ref. I completely forgot that contracts would need to do this.

@pocmatos they don’t need to do that — those are about internal implementation contracts inside typed racket

here’s another example: https://github.com/racket/racket/blob/master/racket/src/expander/common/performance.rkt

@samth maybe you pointed me to a different thing since it’s in the typed-racket repo but isn’t there a way to disable contracts in a program written with contracts? I was pretty sure there was something like this, maybe for contract profiling, but I might be confused. Guess I will search before opening my mouth again. :slightly_smiling_face:

@pocmatos no, there isn’t a general way to do that

whoops. ok. :slightly_smiling_face:

@samth in the last example you reference it seems that the no-code-measure
is always re-exported. is this the case, where you have to change the code in order to change the behaviour?

yes

Does anyone have any feelings they would like to share about designing programs around racket class system versus struct inheritance + generics? Curious about experiences with these from the point of view of abstraction and performance.

@pocmatos I design mostly with structs + generics, but change some entities to classes when their behavior changes depending on some internal state.

Except when that given state can be a parameter

so it goes like this: <— stateless ————————— statefull —> struct
— generics
— parameters
— classes

@jerome.martin.dev interesting, by statefull you mean private state, right? you can encode state in structs but that state is public.

yes exactly

you can copy struct and be completely stateless

by statefull I mean “behavior depends on an internal state”

yes, that makes sense. thanks.

For example, when I’m inclined to use the “let-over-lambda” trick, so that a method sends a different result depending on some outside variable, I think twice because I might be needing a class after all. (let ([n 0])
(lambda ()
(set! n (+ n 1))
n))
could be changed into a counter class.

In general, most uses of set!
are clues that something state-ish is going on, so I try to listen to my code… light up some candles… then things get spiritual.

I’ve defined metadata tags like (@template String) that are working nicely. But they seem to break the BSL stepper. Right now the tags ultimately expand into (values). The stepper errs with: reconstruct: context expected one value, given empty

What should I be expanding into?

@gregor.kiczales (void)
is less likely to trip up the stepper

(void) doesn’t make the stepper barf, but leaves a lot of voids in the stepped output (require spd/tags) (require 2htdp/universe) (require 2htdp/image) (void) (void) (void)