Gleefre has quit [Remote host closed the connection]
Gleefre has joined #commonlisp
dtman34 has joined #commonlisp
Oladon has joined #commonlisp
beach` has joined #commonlisp
beach has quit [Ping timeout: 244 seconds]
brokkoli_origin has quit [Remote host closed the connection]
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
attila_lendvai has quit [Ping timeout: 248 seconds]
brokkoli_origin has joined #commonlisp
ndanilov has quit [Ping timeout: 245 seconds]
ndanilov has joined #commonlisp
admich1 has quit [Ping timeout: 244 seconds]
dtman34 has joined #commonlisp
admich1 has joined #commonlisp
attila_lendvai has joined #commonlisp
drasken has left #commonlisp [#commonlisp]
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
dtman34 has joined #commonlisp
gorignak has quit [Quit: quit]
gorignak has joined #commonlisp
random-jellyfish has joined #commonlisp
<random-jellyfish>
I use gensym inside a macro to generate some fresh names at each macro call, but instead at each macro call I get the same outputs from gensym, is there a reason why this would happen?
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
Gleefre has quit [Remote host closed the connection]
<random-jellyfish>
env-name and derived-class-name are always the same every time I run the macro
<random-jellyfish>
with one mention: This happens whenever I compile them with C-c C-c inside emacs+sly
<random-jellyfish>
if I copy paste the macro calls in the REPL I get different outputs from gensym
<random-jellyfish>
might have something to do with compile time vs run time or something but I can't put my finger on it
<random-jellyfish>
any thoughts?
<_death>
what do you think (string (gensym)) should do
<random-jellyfish>
convert the output of gensym to a string?
<random-jellyfish>
I could do it differently
<random-jellyfish>
but is there anything wrong with how it's used there?
<_death>
gensym gives you a new symbol, and string on a symbol gives you the symbol name.. a new symbol does not mean its name is unique.. if you want to create a new symbol with a particular name you can use make-symbol
<random-jellyfish>
or (make-symbol some-expr-calling-gensym) ?
<random-jellyfish>
instead of (read-from-string some-expr-calling-gensym) ?
<nil>
or (intern (format nil "~:@(%resumable-state-env-~a-~a%~)" name (gensym)))
<_death>
no, again that's wrong
<_death>
random-jellyfish: instead of read-from-string, yes.. you should think about it (and ask questions as needed) until everything's clear..
bpanthi977 has joined #commonlisp
<_death>
you should never expect the name of a gensym to have the magical quality of making something unique
<duuqnd>
gensym's name is supposed to be created using a prefix and suffix, and if no suffix is provided then *gensym-counter* should be incremented and used as the suffix.
<duuqnd>
So really, if you're calling gensym with no parameter, then the name should be unique on each call.
<duuqnd>
(unless you change *gensym-counter* in between)
<gilberth>
Yes, and that might be out of your control. So never assume that the name of a gensym is in any way unique.
<random-jellyfish>
I just want random names whenever the macro is expanded and its expansion is compiled...
bpanthi977 has quit [Ping timeout: 260 seconds]
<random-jellyfish>
should I use a random number generated with random seed instead?
<duuqnd>
Random seems wrong here
<random-jellyfish>
(assuming random implies uniqueness)
<duuqnd>
Perhaps instead of going for gensym, try having a counter of your own that you use and increment yourself
<duuqnd>
gilberth: yeah that's true, not sure why I bothered saying what I did when it's both obvious and unhelpful
dtman34 has joined #commonlisp
<gilberth>
Well, all you said was true.
<gilberth>
Anyhow, uniqueness just like equalness has no universal answer. Unique to what? This run of the macro? In the compile time environment? In the load time environment? Within a process? On a machine? On Earth? In the universe? It needs a domain.
jonatack has quit [Ping timeout: 276 seconds]
toadlicker_ has joined #commonlisp
<random-jellyfish>
I would like uniqueness in all environments
<random-jellyfish>
every time the macro is expanded => unique env-name and derived-class-name
toadlicker has quit [Remote host closed the connection]
<random-jellyfish>
unique = different than the last expansion
<nil>
Always encode more entropy then the universe then.
<random-jellyfish>
even if I use my own counter, won't it be reset when we switch from compile time to load time and then to execute time?
<random-jellyfish>
I could randomize a seed using a timestamp...
<duuqnd>
No, it shouldn't be reset, unless you're binding it to something somewhere
<nil>
But for reals, relying on gensym used outside the body of a macro doesn't seem good. and GUID seem ugly too.
pkal has joined #commonlisp
<duuqnd>
realistically, unless there's something funky going on that I've missed, incrementing a global counter should work fine
apac has quit [Ping timeout: 252 seconds]
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
<random-jellyfish>
nil, what do you mean by "used outside the body of a macro", you mean in the let surrounding the macro body? I all common lisp books I've read that's how it's used
<random-jellyfish>
For example in the common lisp cookbook:
<random-jellyfish>
To make temporary variables, we use the gensym function, which returns a fresh variable guaranteed to appear nowhere else. Here is what the macro should look like:
<random-jellyfish>
(defmacro setq2 (v1 v2 e)
<random-jellyfish>
(let ((tempvar (gensym)))
<random-jellyfish>
`(let ((,tempvar ,e))
<random-jellyfish>
(progn (setq ,v1 ,tempvar)
<random-jellyfish>
(setq ,v2 ,tempvar)))))
dtman34 has joined #commonlisp
<random-jellyfish>
I guess in my case I don't create temp var names with gensym, I create class names...
<random-jellyfish>
maybe that's where I got it wrong
<duuqnd>
Yeah, you're letting gensym's return value leak out of the macroexpansion by defining a class with a name influenced by gensym.
<nil>
Yes, in that example it's used only inside the generated body.
<random-jellyfish>
alrighty then incrementing a global counter is the way to go it seems, I'll start changing it
<random-jellyfish>
Thanks guys
yaneko has quit [Quit: parting]
yaneko has joined #commonlisp
gorignak has quit [Quit: quit]
lisper29 has joined #commonlisp
<_death>
gensym and make-symbol return new symbols, while intern/read-from-string don't.. if you want a new symbol that's never been used before, use the former.. multiple symbols can have equal names, so never rely on naming
<_death>
*don't necessarily
pve has quit [Quit: leaving]
<_death>
if you make sure a symbol with a given name does not exist in a package, you can create one with that name and (if guarded against race conditions) can rely on the symbol not being used before, but doing that is almost never necessary
<nil>
Ambitious macroing of CLOS code is a nice way to flex CL power.
lutherann has joined #commonlisp
mgl has quit []
attila_lendvai has quit [Ping timeout: 248 seconds]
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
<aeth>
there definitely isn't enough ambitious macroing going on in most code
<aeth>
after all, it's the point of the language: nothing's impossible!
lutherann has quit [Quit: Leaving]
lutherann has joined #commonlisp
lutherann has joined #commonlisp
lutherann has quit [Changing host]
<aeth>
well, defmacro haltp may still have issues
dtman34 has joined #commonlisp
pkal has quit [Ping timeout: 265 seconds]
dtman34 has quit [Quit: ZNC 1.8.2+deb3.1+deb12u1 - https://znc.in]
lisper29 has quit [Quit: Leaving]
rgherdt has quit [Remote host closed the connection]
flip214 has quit [Read error: Connection reset by peer]
Gleefre has quit [Remote host closed the connection]
flip214 has joined #commonlisp
robin has quit [Ping timeout: 248 seconds]
robin has joined #commonlisp
<random-jellyfish>
yeah the power of CLOS is quite impressive, so much untapped potential, Julia copied it quite nicely
ndanilov has quit [Remote host closed the connection]
bpanthi977 has joined #commonlisp
ndanilov has joined #commonlisp
bpanthi977 has quit [Ping timeout: 248 seconds]
dtman34 has joined #commonlisp
ndanilov has quit [Ping timeout: 272 seconds]
Oladon has quit [Quit: Leaving.]
random-jellyfish has quit [Ping timeout: 244 seconds]