tools.reader

Reading comment should not throw exception

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

I have notice a discrepancy in how comments are read between cljs.tools.reader/read-string and cljs.reader/read-string.

In cljs.reader, as shown here no exception is thrown but nil is returned, concretely ignoring the comment.

Conversely, the following throws:

(r/read-string {:read-cond :allow :features #{:cljs ;; comment) ;;+> EOF

In my opinion the cljs.reader is the correct one and cljs.tools.reader should be patched, but of course there might be a reason I ignore to throw an exception.

Activity

Hide
Nicola Mometto added a comment -

This is consistent with how the clojure reader works, and the correct behaviour.
Reading a comment is not the same as reading nil

Show
Nicola Mometto added a comment - This is consistent with how the clojure reader works, and the correct behaviour. Reading a comment is not the same as reading nil
Hide
Andrea Richiardi added a comment -

Can you expand on this a bit? The reader should ignore comments, so it is like the reader is actually reading nothing (therefore nil). Maybe I am missing?

Show
Andrea Richiardi added a comment - Can you expand on this a bit? The reader should ignore comments, so it is like the reader is actually reading nothing (therefore nil). Maybe I am missing?
Hide
Nicola Mometto added a comment -

The reader must return the object it read. If there's nothing to read, an EOF exception signales that the stream terminated before it could find an object to read. Otherwise reading nil and reading nothing would mean different things in different contexts

Show
Nicola Mometto added a comment - The reader must return the object it read. If there's nothing to read, an EOF exception signales that the stream terminated before it could find an object to read. Otherwise reading nil and reading nothing would mean different things in different contexts
Hide
Andrea Richiardi added a comment -

Thanks, it was just for curiosity, of course a lot of clever people have already thought about this. I am then a bit surprised by the different behaviour in cljs.reader but this is another story.

Show
Andrea Richiardi added a comment - Thanks, it was just for curiosity, of course a lot of clever people have already thought about this. I am then a bit surprised by the different behaviour in cljs.reader but this is another story.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: