0

I can define view either by loading a q script, or interactively from console:

q)myview::a+b                / even semi-programmatically using ugly strings: value"myview::a+b"

Some exploration:

q)value `. `myview
::
(+;`a;`b)
`a`b
"a+b"

I can see that my newly-designed view is now part of the the global environment dictionary:

q)select myview from `.
myview| a+b

The value part of that key-value pair is a list of lambda types:

q)-3!value select myview from `.
",a+b"
q) type first value select myview from `.
100h

Even though {a+b} is lambda type as well ...

q)type {a+b}
100h

... the a+b and {a+b} are not the same thing:

q){a+b} ~ first value select myview from `.
0b

Question: Now that myview is defined in the global environment, how can I change its definition programmatically, to say a+c lambda expression, by referring to that view by name, i.e. `myview?

For example, I may want to process this input:

q)config:()!(); config[`myview]:"a+c"
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75

2 Answers2

1

Views are not parseable (see the very last line at http://code.kx.com/q/tutorials/views/) so it seems that "using ugly strings" is your only option:

q)show config:`view1`view2!("a+b"; "c+d")
view1| "a+b"
view2| "c+d"
q)defView:{value string[x],"::",y}
q)defView'[key config; value config]
q)\b
`s#`view1`view2
q)view1
'b
q)a:1;b:2
q)view1
3
Igor Korkhov
  • 8,283
  • 1
  • 26
  • 31
0

Does something like this achieve what you are looking for?

q)f:{value "::" sv (string x;y)}
q)f[`myview;"a+b"]
q)select myview from `.
myview| a+b
Gilmer
  • 410
  • 3
  • 8
  • thanks, any way using expressions rather than string manipulation? ``f[`myview; a+c] `` would throw `'c` error. And encapsulating expression in curly braces `{a+c}` to delay evaluation is obviously something else. Can't get my head around manipulating the right-hand side of `myview| a+c` – Daniel Krizian Jun 15 '17 at 22:04