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

call/cc give error #5

Closed
jcubic opened this issue Jan 3, 2022 · 3 comments
Closed

call/cc give error #5

jcubic opened this issue Jan 3, 2022 · 3 comments

Comments

@jcubic
Copy link

jcubic commented Jan 3, 2022

This is an example that helped me find an error in BiwaScheme and its call/cc implementation biwascheme/biwascheme#257. Here is the code. You can use it to test your implementation:

(call/cc (lambda (return)
           (let ((n 5)
                 (result (list))
                 (k #f))
             (set! result (append result (list (call/cc (lambda (return)
                                                          (set! k return)
                                                          "Hello")))))
             (when #t
               (if (zero? n)
                   (return result))
               (set! n (- n 1))
               (k (string-append "Hello <" (number->string n) ">"))))))

It should return:

("Hello <0>")

All elements are implemented but git weird:

<error args 4>

@PollRobots
Copy link
Owner

Thanks for reporting this!

There's (apparantly) a bug in number->string, if I change your code to

(call/cc (lambda (return)
           (let ((n 5)
                 (result (list))
                 (k #f))
             (set! result (append result (list (call/cc (lambda (return)
                                                          (set! k return)
                                                          "Hello")))))
             (when #t
               (if (zero? n)
                   (return result))
               (set! n (- n 1))
               (k (string-append "Hello <" (number->string n 10) ">"))))))

Then it works as expected

@jcubic
Copy link
Author

jcubic commented Jan 3, 2022

Nice, awesome project. You should also try to test quasiquote and syntax-rules, check the links, it took a while to create those tests.

@jcubic
Copy link
Author

jcubic commented Jan 3, 2022

If you want to run the code from unit tests without Ava and by helper code, you will need to write mocks for Ava testing framework, I think that you only need those:

  • to.throw macro
  • test function that executes the second argument, and can print the message before execution.
  • t.is macro the check for equality and print the expression when not equal. With ava in my Scheme, it's a JavaScript method on t object.

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

2 participants