How should I define loop
so that this (loop (print (eval (read))))
will actually work as a REPL?
I have this definition that works (define (loop x)
(loop (print (eval (read)))))
but, is there anything more elegant?
If I were to write it to actually use it, I would write it as:
(let loop ()
(print (eval (read)))
(loop))
But it looks like you are interested in the gimmick “REPL”, not good code quality.
In that case, you might be interested in https://twitter.com/leastfixedpoint/status/1326436246525276160
Or:
(define-syntax-rule (loop e) (let go () e (go)))
(loop (print (eval (read))))
@sorawee > But it looks like you are interested in the gimmick “REPL”, not good code quality. (edited) why do you consider it bad code?
The one in Twitter is pretty convoluted.
ah my bad, I thought you were talking about my definition (define (loop x)
(loop (print (eval (read)))))
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.
oh do you mean this is better (define (loop)
(print (eval (read)))
(loop))
yes
@jlw has joined the channel
@benj.calderon has joined the channel
Maybe an atom means a terminal element in a language?