From 006fa693d3184c44fba1e66c47ce57449c5a041d Mon Sep 17 00:00:00 2001 From: Circling Skies Date: Sun, 15 Dec 2024 22:37:38 -0300 Subject: [PATCH] Replaces tail-call with loop. --- loop.lisp | 11 ++++++----- loop.nw | 27 +++++++++++---------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/loop.lisp b/loop.lisp index 582ff75..1badb6c 100644 --- a/loop.lisp +++ b/loop.lisp @@ -1335,11 +1335,12 @@ :handler #'cli/main-with-handlers)) (defun main-loop () - (let* ((bs (nntp-read-line)) - (ln (bytes->string (ucs-2->ascii bs)))) - (let ((r (send-response! (dispatch-line ln)))) - (when (not (response-quit? r)) - (main-loop))))) + (loop + (let* ((bs (nntp-read-line)) + (ln (bytes->string (ucs-2->ascii bs)))) + (let ((r (send-response! (dispatch-line ln)))) + (when (response-quit? r) + (return)))))) (defun request-quit? (r) (and r (string= 'quit (request-verb r)))) (defun response-quit? (r) (and r (request-quit? (response-request r)))) diff --git a/loop.nw b/loop.nw index 5cbe239..3c7fda2 100644 --- a/loop.nw +++ b/loop.nw @@ -397,12 +397,7 @@ LOOP> quit 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*]], 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 -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.}. +line, which is what causes that 400 response. <>= (defun repl (r) @@ -636,11 +631,12 @@ itself---so we can cascade actions based on a user's request. <
>= (defun main-loop () - (let* ((bs (nntp-read-line)) - (ln (bytes->string (ucs-2->ascii bs)))) - (let ((r (send-response! (dispatch-line ln)))) - (when (not (response-quit? r)) - (main-loop))))) + (loop + (let* ((bs (nntp-read-line)) + (ln (bytes->string (ucs-2->ascii bs)))) + (let ((r (send-response! (dispatch-line ln)))) + (when (response-quit? r) + (return)))))) (defun request-quit? (r) (and r (string= 'quit (request-verb 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}} -Mean for hackers, \lp\ is totally {\em hackable}. After -authentication, users can say {\tt repl} to have complete control over -their \lxxp\ process. XXX: we should implement an option -[[--disable-repl]] so that REPL hacking is turned off. (This would -mean your users are not true hackers.) +\lp\ is totally {\em hackable}. Users can say {\tt repl} to have +complete control over their \lxxp\ process. XXX: we should implement +an option [[--disable-repl]] so that REPL hacking is turned off. +(This would mean your users are not true hackers.) <>= (defun cmd-repl (r)