> Sadly comparisons like < and == cannot be overloaded in Lua :(
You can overload == in 5.3. Before that, there was a slightly-less-overloadable __eq method. But as of 5.3, as long as the bound __eq method is the same underlying function, it will be called.
I assume you meant instead, that the return value of the comparison is always coerced to a boolean, so you can't re-use it to get arbitrary infix operators?
For that sort of thing, I've used Mike Pall's hack in the past:
local sm = setmetatable
local function infix(f)
local mt = { __sub = function(self, b) return f(self[1], b) end }
return sm({}, { __sub = function(a, _) return sm({ a }, mt) end })
end
local shl = infix(function(a, b) return a*(2^b) end)
print(5 -shl- 4)
Lua is nice because it can be embedded anywhere with very little overhead, but in my experience it’s very easy (and fun) to port Prela to most languages
Tarantool[1] has been using Lua for the queries since inception. Eventually 3rd party users complained enough that they added a SQL as a query frontend.
I often fantasize of a Linux distro that is pure Lua, like .. for everything, and literally nothing in the userland/config realm is anything but Lua, so even the interfaces to a GUI and so on, no other scripting languages, just full commit to Lua only. The ultimate rice.
There has been no shortage of query and SQL-like DSL's in different programming languages; however, when it comes to querying, Prolog is heavily underrated.
The interesting property of Prolog is that it needs neither a DSL nor a differentiation between input and output parameters at the level of its relational predicates. Joins, filtering, projection and grouping can all also be expressed using native Prolog constructs.
The same Prolog query can also be run in both directions, including the reverse. That is, if I known the «answer» (i.e. the result), I can ask Prolog to give me an exhaustive set of «questions» that may lead to the «answer».
The first sample query (named «exhibit1») from the blog post can be rewritten in Prolog thusly (SWI-Prolog is used in the example):
Since the author mentioned Rust and Lua I've bee chipping away at OmniLua for awhile https://github.com/ianm199/omnilua a project that bundles Lua 5.1-5.5 in one Rust project. Might be useful for this kind of thing!
Don't ever try Fennel. In general, don't ever try Lisp dialects. You will be disappointed seeing where everyone else has been moving. It would feel as if the industry at large chooses to stay foolish, for the sake of questionable gains.
And that's the silliest, most foolish justification ever. It's not like s-expressions make things unequivocally cryptic. If anything, things get far more readable - this can be observed by simply grabbing a small piece of JSON and converting it to idiomatic EDN - it's almost twice as compact, there's no redundant noise, commas are optional - things can be aligned and read in tabular form.
phillc73 | a day ago
It's built over DuckDB and Rayforce[2]. Single query, either engine.
[1] https://github.com/jennystats/janet-query
[2] https://github.com/RayforceDB/rayforce
shakna | a day ago
You can overload == in 5.3. Before that, there was a slightly-less-overloadable __eq method. But as of 5.3, as long as the bound __eq method is the same underlying function, it will be called.
I assume you meant instead, that the return value of the comparison is always coerced to a boolean, so you can't re-use it to get arbitrary infix operators?
For that sort of thing, I've used Mike Pall's hack in the past:
[OP] remywang | a day ago
behnamoh | a day ago
sumnole | a day ago
[OP] remywang | a day ago
PinkSheep | a day ago
[1]: https://en.wikipedia.org/wiki/Tarantool
Rohansi | a day ago
jeswin | 22 hours ago
By now battle-tested in production.
adhamsalama | 20 hours ago
jeswin | 14 hours ago
harrykris | a day ago
"it's not really a query langauge. It's just a bunch of Rust types and methods that give the feel of a query language" I FEEL THIS LMAO
nice project anyways love it
MomsAVoxell | 12 hours ago
I often fantasize of a Linux distro that is pure Lua, like .. for everything, and literally nothing in the userland/config realm is anything but Lua, so even the interfaces to a GUI and so on, no other scripting languages, just full commit to Lua only. The ultimate rice.
inkyoto | a day ago
The interesting property of Prolog is that it needs neither a DSL nor a differentiation between input and output parameters at the level of its relational predicates. Joins, filtering, projection and grouping can all also be expressed using native Prolog constructs.
The same Prolog query can also be run in both directions, including the reverse. That is, if I known the «answer» (i.e. the result), I can ask Prolog to give me an exhaustive set of «questions» that may lead to the «answer».
The first sample query (named «exhibit1») from the blog post can be rewritten in Prolog thusly (SWI-Prolog is used in the example):
Note that it uses the bog standard Prolog syntax. We can now ask to: Note how the query itself («exhibit1») does not change and remains the same for all queries.lenkite | 23 hours ago
Really ? I found the SQL far easier to read at a single glance compared to the special Lua syntax that I had to pause, focus and think on to grok.
ianm218 | 22 hours ago
steve_taylor | 22 hours ago
hoppp | 21 hours ago
lasajar | 21 hours ago
iLemming | 9 hours ago
CyberDildonics | 5 hours ago
iLemming | 4 hours ago