Replaces tail-call with loop.

This commit is contained in:
Circling Skies 2024-12-15 22:37:38 -03:00
parent bff30b9443
commit 006fa693d3
2 changed files with 17 additions and 21 deletions

View file

@ -1335,11 +1335,12 @@
:handler #'cli/main-with-handlers)) :handler #'cli/main-with-handlers))
(defun main-loop () (defun main-loop ()
(let* ((bs (nntp-read-line)) (loop
(ln (bytes->string (ucs-2->ascii bs)))) (let* ((bs (nntp-read-line))
(let ((r (send-response! (dispatch-line ln)))) (ln (bytes->string (ucs-2->ascii bs))))
(when (not (response-quit? r)) (let ((r (send-response! (dispatch-line ln))))
(main-loop))))) (when (response-quit? r)
(return))))))
(defun request-quit? (r) (and r (string= 'quit (request-verb r)))) (defun request-quit? (r) (and r (string= 'quit (request-verb r))))
(defun response-quit? (r) (and r (request-quit? (response-request r)))) (defun response-quit? (r) (and r (request-quit? (response-request r))))

27
loop.nw
View file

@ -397,12 +397,7 @@ LOOP> quit
What happens is that [[read]] consumes just the symbol \verb|quit|, so What happens is that [[read]] consumes just the symbol \verb|quit|, so
there remains a \verb|\n| or \verb|\r\n| in the [[*standard-input*]], there remains a \verb|\n| or \verb|\r\n| in the [[*standard-input*]],
which we need to wipe out, or [[nntp-read-line]] will consume an empty which we need to wipe out, or [[nntp-read-line]] will consume an empty
line, which is what causes that 400 response\footnote{Months ago I line, which is what causes that 400 response.
pondered whether I should ignore an empty command or whether I should
write back an empty response such as this one---I beg your pardon? I
decided to not ignore. By not ignoring, [[read]] now called my
attention to the fact that a trailing \verb|\r\n| is left, which seems
good to know.}.
<<Loop's REPL>>= <<Loop's REPL>>=
(defun repl (r) (defun repl (r)
@ -636,11 +631,12 @@ itself---so we can cascade actions based on a user's request.
<<Main loop>>= <<Main loop>>=
(defun main-loop () (defun main-loop ()
(let* ((bs (nntp-read-line)) (loop
(ln (bytes->string (ucs-2->ascii bs)))) (let* ((bs (nntp-read-line))
(let ((r (send-response! (dispatch-line ln)))) (ln (bytes->string (ucs-2->ascii bs))))
(when (not (response-quit? r)) (let ((r (send-response! (dispatch-line ln))))
(main-loop))))) (when (response-quit? r)
(return))))))
(defun request-quit? (r) (and r (string= 'quit (request-verb r)))) (defun request-quit? (r) (and r (string= 'quit (request-verb r))))
(defun response-quit? (r) (and r (request-quit? (response-request r)))) (defun response-quit? (r) (and r (request-quit? (response-request r))))
@ -2030,11 +2026,10 @@ all or it has been discussed with the community beforehand.
\subsection{{\tt REPL}} \subsection{{\tt REPL}}
Mean for hackers, \lp\ is totally {\em hackable}. After \lp\ is totally {\em hackable}. Users can say {\tt repl} to have
authentication, users can say {\tt repl} to have complete control over complete control over their \lxxp\ process. XXX: we should implement
their \lxxp\ process. XXX: we should implement an option an option [[--disable-repl]] so that REPL hacking is turned off.
[[--disable-repl]] so that REPL hacking is turned off. (This would (This would mean your users are not true hackers.)
mean your users are not true hackers.)
<<Command repl>>= <<Command repl>>=
(defun cmd-repl (r) (defun cmd-repl (r)