joshibharathiramana
2020-12-16 11:21:54

How should I define loop so that this (loop (print (eval (read)))) will actually work as a REPL?


joshibharathiramana
2020-12-16 11:28:29

I have this definition that works (define (loop x) (loop (print (eval (read))))) but, is there anything more elegant?


sorawee
2020-12-16 11:32:53

If I were to write it to actually use it, I would write it as:

(let loop () (print (eval (read))) (loop))


sorawee
2020-12-16 11:33:56

But it looks like you are interested in the gimmick “REPL”, not good code quality.


sorawee
2020-12-16 11:34:18

sorawee
2020-12-16 11:37:26

Or:

(define-syntax-rule (loop e) (let go () e (go))) (loop (print (eval (read))))


joshibharathiramana
2020-12-16 12:44:22

@sorawee > But it looks like you are interested in the gimmick “REPL”, not good code quality. (edited) why do you consider it bad code?


sorawee
2020-12-16 12:45:02

The one in Twitter is pretty convoluted.


joshibharathiramana
2020-12-16 12:46:40

ah my bad, I thought you were talking about my definition (define (loop x) (loop (print (eval (read)))))


sorawee
2020-12-16 12:48:29

Well, for that one, one thing that could be improved is that loop doesn’t need to be a function of one variable, since you didn’t use the parameter.


joshibharathiramana
2020-12-16 12:50:57

oh do you mean this is better (define (loop) (print (eval (read))) (loop))


sorawee
2020-12-16 12:52:33

yes


jlw
2020-12-16 14:30:19

@jlw has joined the channel


benj.calderon
2020-12-17 00:41:37

@benj.calderon has joined the channel


wanpeebaw
2020-12-17 06:06:43

Maybe an atom means a terminal element in a language?