Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are empty tables prohibited or not? #1697

Open
westluke opened this issue Jul 31, 2023 · 7 comments
Open

Are empty tables prohibited or not? #1697

westluke opened this issue Jul 31, 2023 · 7 comments

Comments

@westluke
Copy link

Shriram and I noticed a funny thing about tables the other day!

If you try to create a table with an empty schema using table: end, you get the message "This table has no column names, but tables must have at least one column." But that's not true! Because the expression (table: colname row: 3 end).drop("colname") doesn't throw an error, and gives you a table without columns.

The B2T2 spec requires the ability to make tables with an empty schema, so it seems like the table: end syntax should work.

Originally posted in the code.pyret.org repo, but that was a mistake.

@bennn
Copy link
Member

bennn commented Jul 31, 2023

My 2c:

  • table: end should be an error (but reword the message be be true), and
  • there should be a special constructor (empty-table() ?) for saying yes, I really do want an empty table

@jpolitz
Copy link
Member

jpolitz commented Jul 31, 2023

I think @bennn 's suggestion is great. The error can say “if you really meant to make an empty table, use empty-table

@shriram
Copy link
Member

shriram commented Jul 31, 2023

I like it too, with that error message!

@blerner
Copy link
Member

blerner commented Aug 1, 2023

Hmm, counterargument: table: x, y, z end is valid. table: x, y end is valid. table: x end is valid. So shouldn't table: end be valid and be a zero-column, zero-row table?

@shriram
Copy link
Member

shriram commented Aug 1, 2023

Well, that was the original argument. Why was it ever disallowed?

@blerner
Copy link
Member

blerner commented Aug 1, 2023

I think it was a question of whether the table could grow or not. An empty table with multiple columns could add new rows. Could an empty table with no columns add new rows? Explicitly, is [raw-row: ] a valid value?

@shriram
Copy link
Member

shriram commented Aug 1, 2023

Yes, it would seem to me we can have a table of no columns with N rows. Then, when we add a column, we can provide (say) a list of N values and each one would extend one of those empty rows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants