lua中的准引用/引用? [英] quasiquote/quote in lua?
本文介绍了lua中的准引用/引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Lisp中,我可以拥有:
In Lisp, I can have:
(a b c d e f g)
这意味着
look up b, c, d, e, f, g
look up a; apply value of a to above
然后,我也可以拥有:
`(a b c d e f g)
这等同于
(list 'a 'b 'c 'd 'e 'f 'g)
现在,在lua中,我可以拥有:
Now, in lua, I can have:
[snipplet 1]
foo = {
Foo,
{Cat, cat},
{Dog, dog}
};
最有可能将其扩展为: {nil,{nil,nil},{nil,nil}}
Which ends up most likely expanding into: { nil, { nil, nil}, {nil, nil}}
我真正想要的是这样的东西:
Whereas what I really want is something like:
[snipplet 2]
{ "Foo", {"Cat", "cat"}, {"Dog", "dog"}}
在lua中是否有类似反引号的方法?
Is there some backquote-like method in lua?
我发现[摘要1]比[摘要2]在视觉上更令人愉悦,但我的意思是摘要2.
I find [snipplet 1] to be more visually pleasing than [snipplet 2], but what I mean is snipplet 2.
谢谢!
推荐答案
没有语法,但是您可以尝试以下运行时解决方案:
There's no syntax for that but you can try this run-time solution:
setmetatable(_G,{__index=function (t,k) return k end})
这使所有未定义的变量的行为就像它们包含名称一样的字符串.
This makes all undefined variables behave as if they contained strings with their names.
这篇关于lua中的准引用/引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文