ephemera_ has quit [Remote host closed the connection]
mzan has joined #racket
endobson has joined #racket
badkins has quit [Remote host closed the connection]
iyzsong has joined #racket
samagino has joined #racket
samagino has quit [Remote host closed the connection]
vraid has quit [Ping timeout: 240 seconds]
pierpal has joined #racket
vraid has joined #racket
theruran has quit [Quit: Connection closed for inactivity]
badkins has joined #racket
badkins has quit [Ping timeout: 260 seconds]
orivej has quit [Ping timeout: 268 seconds]
orivej has joined #racket
badkins has joined #racket
badkins has quit [Remote host closed the connection]
_whitelogger has joined #racket
notzmv has quit [Ping timeout: 260 seconds]
sz0 has joined #racket
_whitelogger has joined #racket
jsomedon has joined #racket
jsomedon has quit [Quit: jsomedon]
narimiran has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
badkins has joined #racket
badkins has quit [Ping timeout: 246 seconds]
pierpal has quit [Ping timeout: 260 seconds]
orivej has quit [Ping timeout: 265 seconds]
endobson has joined #racket
_whitelogger has joined #racket
sauvin has joined #racket
_whitelogger has joined #racket
jellie has joined #racket
jellie has quit [Ping timeout: 260 seconds]
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
endobson has joined #racket
endobson has quit [Client Quit]
endobson has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
endobson has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Trieste has quit [Ping timeout: 260 seconds]
Trieste has joined #racket
_whitelogger has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
srji has joined #racket
_whitelogger has joined #racket
dddddd has quit [Ping timeout: 268 seconds]
ZombieChicken has joined #racket
Fernando-Basso has joined #racket
orivej has joined #racket
Trieste has quit [Ping timeout: 260 seconds]
Trieste has joined #racket
MustardCheese has joined #racket
nullcone has quit [Quit: Connection closed for inactivity]
Trieste has quit [Ping timeout: 240 seconds]
<MustardCheese>
Anyone home?
Trieste has joined #racket
<vraid>
MustardCheese: depends on who you ask
<MustardCheese>
Haha
iyzsong has quit [Ping timeout: 272 seconds]
<MustardCheese>
I've hit a problem and I think I'm looking for solutions in the wrong places
<MustardCheese>
So I was hoping that somebody here would point me in the right direction
<MustardCheese>
I'm trying to improve my grasp of macros and have so far succeeded.
<MustardCheese>
The current macro that I'm working on, however, is perhaps a bit too meta. I want it to run a particular line of code exactly once, once a condition is met.
<MustardCheese>
After that point, the line would be skipped over
<MustardCheese>
This is so that I can insert logging into hot code without getting too much feedback
<MustardCheese>
My initial approach to this problem is to have state stored in the macro's module, which would retain information about where the macro has been called. That way, if the same function calls the macro again, the repository confirms duplication and cancels the logging
<vraid>
this might be out of my expertise
<vraid>
but is a macro necessary for this; wouldn't a function do?
<MustardCheese>
I can assure you it's out of mine as well haha
<MustardCheese>
The purpose of the macro is for convenience - I want to call it like so:
<MustardCheese>
(log-once my-var another-var)
<MustardCheese>
And for that to log something akin to
<MustardCheese>
"Value for 'my-var': 4"
<vraid>
samth, greghendershott, lexi-lambda might have a better idea
<MustardCheese>
So I want to keep hold of the identifier just long enough to print it
<MustardCheese>
Any help would be much appreciated :)
<vraid>
ah, you need the variable name
<vraid>
what purpose does another-var have in that call?
evhan has quit [Quit: De IRC non curat rex...]
evhan has joined #racket
<MustardCheese>
Ah - that's just to prove that log-once could take any number of arguments and would still function
<MustardCheese>
So in that case it would also print
<MustardCheese>
"Value for 'another-var': 86"
<vraid>
once for each variable, or once, period?
<MustardCheese>
Yes, that's right
<MustardCheese>
They'd all get printed together, then would never be printed again
<MustardCheese>
Once I've got the basic functionality down, then I'd add more complex parts, such as named arguments that specify delayed printing
<greghendershott>
vraid: Looks like MustardCheese is gone now but first reaction this is `when` plus some counter-in-a-closure-lambda?
<greghendershott>
And my advice would be to write it that way, and get it working, before trying to make a macro.
badkins has joined #racket
<greghendershott>
And have the macro only "sugar" away things like `lambda`.
<MustardCheese>
Hello there
<greghendershott>
It's usually best when macros do the least possible -- contribute the magic only they can -- and delegate as much as possible to plain old functions.
<MustardCheese>
Ok so you say a closure lambda eh
<greghendershott>
"best" meaning the least-horrible to debug and maintain :) Also probably less generated code bloat.
<MustardCheese>
This is true
<vraid>
right, so my intuition to use functions wasn't off
<MustardCheese>
But surely if I have a lambda, I'm going to have to keep hold it and drag it around with me so that it acn maintain state
<greghendershott>
Yeah sorry that's obscure. I mean a "let over lambda".
<MustardCheese>
So uhm I was planning on doing something like that for the counter business yeah
<greghendershott>
It's a sort of "poor person's 'object'"
<MustardCheese>
The current impl is in its own file, which means I can hide all of my state in there out of sight
<MustardCheese>
My issue is that I want some way to keep track of multiple uses of this function/macro/whatever without having to keep track of each usage
<MustardCheese>
I want to just throw down calls to it, lob variables in there and let it do the rest
<greghendershott>
If you could get it working something like that??
<MustardCheese>
Yeah something similar to that!
<greghendershott>
Maybe that's clear enough and not too tedious, and you're done. No macro.
<greghendershott>
Or
<greghendershott>
Maybe you want to make it a little shorter/sweeter. Simple macro.
<greghendershott>
That's kind of what I'm suggesting.
<greghendershott>
I have to AFK in a few seconds but, that's my general hand-wavy suggestion. :)
<MustardCheese>
Yeah I want to keep the macro as simple as possible for this deal. Keep as much as possible out of arcana
orivej has quit [Ping timeout: 268 seconds]
<MustardCheese>
I suppose the crux of the what I'm asking is this: if I declare a variable within scope, that variable is discarded once I leave that scope
<MustardCheese>
This means that I have to manually declare state outside of scope, then hop into scope and write some condition etc for logging
<MustardCheese>
Rinse and repeat for each variable I'm planning to log
<MustardCheese>
The when statement could certainly be abstracted to a function and stop there, but I think something else may be needed to dynamically declare state and give it a unique id that won't conflict with anything else
<greghendershott>
Maybe I need more coffee, and I'm wrong, but I feel like you can use that, plus `when`, plus `log-info`, and that's all you need? Then just see if you still want to write a macro?
<greghendershott>
As for your questions about scope, I think the answer is, only use the vars when they're within scope.
<MustardCheese>
I'll knock up an example against what you've sent and I'll get back to you - thank you for the help so far!
soegaard has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<MustardCheese>
The only thing missing is that I want to automate declaration of the `should-print` variable, so that I don't have to manage it manually
sagax has joined #racket
<greghendershott>
Hmm, right. I kind of kicked the can down the road. If the counter closure is defined in the function body, it will be reset each time.
<greghendershott>
You want that defined outside the function, at the module level.
<MustardCheese>
That's the root problem that I seem to have ended up with
<MustardCheese>
Yeah - so something of note there
<MustardCheese>
We can define a list or something of the like in the module containing these helper functions
<greghendershott>
I've never used it before, but this sounds like it might be a job for `syntax-local-lift-module`?
<greghendershott>
Either that or just use some side hash-table for counters, with some sort of unique keys (if you didn't want to, or couldn't, use syntax).
<MustardCheese>
That macro is quite exciting, but I wouldn't retain the secret names between iterations unless I had some other known variable
<greghendershott>
I mean your macro (a) makes some name for the counter variable using gen-temps, (b) uses syntax-local-lift-module to define that counter variable, and (c) uses that counter variable in its "should I print" logic.
<greghendershott>
Again that's just my hunch how it could work.
badkins has quit [Remote host closed the connection]
badkins has joined #racket
badkins has quit [Ping timeout: 240 seconds]
badkins has joined #racket
<MustardCheese>
Aha you're saying that the macro puts the name into the expanded code, so that it stays there?
<MustardCheese>
I think I'm on your page now
<greghendershott>
Yes!
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
endobson has joined #racket
<MustardCheese>
How do you think I might access the 'make-true-when-called-N-times' function from macro context?
<MustardCheese>
Is there a form to require the function for-syntax?
<greghendershott>
I think in this latest approach, you can just define a simple integer counter variable?
<MustardCheese>
Ah you might be right
<greghendershott>
So each invocation the macro will write `(define counter-xxx 0)` at the module level, where `counter-xxx` is actually some name from `generate-temporaries`, -and- where you invoke the macro will do the `(begin0 (== n counter-xx) (set! counter-xxx (add1 counter-xxx)))`, plus any user-supplied test, and maybe call print of log-info or whatever.
<greghendershott>
(is what I had in mind)
nullcone has joined #racket
<MustardCheese>
As I plan to declare the variable, then return some expanded form, I wanted to declare the variable in a `with-syntax` clause
<MustardCheese>
But then I hit the unfortunate circumstance of needing a macro to assemble the `define` statement haha
badkins has quit [Remote host closed the connection]
badkins has joined #racket
Trieste has quit [Ping timeout: 240 seconds]
endformationage has joined #racket
badkins has quit [Ping timeout: 265 seconds]
Trieste has joined #racket
NinjaTrappeur has joined #racket
endobson has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
endobson has joined #racket
MustardCheese has quit [Ping timeout: 260 seconds]
badkins has joined #racket
Nomenclatura has joined #racket
badkins has quit [Ping timeout: 246 seconds]
MustardCheese has joined #racket
theruran has joined #racket
Nomenclatura has quit [Quit: q]
qop has joined #racket
qop has quit [Read error: Connection reset by peer]