Quasiquote / quote in lua?

In Lisp, I can:

(a b c d e f g)

      

which means

look up b, c, d, e, f, g
look up a; apply value of a to above

      

Then I can also have:

`(a b c d e f g)

      

which is equiv <

 (list 'a 'b 'c 'd 'e 'f 'g)

      

Now, in lua, I can:

[snipplet 1]
foo = {
  Foo,
  {Cat, cat},
  {Dog, dog}
};

      

This is most likely an extension: {nil, {nil, nil}, {nil, nil}}

While what I really want is something like:

[snipplet 2]
{ "Foo", {"Cat", "cat"}, {"Dog", "dog"}}

      

Is there some kind of backquote method in lua?

I find [snipplet 1] more visually pleasing than [snipplet 2], but I mean snipplet 2.

Thanks!

+2


a source to share


2 answers


There is no syntax for this, but you can try this solution at runtime:

setmetatable(_G,{__index=function (t,k) return k end})

      



This causes all undefined variables to behave as if they contained strings with their names.

+6


a source


Consider a function that parses a string containing Lisp syntax and builds a table from that.



0


a source







All Articles