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

documentation mistake #2158

Open
Syntacticlosure opened this issue Jul 3, 2018 · 5 comments
Open

documentation mistake #2158

Syntacticlosure opened this issue Jul 3, 2018 · 5 comments

Comments

@Syntacticlosure
Copy link

In the doc of function get-default-percentages in gui-lib:


method(send a-panel:dragable get-default-percentages subwindow-count)
--
→ (listof (and/c real? (between/c 0 1)))
subwindow-count : exact-positive-integer?

Should the contract of function result be (listof (and/c real? exact? (between/c 0 1))) , not (listof (and/c real? (between/c 0 1))) ?

@bennn
Copy link
Contributor

bennn commented Jul 4, 2018

It looks ok to me. I can see it might be a bad idea to have inexact percentages, but it doesn't seem so bad that it should be prohibited.

@Syntacticlosure
Copy link
Author

@bennn The problem is , if u override this function with augment and return an inexact real number between 0 and 1 , u will get an error.

@bennn
Copy link
Contributor

bennn commented Jul 6, 2018

I don't understand. Can you post the code you have?

In the implementation, get-default-percentages checks that the percentages add to 1. That might error if some percentages are inexact, but it might not:

Welcome to Racket v7.0.0.2.
> (= 1 (apply + '(1/5 0.2 0.6)))
#t
> (= 1 (apply + (list 1/3 (exact->inexact 2/3))))
#t

@Syntacticlosure
Copy link
Author

My code is here:

(require racket/gui framework)
(define f (new frame% [label "test"][width 400][height 200]))

(define p (new (class
                   panel:horizontal-dragable%
                 (super-new)
                 (define/augment (get-default-percentages i)
                   (match i
                     [2 (list #e0.5 #e0.5)]
                     [_ (build-list i (λ (_) (/ 1 i)))])))
               [parent f]))

(define m1 (new message% [label "left"][parent p]))
(define m2 (new message% [label "right"][parent p]))
(send f show #t)

It runs perfectly but if you replace #e0.5 with 0.5 ,you will get this:

container-redraw: result from place-children is not a list of length 2 (matching the input list length) whose elements are lists of length 4 of exact integers
result: '((0 0 190.0 162) (195.0 0 190.0 162))

@LeifAndersen
Copy link
Member

Given that they must add up to exactly 1, it makes sense to me that they should be limited to exact-real? numbers.

But it does seem like there is also a bug in the implementation (or contract) this function uses as well.

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

3 participants