libera/#commonlisp - IRC Chatlog
Search
4:31:25
phantomics
Morning beach, is anyone around here using Allegro CL? If so I have something amusing for you to try
4:48:56
ns12
Does "Object-Oriented Programming in COMMON LISP: A Programmer's Guide to CLOS" by Sonya E. Keene describe CLOS as it appears in ANSI Common Lisp? Or is the book about pre-ANSI CLOS?
5:18:16
beach
ns12: ANSI pretty much incorporated CLOS as it was defined, or the subset that was necessary for the standard.
10:46:43
VincentVega
So, in a situation like this https://pastebin.com/Ft6qYNMa , what can I do to optimize away the WHEN clause? Any way to declare FLAG constant?
10:48:13
phoe
that's slightly subpar because it leads to code duplication, but you do seem to want code duplication - you want to return different functions depending on the value of flag
10:49:17
phoe
but, good golly, I hope you don't use microoptimizations like these for simple functions like that
10:49:49
phoe
VincentVega: not really; you basically want to return different anonymous functions based on the value of FLAG
10:50:16
phoe
and LAMBDA is not a good abstraction for that, because it always describes a single body of code
10:51:30
phoe
you can only try to hide it behind some sort of macrology, but adding conditionals like that would likely require code walking in order to find the conditionals in the code
10:52:21
phoe
like, if a hypothetical FLAG-LAMBDA like (flag-lambda (x y z) ...) expands into conditionals based on X, Y and Z, then (flag-lambda (x y z) (... (... (flag-when x ...))))
10:52:46
phoe
this requires code walking so FLAG-LAMBDA can recognize how to skip or not skip the inner FLAG-WHEN invocation
10:53:33
VincentVega
phoe: Hmm, I see what you are saying, that makes sense. But to avoid code walking, I could write a seperate macro too, so that's cool. Well, thanks for explaining this!
10:55:14
Nilby
I don't think you need walking if you don't care that there's two versions of the lambda
10:55:43
phoe
Nilby: I mean, one of these lambdas needs to have the PRINT call and the other needs to not have it
10:56:44
phoe
so something like (flag-lambda (x) (flag-when x (print "foo")) (+ 1 2)) expands into (if x (lambda () (print ...) ...) (lambda () ...))
10:57:14
phoe
and I just realized that you can avoid code walking - you can pass information in &environment
10:57:47
phoe
and it will cause FLAG-WHEN to expand into either (progn) for nothing or (progn ...) - depending on whether a given flag is meant to be set for the given generated lambda
10:58:30
phoe
VincentVega: I can sketch out a solution later today if you're interested and/or don't know how to start
10:59:07
VincentVega
phoe: I think I know what you are saying, I am playing around with code rn to see what works best : )
11:12:44
VincentVega
I mean, the other way is to do this generally like phoe suggested. For multiple variables, that is, would be useful. Maybe I will even make it.
11:31:56
VincentVega
phoe: Nilby: OK, it's actually quite nifty with a symbol-macrolet https://pastebin.com/WN3NU68j except for the deleting unreachable code warnings.
11:42:49
phoe
give me a few hours to finish work and then I'll be able to show you if no one does before me :D
11:46:09
Nilby
Nice. Nearly zero run cost conditional logging. Probably less code bloat than C++ templates. I'm curious to see phoe's extra fancy way.
11:47:52
VincentVega
Nilby: yep, with a custom when-flag, the warnings are gone, will be curious to see another way too : )
13:35:14
phoe
I use &environment to communicate between the outer macro(s) FLAG-LAMBDA and the inner macro(s) FLAG-WHEN
13:35:58
phoe
SYMBOL-MACROLET is a way of writing stuff into the compilation environment and MACROEXPAND-1 with a symbol is a way of reading it
13:36:33
phoe
in the fully macroexpanded code, you can ignore L29 completely - it's just noise leftover by the communication
13:37:18
phoe
what matters is the fact that the (IF X (LAMBDA ...) (LAMBDA ...)) structure is what you seem to want, and a total of 2^n functions will be generated based on the combination of flags
13:38:22
phoe
a tidbit is my use of LOCALLY instead of PROGN to permit declarations, since you have a lot of #.*burn-baby-burn* style of declarations
14:42:45
phoe
and the other being symbol macros whose only purpose is to exist in &env as a way of passing information deeper into the macroexpansion process
14:49:59
phoe
VincentVega: in your previous example, you could substitute SYMBOL-MACROLET for LET and it would still work
14:50:58
phoe
in your previous example, you had (when x ...) turn into (when t ...) or (when nil ...) which generated unreachable code warnings
14:51:22
phoe
now the macro simply doesn't generate any code for the cases that could previously generate something like (when nil ...)