ClojureScript

Sending EOF (^D) to command-line REPL causes infinite loop

Details

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

Description

Need to make forms-seq distinguish between nil and EOF.

Activity

Hide
Travis Thieman added a comment -

Patch: 20131104

Exit REPL on ^D and don't infinite loop when evaluating nil.

Show
Travis Thieman added a comment - Patch: 20131104 Exit REPL on ^D and don't infinite loop when evaluating nil.
Hide
Chas Emerick added a comment -

This is close. What you want is to have forms-seq terminate when you get an EOF, and to use a value that is guaranteed to not be emitted by the reader otherwise (the current patch will terminate the REPL if you type ":reader-eof", which isn't good).

The general pattern is to let-bind a sentinel object (i.e. (Object.)), and use that as the value returned from the reader on EOF. If it is, just return nil from forms-seq.

On the REPL side, all you need to do is bind form to :cljs/quit if forms is empty, and the REPL will exit naturally.

Show
Chas Emerick added a comment - This is close. What you want is to have forms-seq terminate when you get an EOF, and to use a value that is guaranteed to not be emitted by the reader otherwise (the current patch will terminate the REPL if you type ":reader-eof", which isn't good). The general pattern is to let-bind a sentinel object (i.e. (Object.)), and use that as the value returned from the reader on EOF. If it is, just return nil from forms-seq. On the REPL side, all you need to do is bind form to :cljs/quit if forms is empty, and the REPL will exit naturally.
Hide
Travis Thieman added a comment -

Patch: 20131104-2

Updated as per Chas's suggestions.

Show
Travis Thieman added a comment - Patch: 20131104-2 Updated as per Chas's suggestions.
Hide
Chas Emerick added a comment -

Thanks for the edits Travis.

Show
Chas Emerick added a comment - Thanks for the edits Travis.
Hide
Travis Thieman added a comment -

Thanks for helping me write better code!

Show
Travis Thieman added a comment - Thanks for helping me write better code!

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: