2015.06.21 06:51 PM
2015.06.22 12:15 AM
2015.06.22 08:46 AM
2015.06.22 08:55 AM
2015.06.23 01:01 AM
q).d1.a:1
q)0N!value `.d1
``a!(::;1)
| ::
a| 1
q)0N!value `.d1
``a`d2!(::;1;``a!(::;1))
| ::
a | 1
d2| ``a!(::;1)
And so on, for an arbitrarily deep nesting.
A final interesting thing to note on directories is that functions are dependent on the context they were created. The persistence is achieved because the function serialises the context in which it was created.
/ Function g defined in root directory:
q).aaa.g:{a+x}
/ Function h defined in aaa directory:
q)\d .aaa
q.aaa).aaa.h:{a+x}
Function g will always refer to the variable a on root directory and h on directory 'aaa'.
You can see how this is handled behind the covers by inspecting the IPC byte representation of both functions:
q)-8!.aaa.g
0x010000001500000064000a00050000007b612b787d
Endianess: 1 (little endian)
Length: 15
Type: 0x64 (100 - lambda)
Context: 00 (root)
Type: 0x0a (character vector)
Attributes: 0x0
Vector len: 5
Vector: 0x7b612b787d (“{a+x}”)
q)-8!.aaa.h
0x010000001800000064616161000a00050000007b612b787d
Endianess: 1 (little endian)
Length: 18
Type: 0x64 (100 - lambda)
Context: 0x61616100 (“aaa\0”)
Type: 0x0a (character vector)
Attributes: 0x0
Vector len: 5
Vector: 0x7b612b787d (“{a+x}”)
Regards,
Tiago
2015.06.23 07:28 AM
namespaces are built from dicts where the key is a vector of symbols, and there is a map from ` to (::).
q).z.vs:{0N!(x;y);}
q)a.d:4
(`a.d;())
q)a.b:1
(`a.b;())
q).a.b:1
--No, you can't change directories in a hierarchical fashion with \d, but its trivial to write a function analogous to 'cd ..' (change to upper level directory). This is arguably useless, since q does not allow you to change directories beyond the first level.If you want to play with the idea, you can get the current directory into a variable with c:value"\\d", and call \d from inside a function with eval parse "\\d ", dirRegarding the directory structure, its a tree built of nested dictionaries. For instance:q).d1.a:1
q)0N!value `.d1
``a!(::;1)
| ::
a| 1
Note the first element is a null. Now if we create a subdirectory, you get a nested dictionary:q)0N!value `.d1
``a`d2!(::;1;``a!(::;1))
| ::
a | 1
d2| ``a!(::;1)
And so on, for an arbitrarily deep nesting.
A final interesting thing to note on directories is that functions are dependent on the context they were created. The persistence is achieved because the function serialises the context in which it was created.
/ Function g defined in root directory:
q).aaa.g:{a+x}
/ Function h defined in aaa directory:
q)\d .aaa
q.aaa).aaa.h:{a+x}
Function g will always refer to the variable a on root directory and h on directory 'aaa'.
You can see how this is handled behind the covers by inspecting the IPC byte representation of both functions:
q)-8!.aaa.g
0x010000001500000064000a00050000007b612b787d
Endianess: 1 (little endian)
Length: 15
Type: 0x64 (100 - lambda)
Context: 00 (root)
Type: 0x0a (character vector)
Attributes: 0x0
Vector len: 5
Vector: 0x7b612b787d (“{a+x}”)
q)-8!.aaa.h
0x010000001800000064616161000a00050000007b612b787d
Endianess: 1 (little endian)
Length: 18
Type: 0x64 (100 - lambda)
Context: 0x61616100 (“aaa\0”)
Type: 0x0a (character vector)
Attributes: 0x0
Vector len: 5
Vector: 0x7b612b787d (“{a+x}”)
Regards,
Tiago
On Monday, 22 June 2015 16:55:03 UTC+1, Charles Skelton wrote:that page contains the answers, but you do have to think about it.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-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.
2015.06.22 10:38 AM
2015.06.23 08:22 AM
EMEA
Tel: +44 (0)28 3025 2242
AMERICAS
Tel: +1 (212) 447 6700
APAC
Tel: +61 (0)2 9236 5700
KX. All Rights Reserved.
KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.