i’m guessing it’s the way value works and when v appears, but why do iget this behaviour?$ qKDB+ 3.0 2013.04.05 Copyright (C) 1993-2013 Kx Systemsq)a:1;b:2;v!-16!'value each v:system"v"a| 0b| 0q)a:1;b:2;v!-16!'value each v:system"v"a| 2b| 2v| 1how can i get the list of variables and their reference counts?thanks,jack.
Is this what you’re looking for?
q)a:1;b:2;v!value each “-16!”,/:string v:system"v"
a| 2
b| 2
q)a:1;b:2;v!value each “-16!”,/:string v:system"v"
a| 2
b| 2
v| 1
by hiding v in a function, doing the gets first and {x-1} the result isthe true reference countsq)a:1;b:2;c:aq){v!value each"-16!“,/:string v:system"v”}-1a| 1b| 0c| 1q){v!value each"-16!“,/:string v:system"v”}-1a| 1b| 0c| 1On 19 June 2013 18:26, WooiKent Lee <wkent.lee> wrote:> Is this what you’re looking for?>> q)a:1;b:2;v!value each “-16!”,/:string v:system"v"> a| 2> b| 2> q)a:1;b:2;v!value each “-16!”,/:string v:system"v"> a| 2> b| 2> v| 1>> On Wednesday, 19 June 2013 07:34:12 UTC+1, effbiae wrote:>>>> i’m guessing it’s the way value works and when v appears, but why do i>> get this behaviour?>>>> $ q>> KDB+ 3.0 2013.04.05 Copyright (C) 1993-2013 Kx Systems>>>> q)a:1;b:2;v!-16!'value each v:system"v">> a| 0>> b| 0>> q)a:1;b:2;v!-16!'value each v:system"v">> a| 2>> b| 2>> v| 1>>>>>> how can i get the list of variables and their reference counts?>>>> thanks,>>>>>> jack.>> –>
Submitted via Google Groups</wkent.lee>
I wonder why when you execute the whole thing in one line, the reference count is more?
q)a:1;-16!a
2i
I would actually expect it to be 0 if you take off the result by one.
there are some subtleties at work i don’t fully understand, but inq)a:1;-16!athe a:1 doesn’t just set a to 1, it also returns a value. that valueis actually a itself and before the interpreter releases this returnedvalue, it executes -16!a and finds two references. another way ofthinking about it is:q)-16!a:12iwhere we are getting the refcount of the returned valuehowever, i can’t explain why the result is 2 and not 1 - in C code,you expect x->r to be 1 if it has two references.something else i cannot explain isq)-16!11iq)-16!`o0ita, jack.On 20 June 2013 18:10, WooiKent Lee <wkent.lee> wrote:> I wonder why when you execute the whole thing in one line, the reference> count is more?>> q)a:1;-16!a> 2i>> I would actually expect it to be 0 if you take off the result by one.>>> On Thursday, 20 June 2013 08:39:46 UTC+1, effbiae wrote:>>>> by hiding v in a function, doing the gets first and {x-1} the result is>> the true reference counts>>>> q)a:1;b:2;c:a>> q){v!value each"-16!“,/:string v:system"v”}-1>> a| 1>> b| 0>> c| 1>> q){v!value each"-16!“,/:string v:system"v”}-1>> a| 1>> b| 0>> c| 1>>>>>> On 19 June 2013 18:26, WooiKent Lee <wken…> wrote:>> > Is this what you’re looking for?>> >>> > q)a:1;b:2;v!value each “-16!”,/:string v:system"v">> > a| 2>> > b| 2>> > q)a:1;b:2;v!value each “-16!”,/:string v:system"v">> > a| 2>> > b| 2>> > v| 1>> >>> > On Wednesday, 19 June 2013 07:34:12 UTC+1, effbiae wrote:>> >>>> >> i’m guessing it’s the way value works and when v appears, but why do i>> >> get this behaviour?>> >>>> >> $ q>> >> KDB+ 3.0 2013.04.05 Copyright (C) 1993-2013 Kx Systems>> >>>> >> q)a:1;b:2;v!-16!'value each v:system"v">> >> a| 0>> >> b| 0>> >> q)a:1;b:2;v!-16!'value each v:system"v">> >> a| 2>> >> b| 2>> >> v| 1>> >>>> >>>> >> how can i get the list of variables and their reference counts?>> >>>> >> thanks,>> >>>> >>>> >> jack.>> >>> > –>> > You received this message because you are subscribed to the Google>> > Groups>> > “Kdb+ Personal Developers” group.>> > To unsubscribe from this group and stop receiving emails from it, send>> > an>> > email to personal-kdbpl...@googlegroups.com.>> > To post to this group, send email to personal...@googlegroups.com.>> > Visit this group at http://groups.google.com/group/personal-kdbplus.>> > For more options, visit https://groups.google.com/groups/opt_out.>> >>> >>> –>
Submitted via Google Groups</wken…></wkent.lee>
Another weird thing is this:
q)-16!a:1+1
1i
instead of 2? whats the difference anyway…
That’s why I’m really confused on how reference count works in q