pocmatos
2018-5-15 07:09:23

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?


pocmatos
2018-5-15 07:10:55

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.


pocmatos
2018-5-15 07:12:53

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 ...


pocmatos
2018-5-15 07:13:19

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


pocmatos
2018-5-15 07:13:45

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


mark.warren
2018-5-15 07:18:38

@mark.warren has joined the channel


samth
2018-5-15 12:28:21

@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


pocmatos
2018-5-15 12:44:47

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


samth
2018-5-15 12:45:12

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



pocmatos
2018-5-15 12:49:37

@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:


samth
2018-5-15 12:49:57

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


pocmatos
2018-5-15 12:50:24

whoops. ok. :slightly_smiling_face:


pocmatos
2018-5-15 13:25:21

@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?


samth
2018-5-15 13:25:53

yes


pocmatos
2018-5-15 15:04:03

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.


jerome.martin.dev
2018-5-15 15:13:13

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


jerome.martin.dev
2018-5-15 15:13:58

Except when that given state can be a parameter


jerome.martin.dev
2018-5-15 15:15:40

so it goes like this: <— stateless ————————— statefull —> structgenericsparametersclasses


pocmatos
2018-5-15 15:30:22

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


jerome.martin.dev
2018-5-15 15:30:31

yes exactly


jerome.martin.dev
2018-5-15 15:30:55

you can copy struct and be completely stateless


jerome.martin.dev
2018-5-15 15:31:21

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


pocmatos
2018-5-15 15:32:32

yes, that makes sense. thanks.


jerome.martin.dev
2018-5-15 15:39:02

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.


jerome.martin.dev
2018-5-15 15:41:32

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.


gregor.kiczales
2018-5-16 02:22:08

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


gregor.kiczales
2018-5-16 02:22:40

What should I be expanding into?


mflatt
2018-5-16 02:24:17

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


gregor.kiczales
2018-5-16 03:23:11

(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)