Eugleo / magic-racket

The best coding experience for Racket in VS Code
https://marketplace.visualstudio.com/items?itemName=evzen-wybitul.magic-racket
GNU General Public License v3.0
204 stars 28 forks source link

Hard to describe I/o problems #121

Closed lewisl closed 1 year ago

lewisl commented 1 year ago

Environment

Error message

There is no error message. Just incorrect results

Additional context

An endemic problem to all Schemes is inconsistency for 'read-line', 'show', 'display' and their behavior in the repl. The following works in Dr Racket, which works but is not a very good editor or runtime environment. It's just the "reference implementation" for racket, a racket editor and a racket repl. I'll try to see what happens in terminal assuming I can get 'racket' running in a terminal to use a #lang (sure there is a way: Google will tell me how...)


here is a fragment of the file and the output:

#lang simply-scheme

;;; The functions program

(define (functions)
  ;; (read-line)
  (show "Welcome to the FUNCTIONS program.")
  (functions-loop))

(define (functions-loop)
  (let ((fn-name (get-fn)))
    (if (equal? fn-name 'exit)
    "Thanks for using FUNCTIONS!"
    (let ((args (get-args (arg-count fn-name))))
      (if (not (in-domain? args fn-name))
         (show "Argument(s) not in domain.")
         (show-answer (apply (scheme-function fn-name) args)))
      (functions-loop)))))

(define (get-fn)
  (display "Function: ")
  (let ((line (read-line)))
    (cond ((empty? line)
       (show "Please type a function!")
       (get-fn))
      ((not (= (count line) 1))
       (show "You typed more than one thing!  Try again.")
       (get-fn))
      ((not (valid-fn-name? (first line)))
       (show "Sorry, that's not a function.")
       (get-fn))
      (else (first line)))))

It works, but none of the prompt messages appear. Output:

"functions.scm"> (functions)
Welcome to the FUNCTIONS program.
tan
1.0
Function: Argument: 
The result is: 1.557407724654902

I don't know if there is anything to be done. I/O is super-fragile across schemes because it is super inconsistent. Schemes don't even have the same functions; functions with the same names do different things; behavior of REPLs is essentially undefined so left to the implementer. I can't really see any way to create a semi-portable Scheme program that does console I/O. Academics can't be bothered with the ugly, unseemly real world. Of course, the real world is the only real world the rest of us get to live in.

lewisl commented 1 year ago

Well, this is not yours to fix. The Racket Repl when run from the command line in iTerm is broken in exactly the same way. First, it is unnecessarily hard to get racket to load with a module (e.g.--a file that starts with #lang .

racket <enter>
Welcome to Racket v8.9 [cs].
> (enter! "functions.scm")
"functions.scm"> (functions)
Welcome to the FUNCTIONS program.
tan      ; note absence of prompt  that should have resulted from (show "Please type a function!")
1.0      ; note absence of prompt from (display "Argument: ")
Function: Argument: 
The result is: 1.557407724654902

Note that the prompts occur when output is finally generated using

(define (show-answer answer)
  (newline)
  (display "The result is: ")
  (if (not answer)
      (show "#F")
      (show answer))
  (newline))

It is probably the (newline) that flushes the output buffer.

There is nothing you can do to fix this. it runs in Dr. Racket because of some magic. Here's what that looks like:

Welcome to DrRacket, version 8.9 [cs].
Language: simply-scheme, with debugging; memory limit: 128 MB.
> (functions)
Welcome to the FUNCTIONS program.
Function: tan
Argument: 1.0

The result is: 1.557407724654902

Function: exit
"Thanks for using FUNCTIONS!"
> 

It doesn't run in Gambit either.

Scheme just fucking sucks. The professors like to demonstrate how marvelous the theory of Scheme is and anyone who doesn't bow down is simply a dumb shit. They don't give a shit about the quality of their work. I like Scheme and Lisp the languages for how we express algorithms. But, as practical language they are worthless now--it's not the 60's any more. No more Symbolics machines. Just the real world with languages that are implemented by vastly more capable and responsible people. See Julia; see c++; see nim. Don't know much about Lua or Ruby but these fit and finish problems don't happen. I am marking closed because all you do is run the racket repl as it is. You can't fix that.

jryans commented 1 year ago

I agree there doesn't appear to be anything to do here, as you say, we're just running the Racket REPL.

As an aside, your rants are not appropriate for this space. If you wish to file future issues here, please stick to the facts and discuss them in professional manner.