in-place update/delete does not work within a function

Hello,this works out side of function --q)table: ( a: abc; n: (1 2 3))q)update b:val from tabletableq)tablea n b-------a 1 valb 2 valc 3 valWhy does this not work..(is this something to do with variable scope? If so is there anydocumentation which explains variable scope?)In version 2.5 - it does not return type error but does not do updatein placeq)myf:{table: ([] a: abc; n: (1 2 3)); update b:val fromtable ; :table}q)myfa n—a 1b 2c 3In version 2.6q)myf:{table: ( a: abc; n: (1 2 3)); update b:val from`table ; :table}q)myfq)'2010.02.05T11:41:35.519 typeThanks,RT

Hello,In your example table is a local variable.If you change to a global this will work.q)myf:{table::( a: abc; n: (1 2 3)); update b:val fromtable;:table}q)tableq)myf[]a n b-------a 1 valb 2 valc 3 valq)tablea n b-------a 1 valb 2 valc 3 valRegards,Fintan.On Feb 5, 12:52?pm, Ramdas <rtha...> wrote:&gt; Hello,&gt;&gt; this works out side of function --&gt;&gt; q)table: ([] a: abc; n: (1 2 3))> q)update b:val from table> table&gt; q)table&gt; a n b&gt; -------&gt; a 1 val&gt; b 2 val&gt; c 3 val&gt;&gt; Why does this not work..&gt; (is this something to do with variable scope? ?If so is there any&gt; documentation which explains variable scope?)&gt;&gt; In version 2.5 - it does not return type error but does not do update> in place>> q)myf:{table: ( a: abc; n: (1 2 3)); update b:val from> table ; ? ?:table}&gt; q)myf[]&gt; a n&gt; ---&gt; a 1&gt; b 2&gt; c 3&gt;&gt; In version 2.6&gt;&gt; q)myf:{table: ([] a: abc; n: (1 2 3)); ? update b:val from&gt; table ; ? ?:table}> q)myf> q)'2010.02.05T11:41:35.519 type>> Thanks,> RT</rtha…>

Fintan,I understand that it works on global variables but what do I do if Ido not want to create a global variable?What happens when there are multiple users who connect to remote qprocess and create same global variable name?Thanks,RamdasOn Feb 5, 1:06?pm, fintanq <fint…> wrote:> Hello,>> In your example table is a local variable.>> If you change to a global this will work.>> q)myf:{table::( a: abc; n: (1 2 3)); update b:val from> table;:table}&gt; q)table&gt; q)myf[]&gt; a n b&gt; -------&gt; a 1 val&gt; b 2 val&gt; c 3 val&gt; q)table&gt; a n b&gt; -------&gt; a 1 val&gt; b 2 val&gt; c 3 val&gt;&gt; Regards,&gt;&gt; Fintan.&gt;&gt; On Feb 5, 12:52?pm, Ramdas <rtha...> wrote:&gt;&gt;&gt;&gt; &gt; Hello,&gt;&gt; &gt; this works out side of function --&gt;&gt; &gt; q)table: ([] a: abc; n: (1 2 3))> > q)update b:val from table> > table&gt; &gt; q)table&gt; &gt; a n b&gt; &gt; -------&gt; &gt; a 1 val&gt; &gt; b 2 val&gt; &gt; c 3 val&gt;&gt; &gt; Why does this not work..&gt; &gt; (is this something to do with variable scope? ?If so is there any&gt; &gt; documentation which explains variable scope?)&gt;&gt; &gt; In version 2.5 - it does not return type error but does not do update> > in place>> > q)myf:{table: ( a: abc; n: (1 2 3)); update b:val from> > table ; ? ?:table}&gt; &gt; q)myf[]&gt; &gt; a n&gt; &gt; ---&gt; &gt; a 1&gt; &gt; b 2&gt; &gt; c 3&gt;&gt; &gt; In version 2.6&gt;&gt; &gt; q)myf:{table: ([] a: abc; n: (1 2 3)); ? update b:val from&gt; &gt; table ; ? ?:table}> > q)myf> > q)'2010.02.05T11:41:35.519 type>> > Thanks,> > RT- Hide quoted text ->> - Show quoted text -</rtha…></fint…>

charset=us-ascii;
format=flowed;
delsp=yes

Mime-Version: 1.0 (iPhone Mail 7D11)
Date: Fri, 5 Feb 2010 14:31:56 -0500
Cc: Kdb+ Personal Developers

Ramdas,
You could define the table in a different namespace. Eg: .ns1

Regards,
Nathan

Hi Ramdas,

Is there any particular reason that you want to use update in place??

The typical reason that update in place is nice is to save on memory reallocation. Otherwise, you can always assign the result of the update back to a new variable. If the “new” variable has the same name as the old, then memory allocation is not a problem.?

==Outside function scope==

q)table: ( a: abc; n: (1 2 3)) q)update b:val from `table

q)table


a n b

-------
a 1 val
b 2 val
c 3 val


==Gives same results as==

q)table: ([] a: `a`b`c; n: (1 2 3))
q)table:update b:`val from table
q)table

a n b
-------
a 1 val
b 2 val
c 3 val

==Which works inside function scope==

q)f:{ table: ( a: ab`c; n: (1 2 3));table:update b:x from table;:table}

q)f[`val]
a n b
-------
a 1 val
b 2 val
c 3 val

> What happens when there are multiple users who connect to remote q
process and create same global variable name?

The second user's definition will overwrite the first user's definition, unless you have some sort of setup that each user's queries go into a seperate user namespace...??

Regards,

Andrew?

Regarding “per user namespace” problems, this can be one way of doing
a crude separation of users sharing a Q process:

.z.pg:{
0N!"User, get: ",string .z.u;
system “d .usr.”,string .z.u;
x y} .z.pg

.z.ps:{
0N!"User, set: ",string .z.u;
system “d .usr.”,string .z.u;
x y} .z.ps

.z.pc:{
0N!“User, close: “,string .z.u;
delete from `$”.usr.”,string .z.u}

This still don’t have an answer.
Is this by design?