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

csv.bqn doesn't handle empty fields at the end of data correctly #4

Closed
shnarazk opened this issue Jul 20, 2023 · 2 comments
Closed

Comments

@shnarazk
Copy link
Contributor

Hi,
I found Split in csv.bqn converts "ab,,bc," to ⟨ "ab" ⟨⟩ "bc" ⟩ instead of ⟨ "ab" ⟨⟩ "bc" ⟨⟩ ⟩.
And it emits the following error by "ab,,bc,,":

Error: ⊔: ≠𝕨 must be either ≠𝕩 or one bigger (5≡≠𝕨, 3≡≠𝕩)
test/../csv.bqn:22:
    (0∾s/+`e<n) ⊔ (d(¬⊸×-⊣)+`s) ⊔ 𝕩
                ^
test/csv.bqn:19:
  ! ⟨⟨"ab",⟨⟩,"bc",⟨⟩,⟨⟩⟩⟩ ≡ c.Split "ab,,bc,,"
                               ^^^^^

So I came up with the following.

$ diff -u csv.bqn csv-rev.bqn
--- csv.bqn     2023-07-20 07:32:01
+++ csv-rev.bqn      2023-07-20 14:19:51
@@ -24,7 +19,7 @@
   e ← ≠`q       # Escaped characters
   s ← e<c∨n     # Split points
   d ← s∨q>»e<q  # Characters to be dropped
-  (0∾s/+`e<n) ⊔ (d(¬⊸×-⊣)+`s) ⊔ 𝕩
+  (0∾s/+`e<n) ⊔ (1++´s)↑(d(¬⊸×-⊣)+`s) ⊔ 𝕩
 }
                                                                                        
 # Parse list of lines, e.g. from •file.Lines

This seems to work well. But I don't know if it's the best solution... 😄

@mlochbaum
Copy link
Owner

That fix is fine, although I might shorten 1++´s to 1+´s. I usually try to build the length into the left argument somehow, so that's what I did instead.

@shnarazk
Copy link
Contributor Author

Wow. Anyway, thank you.

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

2 participants