datalog icon indicating copy to clipboard operation
datalog copied to clipboard

REPL does not work

Open greenfork opened this issue 4 years ago • 10 comments
trafficstars

I'm new, just installed Racket v8.0, trying to follow tutorial https://docs.racket-lang.org/datalog/Tutorial.html.

I expect REPL to print me same results as when I execute code:

> parent(A, B)?
parent(john, douglas).
parent(bob, john).
parent(ebbon, bob).

but it doesn't happen.

Here is my DrRacket screenshot: image

Here is my shell session:

grfork@pisec ~/p/r/datalog> cat test.rkt
#lang datalog

parent(john, douglas).
parent(bob, john).
parent(ebbon, bob).
parent(A, B)?
grfork@pisec ~/p/r/datalog> racket
Welcome to Racket v8.0 [cs].
> ,en "test.rkt"
parent(john, douglas).
parent(bob, john).
parent(ebbon, bob).
"test.rkt"> parent(A, B)?
; <pkgs>/datalog/stx.rkt:64.35: datalog-stmt: bad syntax
;   in: (datalog-stmt parent)
; [,bt for context]
; <pkgs>/datalog/stx.rkt:64.35: datalog-stmt: expected one of these
;   identifiers: `!', `~', or `?'
;   at: A
;   in: (datalog-stmt (A (unquote B)))
; [,bt for context]
; <pkgs>/datalog/stx.rkt:64.35: datalog-stmt: bad syntax
;   in: (datalog-stmt ?)
; [,bt for context]
"test.rkt"> ^D

greenfork avatar Feb 25 '21 15:02 greenfork

This works in DrRacket BC but not in DrRacket CS. Really bizarre.

It's never meant to work in command-line REPL. If you take a look at the error message, you will see that it tries to parse your input as a Racket program. E.g.,

parent(A, B)?

is read as:

parent
(A (unquote B))
?

sorawee avatar Feb 25 '21 22:02 sorawee

Working in BC but not CS means it's likely a Racket-level bug. cc @mflatt

samth avatar Feb 25 '21 22:02 samth

Looks like the problem is with char-ready?, which returns differently in BC vs CS.

https://github.com/racket/datalog/blob/master/lang/configure-runtime.rkt#L12

sorawee avatar Feb 25 '21 22:02 sorawee

I've pushed a repair for char-ready?, but I'm skeptical that char-ready? is ever appropriate in a parser.

(Really, I'm skeptical of almost any program that uses char-ready?. The CS bug may have gone undetected until now because char-ready? is so rarely useful.)

mflatt avatar Feb 26 '21 18:02 mflatt

It is only here:

https://github.com/racket/datalog/blob/057771889eff193e5442a0c95b8c837bac4c241c/lang/configure-runtime.rkt#L10

And I seem to recall putting it in because when DrRacket does parsing, it doesn't give a port that has an EOF, because there might be more, and if you just do the peek-char then it will hang. This happened 8 years ago so I only have a vague memory --- https://github.com/racket/datalog/commit/d7c8cdd938cecc976f049b1dd154ae7c581fe9fd

jeapostrophe avatar Feb 26 '21 18:02 jeapostrophe

I think DrRacket's REPL can have multiple EOFs (one per interaction). Maybe that's what you're thinking of?

rfindler avatar Feb 26 '21 19:02 rfindler

Perhaps?

jeapostrophe avatar Feb 26 '21 19:02 jeapostrophe

FWIW I found this EOF protocol to be:

  • difficult to understand in the first place
  • tricky to get working when the REPL is connected via stdin/stdout
  • and later, more or less "impossible" when connected via TCP ports (which is what Racket Mode does these days, to support multiple REPLs from one back end process connected to Emacs).

TL;DR it was confusing, I got it working(ish), but then had to abandon it.


Is there another possible protocol?

I think this could be one of a few items on a hypothetical roadmap, "Improving the LOP story for non-sexp langs".

greghendershott avatar Mar 02 '21 20:03 greghendershott

Sounds like a nice thing to sort out!

rfindler avatar Mar 02 '21 21:03 rfindler

This issue has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/current-read-interaction-returning-eof/1032/1