prql
prql copied to clipboard
feat: use let for table def
Ref #523
I find this quite reasonable.
One downside is that we only allow tables here — and probably only ever will, since everything can be represented by a table, and having a consistent type there simplifies things.
Will folks try doing:
let x = 5
from employees
filter id = x
...which looks like it should work, but doesn't?
I guess one option would be to force typing, too verbose but makes the point:
let x<table> = ...
I also think it's worth considering whether we should align the func and table definition syntax. With the proposed code, they don't look that similar:
let foo_table = (from employees)
func add a b -> a + b
Arguably the corollary of the proposed code would be to define funcs like:
let add = func a b -> a + b
# or
let add = a b -> a + b
# or
let add<func> = a b -> a + b
I recognize those suggestions widen the aperture of options rather than focus us — I don't mean to reopen every discussion about these. But in this case I do think it's worth ensuring the whole language is coherent. What do others think?
Actually, signaling that you could define constants was my intention. Currently it (should) throw an error saying it's expecting a table, but this is a feature that does have use-cases.
See the linked issue for my comment about that.
I agree with @max-sixty 's point that we should try to ensure the language remains coherent.
I'm in the process of writing up a bigger discussion around "Tables, transforms and pipelines" which I'll post in the discussions section. I've been trying to formulate my thought around that for months and I think I actually had a breakthrough insight yesterday (for me).
The points raised about functions and constants open the scope even further so can we hold on this for a bit until we've had time to discuss this in more depth?
Agreed. Let's leave this PR open until then.
Thanks. The discussion is in #1323 .
Great! I'm a +0.7.
We should update the docs and the grammars too, and do a release, so the docs aren't out of date for something so fundamental. I'm happy to own those.
As mentioned in #523 , I had a discussion with Aljaz on this and had misunderstood an aspect of this. Very happy with this feature now.
Thanks!