1. List of tables
Command \a [namespace]
q)\a
`symbol$()
q)t:([] c1:`a`b`c; c2:10 20 30)
q)\a
,`t
q).jab.t:([] c1:`a`b`c; c2:10 20 30)
q)\a .jab
,`t
2. Views/Alias
Command \b [namespace]
q)\b
`symbol$()
q)a:42
q)b::a+1
q)c::b*b
q)\b
`s#`b`c
3. Pending Views/Alias
Command \B [namespace]
returns a sorted list of the symbolic names of the aliases (a.k.a. views, dependencies) in a context that are stale – i.e., there is a pending update that will be realized on the next reference.
q)x:42
q)a::x+1
q)\B
,`a
q)a
43
q)\B
`symbol$()
4. Console \c
q)\c
25 80i
q)\c 10 20
q)2#enlist "abcdefghijkmlnopqrstuvwxyz"
"abcdefghijkmlnop..
"abcdefghijkmlnop..
5. Change OS Directory \cd
q)\cd
"/Users/jeffry"
q)\ls /data
q)\cd /data/new
q)\ls /data
"new"
6. Error Trap \e
7. Functions \f
displays a sorted list of symbolic names of functions in the current, or specified, working context.
q)\f
`symbol$()
q)f:{x*x}
q)g:{x*x*x}
q)\f
`s#`f`g
q).jab.f:{[] 42}
q)\f .jab
,`f
8. Garbage Collection \g
9. GMT Offset \o
displays or changes the offset from GMT for q date/time values in the current q session.
q).z.t / GMT
15:20:10.892
q).z.T / I live in NY
11:20:07.700
q)\o / Using OS offset
0Ni
q).z.t-.z.T / No daylight savings in UK yet
04:00:00.000
q)\o -10 / Think about moving to Hawaii
q).z.T / Much better
05:21:23.155
q).z.t-.z.T / Hawaii doesn’t use daylight saving
10:00:00.000
10. Port \p
displays or changes the port on which the q process is listening. In a fresh q session the value is 0i
q)\p
0i
q)\p 5042
q)\p
5042i
q)\p 0
11. Display Precision (\P)
q)\P
7i
q)1%3
0.3333333
q)2%3
0.6666667
q)\P 0
q)1%3
0.33333333333333331
q)\P 2
q)1%3
0.33
12. Elapsed Time \t expr
the expression is evaluated and the execution duration in milliseconds is reported. This can be used to profile code execution when tuning an application.
Some expressions execute so quickly in q that the result is less than the timer granularity. Fortunately \t:x
obviates what was formerly the only valid use of do in q – namely, repeating the expression evaluation to raise its execution time above the timer floor.
q)\t sum til 100000
0
q)\t:1000 sum til 100000
453
13. Elapsed Time and Space (\ts expr)
an enhancement of the version of \t that times an expression. It provides both the time and the number of bytes used in evaluating the expression.
q)\ts log til 100000
4 3145856
q)\ts:100 log til 100000
248 3145824
14. Timeout \T
The command (note upper case) sets the number of seconds a remotely initiated execution will run before timing out. The default value is 0, meaning that such execution will not timeout. This is useful to protect against runaway client calls when the q process is acting as a server.
15. Variables \v
command displays a sorted list of symbolic names of all variables in the specified context when the namespace parameter is present, or the current working context if it is not.
q)\v
`symbol$()
q)a:b:c:42
q)\v
`a`b`c
q)\v .
`a`b`c
q).jab.a:43
q)\v .jab
,`a
16. Workspace \w
displays information about resource utilization in the current q session. When the parameter is not present, it returns a list of six integers:
-
Number of bytes allocated
-
Number bytes available in heap
-
Maximum heap size used heretofore in session
-
Maximum bytes available as specified at startup in
-w -
Number of bytes for mapped entities
-
Number of bytes of physical (i.e. machine) memory
q)\w 118256 67108864 67108864 0 0 17179869184 q)bigdata:til 200000000 q)\w 2147601952 2214592512 2214592512 0 0 17179869184
When the parameter is present, \w 0 returns a list with two items relating to symbol usage: the number of symbols and the corresponding number of bytes of memory used. For example, in a fresh q session on the author’s laptop:
q)\w 0
566 18470
q)lottasyms:1000000?`5
q)\w
4312768 67108864 67108864 0 0 17179869184
17. Expunge Handler \x
The expunge handler command un-assigns a user specified event handler for one of the .z.* event handlers and restores the default system behavior. For example, here is how you can customize the console response and then restore the original behavior.
q).z.pi:{"==>",.Q.s value x}
q)42
==>42
q)43
==>43
q)\x .z.pi
==>q)43
43
q)44
44
18. Date Format \z
The date parsing format command displays or specifies the format for date parsing. A value of 0 corresponds to month-then-day – as in mm/dd/yyyy – and a value of 1 corresponds to day-then month – as in dd/mm/yyyy. The default value is 0i.
q)\z
0i
q)"D"$"12/31/2015"
2015.12.31
q)"D"$"31/12/2015"
0Nd
q)\z 1
q)"D"$"12/31/2015"
0Nd
q)"D"$"31/12/2015"
2015.12.31
出处:hhttps://code.kx.com/q4m3/13_Commands_and_System_Variables/
作者:Jeffry A. Borror