cancel
Showing results for 
Search instead for 
Did you mean: 

Underscore in variable names inside k4.

Krishna
New Contributor
Dear q (and k4) folks, 
I was writing some code in k4(oh, the joy!) and was having trouble using variables with "_" in them. I can avoid this in my code, but when I use the embedPy module, some names imposed by python(e.g: fit_transform) signal errors. 
How may I work with this? Is there a way to escape the "_" so k4 accepts it? Please advise.

Thank you, 
Kumar

Virus-free. www.avast.com
5 REPLIES 5

Alexander_Belop
New Contributor


On Monday, January 22, 2018 at 7:25:42 AM UTC-5, Krishna wrote:
Is there a way to escape the "_" so k4 accepts it? 

If you create a variable with an _ in the name in q, you should be able to retrieve it from k4 as follows:

q)foo_bar:42
q)\
  `. `$"foo_bar"
42 

You can also reset it with

  @[`.;`$"foo_bar";:;43]
  \
q)foo_bar
43

This is not pretty and if you have to work with such names, it is probably better to do it in q.

Thanks very much, Alexander. For purposes of embedPy calling from inside k4(although superfluous, when there is convenient calling from inside q), I managed to conjure the following :
`$"fit_transform" - this returns a `fit_transform, which is what the python call inside embedPy requires. This does the job. 

As for using "_" inside variable names inside k4, i shall avoid it like the plague. 

Quick question - what does the `. do, inside k4? 

Cheers, 
Kumar

q)value`.    /is a dictionary
foo_bar| 42



On Tuesday, January 23, 2018 at 4:28:41 AM UTC-5, Krishna wrote:

Quick question - what does the `. do, inside k4? 

`. is the name of the root namespace, but on the second thought, simply using the . function (eval) is probably better:

  q)foo_bar:42
  .`$"foo_bar"
42 

Thanks, Alexander. 
Kumar