~abcdw/rde-discuss

1

No indication that a loaded module starts an endless loop

Details
Message ID
<CABKQn8E2eEjCA1N41Bqk0us2UbLVVj0xnYVLxXpJ9z8eeujt6Q@mail.gmail.com>
DKIM signature
missing
Download raw message
I was confused for a while because I didn't realise arei loads and
runs a `(define-library ...)`.  When it does, it goes into an endless
loop, which is the intended behaviour of this program, but I did not
expect that when first loading arei.  An indication that the nrepl
engine is busy would be very useful.

Steps to reproduce:

1. Copy the attached `example.scm` file into a clean directory,
2. and run:

    guix shell guile-next guile-ares-rs -- guile -L . -c '((@ (nrepl
server) run-nrepl-server) #:port 7888)'`

3. Open the downloaded `example.scm` in GNU Emacs.
4. Run `M-x sesman-start`.
5. Move cursor right after `(display "moo")`.
6. Run `M-x arei-evaluate-last-sexp`.
Details
Message ID
<87o7e8f15a.fsf@trop.in>
In-Reply-To
<CABKQn8E2eEjCA1N41Bqk0us2UbLVVj0xnYVLxXpJ9z8eeujt6Q@mail.gmail.com> (view parent)
DKIM signature
missing
Download raw message
On 2023-12-25 13:49, 無無 wrote:

> I was confused for a while because I didn't realise arei loads and
> runs a `(define-library ...)`.  When it does, it goes into an endless
> loop, which is the intended behaviour of this program, but I did not
> expect that when first loading arei.  An indication that the nrepl
> engine is busy would be very useful.
>
> Steps to reproduce:
>
> 1. Copy the attached `example.scm` file into a clean directory,
> 2. and run:
>
>     guix shell guile-next guile-ares-rs -- guile -L . -c '((@ (nrepl
> server) run-nrepl-server) #:port 7888)'`
>
> 3. Open the downloaded `example.scm` in GNU Emacs.
> 4. Run `M-x sesman-start`.
> 5. Move cursor right after `(display "moo")`.
> 6. Run `M-x arei-evaluate-last-sexp`.
> (define-library (example)
>   (import (scheme base)
>           (scheme write))
>
>   (begin
>     (display "moo")
>
>     (define (main)
>       (display (read-line))
>       (newline)
>       (main))
>
>     (main)))

Hey everyone!  Already answered it on IRC, but will repeat for future
readers:

it's better not to do an inifinite recursion in top level forms (the
last call to `(main)` at the end of begin form in this example) and
instead call a particular event loop function explicitly:

guile -c '((@ (example) main))'

Also, it's a good idea to avoid calling functions with side effects in
top level, because they can be evaluated during compilation or
loading/reloading of the module or other arbitrary moment (in this
example such side-effectful function call is `(display "moo")`).

Initialization of modules from load-path can happen even before the
start of ares-rs or independently of it/in parallel to it, so tracking
such events and somehow indicating them can require rework of guile
compilation/evaluation machinery itself and is out of scope of ares-rs.

Thank you for the question and hope you enjoy using Ares RS and Arei :)

-- 
Best regards,
Andrew Tropin
Reply to thread Export thread (mbox)