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

Classlib: Allow any type of text stream in the FileReader hierarchy #5611

Merged
merged 2 commits into from
Feb 27, 2022

Conversation

jamshark70
Copy link
Contributor

Purpose and Motivation

c = CollStream("5,7,hello,\"a comma, in quotes!\"");
r = CSVFileReader(c);

ERROR: Primitive '_FileOpen' failed.
Wrong type.

But... FileReader's interaction with the stream is, in total:

  • stream.reset -- CollStream implements this
  • stream.getChar -- CollStream implements this
  • stream.close -- CollStream doesn't implement this, but we can use tryPerform to make it a no-op

So there is not a compelling reason why a FileReader must be accessing a file on disk and disallow a stream of characters in memory.

(Editorial: The usual OOP advice is to program toward interfaces rather than class hierarchies: respondsTo rather than isKindOf. This looks like a case where "oh, isKindOf will be fine just this once" except that it isn't, not really.)

Since the really relevant operation is getChar, this PR changes the FileReader constructor so that any object implementing getChar will be allowed as the stream.

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • Updated documentation -- Note that the entire FileReader hierarchy has spotty documentation. "Updated documentation" would require essentially a complete rewrite of four or five help files. I'm afraid at the moment I don't have time to do that. If someone is concerned about this, I would recommend opening an issue.
  • This PR is ready for review

@jamshark70 jamshark70 added bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library labels Nov 13, 2021
@joshpar joshpar self-assigned this Feb 20, 2022
Copy link
Member

@joshpar joshpar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request changes just for feedback on my comment - probably fine otherwise.

@joshpar joshpar merged commit 03c2799 into supercollider:develop Feb 27, 2022
@jamshark70
Copy link
Contributor Author

Sorry, late to reply -- wrt "If tryPerform(\close) fails," tryPerform swallows only does-not-understand. It doesn't handle other errors. So this change will not cause other types of silent failure.

Thanks for the merge!

x = 1;

// tryPerform vs DoesNotUnderstandError

x.flurghle;  // Message 'flurghle' not understood.

x.tryPerform(\flurghle);  // no error

// tryPerform vs other errors

x.perform('+', 2);  // 3

x.perform('+', nil);  // binary operator '+' failed.

try { x.perform('+', nil) };  // nil (no error)

x.tryPerform('+', nil);  // binary operator '+' failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants