Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for infinite looping by writing code that times out #348

Open
masak opened this issue Jun 25, 2021 · 3 comments
Open

Add tests for infinite looping by writing code that times out #348

masak opened this issue Jun 25, 2021 · 3 comments

Comments

@masak
Copy link
Owner

masak commented Jun 25, 2021

First I was going to suggest modifying the interpreter to have a "fuel" counter (in the style of some contemporary "smart contract" evaluators), but then I realized that this can probably be expressed in pure Bel, using threads and a modicum of cleverness. Stay tuned.

A lot of functions are susceptible to infinite looping when fed cyclic lists. We should give each of them a test.

@masak
Copy link
Owner Author

masak commented Jun 25, 2021

[...] but then I realized that this can probably be expressed in pure Bel, using threads and a modicum of cleverness. Stay tuned.

Here's the general principle, nicely formatted for readability:

> (do
    (set aborted nil)
    (thread
      (let n 0
        (while (< (++ n) 5))
        (set aborted t)
        (pr 'aborted \lf)))
    ; meanwhile, in the main thread...
    (let n 0
      (while (and (no aborted)
                  (< (++ n) 1000))
        (prn n))))
1
2
3
4
aborted
5
nil

@masak
Copy link
Owner Author

masak commented Jun 25, 2021

> (do
    (set aborted nil)
    (thread
      (do
        (repeat 20)
        (set aborted t)))
    ; meanwhile, in the main thread
    (catch
      (let n 0
        (while (< (++ n) 1000)
          (if aborted (throw 'aborted))
          (prn n)))))
1
2
3
4
5
6
aborted

@masak
Copy link
Owner Author

masak commented Nov 9, 2021

I just got a better idea — which I added to the (private) bel-masak-prelude repo as bind-fn/call-limit and bind-fn/timeout.

It would be sweet to be able to use those functions in the tests. I guess in the short term it will be easier to declare them in the test file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant