Coder Social home page Coder Social logo

bug in loop-at-most-every about roslisp HOT 5 CLOSED

ros avatar ros commented on July 17, 2024
bug in loop-at-most-every

from roslisp.

Comments (5)

airballking avatar airballking commented on July 17, 2024

@Bradford-Miller Thank you for reporting this. We'll look into this. Could you please help us with this by (a) Providing a minimal code example that shows the faulty behavior, and (b) providing your patch as a pull request? That would be really nice and would help us a lot!

@gaya- Who of us should have a look at this?

from roslisp.

Bradford-Miller avatar Bradford-Miller commented on July 17, 2024

a)
(let ((n 5))
(defun loopy ()
(format t "time: ~S" (get-internal-real-time))
(sleep n)
(if (plusp n) (decf n)))
(defun reset-loopy (x) (setq n x)))

(run-at-most-every 1 (loopy))

note the times after the captured variable reaches 0, there are a number of interations spaced 0 ticks apart, instead of the expected 1 second (which it eventually does after "catching up" to the erroneous time calculated by run-and-increment-delay.

b) I would, but firewall issues seem to be preventing me from doing so. The only difference is the first argument to '+ which should be the current time, not the previously captured time.

from roslisp.

airballking avatar airballking commented on July 17, 2024

@Bradford-Miller Thank you for providing this code snippet that produces the problem! I agree there seems to be a bug.
@gaya- I used @Bradford-Miller's example on Indigo, roslisp version 1.9.20 to confirm it:

ROSLISP> (defvar *n* 0)

ROSLISP> (defun loopy ()
           (format t "time: ~s~%" (get-internal-real-time))
           (sleep *n*)
           (if (plusp *n*) (decf *n*)))

ROSLISP> (loop-at-most-every 1 (loopy))

So, the variable *n* allows us to extend the computation time of the body run within loop-at-most-every. When using the above setting of 0s, we get the correct iteration durations of 1s:

time: 912115
time: 913115
time: 914115
time: 915116
time: 916115

By setting *n* to something higher number,e.g. 3, we get three correction iteration durations of 3s, 2s, 1s, and then three incorrect iteration durations of seemingly 0s. Afterwards, all is fine again:

ROSLISP> (setf *n* 3)
3
ROSLISP> (loop-at-most-every 1 (loopy))
time: 1242747
time: 1245747
time: 1247747
time: 1248747
time: 1248747
time: 1248747
time: 1248747
time: 1249747
time: 1250747

@gaya- Could you please also confirm this bug?

from roslisp.

airballking avatar airballking commented on July 17, 2024

@Bradford-Miller Also, thank you very much for providing your fix in a separate pull request! Unfortunately, it seems like it introduce a new bug. This is what I ran to test it:

ROSLISP> (defvar *n* 0)

ROSLISP> (defun loopy ()
           (format t "time: ~s~%" (get-internal-real-time))
           (sleep *n*)
           (if (plusp *n*) (decf *n*)))

ROSLISP> (loop-at-most-every 1 (loopy))

And it seems that in this setup our function body gets called twice per iteration:

time: 26723
time: 27723
time: 27723
time: 28723
time: 28724
time: 29724
time: 29724
time: 30724
time: 30724
time: 31724
time: 31724

For the case with a longer runtime for the function body, I initially get the desired behavior but also the above bug:

ROSLISP> (setf *n* 3)
3
ROSLISP> (loop-at-most-every 1 (loopy))
time: 216467
time: 219467
time: 221467
time: 222467
time: 223467
time: 223467
time: 224468
time: 224468
time: 225468
time: 225468

@Bradford-Miller Could you please confirm this behavior?

from roslisp.

Bradford-Miller avatar Bradford-Miller commented on July 17, 2024

Confirmed in Kinetic 16.04, roslisp 1.9.20

I've updated the pull request and retested. Sorry about that!

from roslisp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.