mppf1
1
19498, "mppf", "I/O module: adjustments to read methods", "2022-03-18T15:19:23Z"
proc channel.read(ref args...) : bool throws
proc channel.read(type t) : t throws
proc channel.read(type t...) : tuple throws
- In [#18496] discussed if we want both type and return-through-argument versions
- Seems that we want both forms because return-through-argument can return bool & is easier for loops
- ‘read(string)’ today just reads one word but that’s a common stumbling block [#7952, #15844]
- ‘read(myClass)’ fails if ‘myClass’ is ‘nil’ but arguably should allocate a class [#7950]
Proposal:
- Keep both type and non-type forms
- Use ‘out’ instead of ‘ref’ (requires also moving away from ‘ioLiteral’ and ‘ioNewline’) & allocate class instances
- With the default Decoder:
- ‘read(string)’ or ‘read(myString)’ should read until EOF and same for bytes
- (works with the default Encoder where e.g. ‘write(“Hello World”)’ will not output quotes)
- a read call containing a string as anything other than the last argument will throw
proc reader.read(out args..., decoder=reader.decoder()) : bool throws
proc reader.read(type t, decoder=reader.decoder()) : t throws
proc reader.read(type t..., decoder=reader.decoder()) : tuple throws
- The ‘out’ version will return ‘false’ and default initialize the arguments if it reached EOF
- It will produce a compilation error if any argument type is not default initializeable
- It will return ‘true’ for success or throw if there was an error, including a partial read before EOF
- The ‘type t’ version will throw if it reaches EOF