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

Part 5: Control flow clogged #393

Open
chuchana opened this issue Oct 12, 2024 · 0 comments
Open

Part 5: Control flow clogged #393

chuchana opened this issue Oct 12, 2024 · 0 comments

Comments

@chuchana
Copy link

When clicking, the printing doesn't seem to finish correctly, e.g. for this snippet:

(defun hello-private (body)
  "Create a div on new pages containing - hello world
That when clicked changes color."
  (set-on-click (create-div body :content "hello world")
                (lambda (obj)
                  (setf (color obj) (progn
                                      (terpri)
                                      (princ "Setting color to:")
                                      (print (rgb (random 255)
                                                  (random 255)
                                                  (random 255))))))))

Instead of

Setting color to:
"rgb(...)"

Setting color to:
"rgb(...)"

Setting color to:
"rgb(...)"

I get

Setting color to:

"rgb(...)"
Setting color to:

"rgb(...)"
Setting color to:

(empty lines added for clarity)


Since I could not imagine that I found a bug in progn, I searched the web for a while and found a similar problem and answer.

Adding (finish-output) to the function fixes the problem:

(defun hello-private (body)
  "Create a div on new pages containing - hello world
That when clicked changes color."
  (set-on-click (create-div body :content "hello world")
                (lambda (obj)
                  (setf (color obj) (progn
                                      (terpri)
                                      (princ "Setting color to:")
                                      (print (rgb (random 255)
                                                  (random 255)
                                                  (random 255)))
                                      (finish-output))))))

The same applies to the next variation of hello-private:

(defun hello-private (body)
  "Create a div on new pages containing - hello world
That when clicked changes color."
  (set-on-click (create-div body :content "CLICK ME TO PLAY")
                (lambda (obj)
                  (setf (color obj) (cond ((equal (random 10) 1)
                                           (setf (text obj) "--(O)-(O)--")
                                           (print "RED LIGHT!")
                                           (finish-output)
                                           (rgb 255 0 0))
                                          (t
                                           (setf (text obj) "--(X)-(X)--")
                                           (print "I'm not looking..")
                                           (finish-output)
                                           (rgb 0
                                                (random 255)
                                                (random 255))))))))
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