⎕VFI empty delimiter behaviour

General APL language issues

⎕VFI empty delimiter behaviour

Postby magnetron on Mon Jul 31, 2023 1:12 am

⎕VFI handling of empty delimited text ...

⎕VFI flags valid numeric values with a '1' in the first returned vector and corresponding values in the second vector. Non-numeric values are marked with a '0' in both vectors. In edge cases, when a delimiter appears at the start, end or in succession within the string, the current behavior treats these delimiters as indicating empty values that default to a valid numeric '0', as illustrated below (brackets added for clarity):

'x'⎕VFI'xMyx2xxHatx3x'
Returns: (1 0 1 1 0 1 1) (0 0 2 0 0 3 0)

Similarly when the function encounters a blank string between delimiters; the blank is also treated as a valid numeric '0':

'x'⎕VFI'xMyx2x xHatx3x'
Currently returns: (1 0 1 1 0 1 1) (0 0 2 0 0 3 0)

The presumption that all empty spaces inferred by delimiters equate to a valid numeric 0, particularly in the case of explicit blanks, may not be universally applicable. I propose introducing a variant option, such as ⍠ n where n could be 0 or '', thus providing an explicit override for the default "empty" condition. Thus, for example:

'x'(⎕VFI ⍠'') 'xMyx2x xHatx3x'
Proposed return: (0 0 1 0 0 1 0) (0 0 2 0 0 3 0)

It's possible I've overlooked a caveat in the documentation, but based on my findings and proposed solution, I believe this change could enhance the function's flexibility and better handle edge cases.
magnetron
 
Posts: 2
Joined: Tue Sep 06, 2016 9:29 am
Location: New Zealand

Re: ⎕VFI empty delimiter behaviour

Postby paulmansour on Mon Jul 31, 2023 3:14 pm

Funny I never noticed that behavior, it really seems it should not return a valid number.

For what it's worth, I have taken to using ⎕CSV rather than ⎕VFI for many use cases. It will handle conventional negative signs, thousands separators, and not turn blanks into valid zeros.
paulmansour
 
Posts: 431
Joined: Fri Oct 03, 2008 4:14 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest