kdb q:';{因为换行而出错?

kdb q:';{因为换行而出错?,kdb,Kdb,我是一个q新手,正在尝试编写一个csv保存函数 CSVsave:{[filename;table] filename: $[-11h = type filename;filename;`$":", filename]; @[hdel;filename;()]; h: hopen filename; (neg h) csv 0: table; hclose h; }; 当我把它放到一个文件IO.q中时 \l IO.q 我收到一条错误消息 k){0N!x

我是一个q新手,正在尝试编写一个csv保存函数

CSVsave:{[filename;table]
    filename: $[-11h = type filename;filename;`$":", filename];
    @[hdel;filename;()];
    h: hopen filename;
    (neg h) csv 0: table;
    hclose h;
};
当我把它放到一个文件IO.q中时

\l IO.q
我收到一条错误消息

k){0N!x y}
'{
@
"q"
"CSVsave:{[filename;table]\n    filename: $[-11h = type filename;filename;`$\..
但是如果我删除新行并将所有内容放在一行中

CSVsave:{[filename;table]     filename: $[-11h = type filename;filename;`$":", filename];    @[hdel;filename;()];    h: hopen filename;    (neg h) csv 0: table;    hclose h;};
它运行良好


我是否遗漏了一些明显的内容?

最后一个括号前的空格

CSVsave:{[filename;table]
    filename: $[-11h = type filename;filename;`$":", filename];
    @[hdel;filename;()];
    h: hopen filename;
    (neg h) csv 0: table;
    hclose h; };

我还建议尝试kdb IDE,而不是不断地保存负载。例如,qStudio在最后一个括号前留出一个空格

CSVsave:{[filename;table]
    filename: $[-11h = type filename;filename;`$":", filename];
    @[hdel;filename;()];
    h: hopen filename;
    (neg h) csv 0: table;
    hclose h; };

我还建议尝试kdb IDE。而不是不断地保存负载。例如,qStudio

任何多行代码都需要在脚本中缩进。大多数人都缩进他们的函数体,所以只需注意右大括号。如果你有类似

select ...
from ...
where ...
然后以“from”和“where”开头的行也需要缩进。或者至少上次我试过了


另外,我非常推荐kdb studio!我无法想象没有它的开发。

任何多行代码都需要在脚本中缩进。大多数人都会缩进他们的函数体,所以只需注意右大括号。如果你有这样的脚本

select ...
from ...
where ...
然后以“from”和“where”开头的行也需要缩进。或者至少上次我试过了


另外,我非常推荐kdb studio!我无法想象没有它的发展。

几年前我刚加入q时,我花了一天时间试图找出我做错了什么。答案是,在结束大括号之前需要一个空格。它可以是独立的,但在它之前只需要一个空格。为什么?不知道。事情就是这样

CSVsave:{[filename;table]
    filename: $[-11h = type filename;filename;`$":", filename];
    @[hdel;filename;()];
    h: hopen filename;
    (neg h) csv 0: table;
    hclose h;
 };

几年前,我刚接触q的时候,我花了一天时间试图找出我做错了什么。答案是,在结尾的花括号之前需要一个空格。它可以在自己的线上,但在它之前只需要一个空格。为什么?不知道。就是这样

CSVsave:{[filename;table]
    filename: $[-11h = type filename;filename;`$":", filename];
    @[hdel;filename;()];
    h: hopen filename;
    (neg h) csv 0: table;
    hclose h;
 };

谢谢John。我尝试过qStudio,但当代码中有“show xxx”行时,它似乎失败了。qStudio将在第一次打印返回时挂起。谢谢John。我尝试过qStudio,但当代码中有“show xxx”行时,它似乎失败了。qStudio将在第一次打印返回时挂起。