Re: [racket-users] Cannot attach submodule to namespace
No worries. Thank you for the help as always. On 4/16/21 2:11 PM, Matthew Flatt wrote: > Yes, attaching a module instances doesn't `require` it anywhere. > > (Sorry --- I didn't look at your program closely enough to work out > whether you meant to require it, start out with a non-empty namespace, > or something else.) > > At Fri, 16 Apr 2021 18:02:47 +, Sage Gerard wrote: >> Yes. The error changed to "hello: unbound identifier, also no #%app ..." >> for me, so I also had to add `(namespace-require (quote-module-path >> restricted) ns)` to get it working. >> >> Were you expecting that I had to do that too? The docs for the >> `make-base-*-namespace` procedures make it sound like attaching is >> sufficient. >> >> >> On 4/16/21 1:51 PM, Matthew Flatt wrote: >>> The name `'restricted` is allowed as a shorthand in `require` because >>> `require` knows what module it's in. The `namespace-attach-module` >>> function does not try to infer a module context from the namespace >>> argument; it uses the namespace argument only for its registry. So, you >>> need to use the full name of the submodule. >>> >>> The `quote-module-path` form expands to a full name using its syntactic >>> context (i.e., the enclsoing module's name), so >>> >>> (namespace-attach-module (namespace-anchor->namespace a) >>> (quote-module-path restricted) >>> ns) >>> >>> is probably what you want. >>> >>> >>> At Fri, 16 Apr 2021 17:29:28 +, Sage Gerard wrote: Why does this raise "namespace-attach-module: module not declared (in the source namespace)"? I expected that the `restricted` submodule would be both declared and instantiated by the time control reached `namespace-attach-module`. (module anon racket/base (module restricted racket/base (provide #%app #%datum #%top hello) (define (hello h) h)) (require 'restricted) (define ns (make-empty-namespace)) (define-namespace-anchor a) (namespace-attach-module (namespace-anchor->namespace a) ''restricted ns) (displayln (eval '(hello "world") ns))) -- ~slg >> -- >> ~slg >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Racket Users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email >> to racket-users+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/racket-users/e11dff02-0a27-06bd-9b4c-128f15e65 >> 849%40sagegerard.com. > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/20210416121152.2b0%40sirmail.smtps.cs.utah.edu. -- ~slg -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/8325d0ca-999c-e972-49c8-d6d46994069c%40sagegerard.com.
Re: [racket-users] Cannot attach submodule to namespace
Yes, attaching a module instances doesn't `require` it anywhere. (Sorry --- I didn't look at your program closely enough to work out whether you meant to require it, start out with a non-empty namespace, or something else.) At Fri, 16 Apr 2021 18:02:47 +, Sage Gerard wrote: > Yes. The error changed to "hello: unbound identifier, also no #%app ..." > for me, so I also had to add `(namespace-require (quote-module-path > restricted) ns)` to get it working. > > Were you expecting that I had to do that too? The docs for the > `make-base-*-namespace` procedures make it sound like attaching is > sufficient. > > > On 4/16/21 1:51 PM, Matthew Flatt wrote: > > The name `'restricted` is allowed as a shorthand in `require` because > > `require` knows what module it's in. The `namespace-attach-module` > > function does not try to infer a module context from the namespace > > argument; it uses the namespace argument only for its registry. So, you > > need to use the full name of the submodule. > > > > The `quote-module-path` form expands to a full name using its syntactic > > context (i.e., the enclsoing module's name), so > > > >(namespace-attach-module (namespace-anchor->namespace a) > > (quote-module-path restricted) > > ns) > > > > is probably what you want. > > > > > > At Fri, 16 Apr 2021 17:29:28 +, Sage Gerard wrote: > >> Why does this raise "namespace-attach-module: module not declared (in > >> the source namespace)"? > >> > >> I expected that the `restricted` submodule would be both declared and > >> instantiated by the time control reached `namespace-attach-module`. > >> > >> (module anon racket/base > >> (module restricted racket/base > >> (provide #%app #%datum #%top hello) > >> (define (hello h) h)) > >> (require 'restricted) > >> (define ns (make-empty-namespace)) > >> (define-namespace-anchor a) > >> (namespace-attach-module (namespace-anchor->namespace a) ''restricted > >> ns) > >> (displayln (eval '(hello "world") ns))) > >> > >> -- > >> ~slg > > -- > ~slg > > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email > to racket-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/e11dff02-0a27-06bd-9b4c-128f15e65 > 849%40sagegerard.com. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20210416121152.2b0%40sirmail.smtps.cs.utah.edu.
Re: [racket-users] Cannot attach submodule to namespace
Yes. The error changed to "hello: unbound identifier, also no #%app ..." for me, so I also had to add `(namespace-require (quote-module-path restricted) ns)` to get it working. Were you expecting that I had to do that too? The docs for the `make-base-*-namespace` procedures make it sound like attaching is sufficient. On 4/16/21 1:51 PM, Matthew Flatt wrote: > The name `'restricted` is allowed as a shorthand in `require` because > `require` knows what module it's in. The `namespace-attach-module` > function does not try to infer a module context from the namespace > argument; it uses the namespace argument only for its registry. So, you > need to use the full name of the submodule. > > The `quote-module-path` form expands to a full name using its syntactic > context (i.e., the enclsoing module's name), so > >(namespace-attach-module (namespace-anchor->namespace a) > (quote-module-path restricted) > ns) > > is probably what you want. > > > At Fri, 16 Apr 2021 17:29:28 +, Sage Gerard wrote: >> Why does this raise "namespace-attach-module: module not declared (in >> the source namespace)"? >> >> I expected that the `restricted` submodule would be both declared and >> instantiated by the time control reached `namespace-attach-module`. >> >> (module anon racket/base >> (module restricted racket/base >> (provide #%app #%datum #%top hello) >> (define (hello h) h)) >> (require 'restricted) >> (define ns (make-empty-namespace)) >> (define-namespace-anchor a) >> (namespace-attach-module (namespace-anchor->namespace a) ''restricted ns) >> (displayln (eval '(hello "world") ns))) >> >> -- >> ~slg -- ~slg -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/e11dff02-0a27-06bd-9b4c-128f15e65849%40sagegerard.com.
Re: [racket-users] Cannot attach submodule to namespace
The name `'restricted` is allowed as a shorthand in `require` because `require` knows what module it's in. The `namespace-attach-module` function does not try to infer a module context from the namespace argument; it uses the namespace argument only for its registry. So, you need to use the full name of the submodule. The `quote-module-path` form expands to a full name using its syntactic context (i.e., the enclsoing module's name), so (namespace-attach-module (namespace-anchor->namespace a) (quote-module-path restricted) ns) is probably what you want. At Fri, 16 Apr 2021 17:29:28 +, Sage Gerard wrote: > Why does this raise "namespace-attach-module: module not declared (in > the source namespace)"? > > I expected that the `restricted` submodule would be both declared and > instantiated by the time control reached `namespace-attach-module`. > > (module anon racket/base > (module restricted racket/base > (provide #%app #%datum #%top hello) > (define (hello h) h)) > (require 'restricted) > (define ns (make-empty-namespace)) > (define-namespace-anchor a) > (namespace-attach-module (namespace-anchor->namespace a) ''restricted ns) > (displayln (eval '(hello "world") ns))) > > -- > ~slg -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/20210416115117.107%40sirmail.smtps.cs.utah.edu.
[racket-users] Cannot attach submodule to namespace
Why does this raise "namespace-attach-module: module not declared (in the source namespace)"? I expected that the `restricted` submodule would be both declared and instantiated by the time control reached `namespace-attach-module`. (module anon racket/base (module restricted racket/base (provide #%app #%datum #%top hello) (define (hello h) h)) (require 'restricted) (define ns (make-empty-namespace)) (define-namespace-anchor a) (namespace-attach-module (namespace-anchor->namespace a) ''restricted ns) (displayln (eval '(hello "world") ns))) -- ~slg -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/4a99db87-0ddb-14a7-7240-ec7f03dc9310%40sagegerard.com.
[racket-users] Is it possible to write a macro that acts like namespace-set-variable-value! for implicit forms?
I'd like to use `eval` in terms of a restricted namespace including `#%datum` and `#%app`. For minimalism and security, I want to build that namespace starting from an empty one, without using racket/sandbox, security guards, or attaching racket/base. Under these restrictions, I would normally attach a custom module providing only what I care to expose to the code under evaluation. That's not a problem, but is it possible to avoid creating the extra module and imperatively attach implicit forms? I'm thinking of a macro that behaves like `namespace-set-variable-value!`, but allows implicit forms. -- ~slg -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/f9120eda-8563-dafa-3466-b86c028bae88%40sagegerard.com.
Re: [racket-users] Typed Racket: type relations
I wanted to polish things a bit before starting a longer discussion, but here we go ;-) The code in question[1] is part of my work into exchanging unsafe modules which can be used either contracted or uncontracted for TR modules. The goal is to replace racket/unsafe/ops with TR to provide compile-time type consistency and to have modules which are internally consistent and if they are used with other TR code the consistency remains. More on that later. On 16. 04. 21 15:51, Sam Tobin-Hochstadt wrote: > To improve this, we'd have to extend the type of `fxquotient`, which > is reasonable, but I'm not sure what the addition would be. In > particular, your addition is not sound: > > (fxquotient 1024 2) produces 512 which is not a Byte. Please, take a quick look at the typed-color.rkt in the repository. The "Color" type is just a Nonnegative-Fixnum. It is a generic RGB value with blue in lowest 8 bits, green shifted above blue and red on top. 24 bits in total. The split-rgb splits it into 3 R,G,B values - where each of those values is a byte. Then the rgb-average function takes an arbitrary number of Color values, computes sums of their distinct R,G,B components and divides all of them by the number of values before merging them together into one RGB Color value. Average value of (listof Byte) is definitely a Byte again. I am sorry I didn't send the whole code in question. I was focused on other parts and this is just a side issue in my current work. Is there a way to express this in TR while still generating a code that is on-par with the unsafe version? In theory, TR should excel in this. A similar problem arises with the rgb-distance^2 function where the component difference can be either positive or negative. But definitely a square of whatever Integer is positive. And definitely the result cannot be bigger than 3*255^2=195075, which is definitely Nonnegative-Fixnum on any platform. Again - is there a way to express this in TR and generate a code that has no runtime checks? The motivation here is that the performance and type soundness should go hand in hand. If I prove the code will never get a value of a wrong type, there is no need for runtime checks. Actually the more strict rules, the better code can be (in theory) generated. Then the typed/untyped boundaries introduce contracts - or they don't. I am really confused, why there is a typed/untyped boundary between typed-unsafe-color.rkt and typed-color.rkt. I assume this comes from my poor understanding of TR - it will probably get better in the forthcoming months as TR has proven to be an invaluable tool for improving the quality of performance-oriented modules so far. More on that later too... Cheers, Dominik [1] https://gitlab.com/racketeer/typed-racket-performance -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/d95b9140-fd78-0230-439b-aba654505fd0%40trustica.cz.
Re: [racket-users] Typed Racket: type relations
(Not experienced with typed racket) How about something like this, is there something bad about this? (fxquotient (-> Fixnum Fixnum Fixnum)) (fixnum->byte (-> Fixnum Byte)) ;; possible runtime error (fixnum->byte (fxquotient rs n)) (I don't expect a type to always snap to the narrower one automatically... Or is that something typed racket actually tries to do [which would be cool], but this is something I am more likely to expect from a dependently typed language??) TL;DR does typed racket try to reason about math and or treat values as types? Sam Tobin-Hochstadt schrieb am Freitag, 16. April 2021 um 15:51:46 UTC+2: > To improve this, we'd have to extend the type of `fxquotient`, which > is reasonable, but I'm not sure what the addition would be. In > particular, your addition is not sound: > > (fxquotient 1024 2) produces 512 which is not a Byte. > > Sam > > On Thu, Apr 15, 2021 at 6:22 PM Dominik Pantůček > wrote: > > > > Hello Racketeers, > > > > working on gradually typing some of my modules I encountered an > > interesting problem: > > > > (define-type Color Fixnum) > > > > (: argb-average (-> Color * Color)) > > (define (argb-average . argbs) > > (let loop ((as : Fixnum 0) > > (rs : Fixnum 0) > > (gs : Fixnum 0) > > (bs : Fixnum 0) > > (n : Fixnum 0) > > (argbs : (Listof Color) argbs)) > > (if (null? argbs) > > (make-argb (fxquotient as n) > > (fxquotient rs n) > > (fxquotient gs n) > > (fxquotient bs n)) > > (let-values (((a r g b) (argb-split (car argbs > > (loop (fx+ as a) > > (fx+ rs r) > > (fx+ gs g) > > (fx+ bs b) > > (fx+ n 1) > > (cdr argbs)) > > > > Type Checker: type mismatch > > expected: Byte > > given: Fixnum > > in: (fxquotient bs n) > > > > The only way of fixing this issue was using unsafe-fxquotient which is > > unsafe-require/typed accordingly: > > > > (unsafe-require/typed > > racket/unsafe/ops > > (unsafe-fxquotient (-> Fixnum Fixnum Byte))) > > > > Is there a better way? > > > > The relation between Byte and (Nonnegative-)Fixnum is mathematically > > sound here, but making TR understand it is apparently pretty hard... > > > > > > Cheers, > > Dominik > > > > -- > > You received this message because you are subscribed to the Google > Groups "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to racket-users...@googlegroups.com. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/608fdb93-b2ce-37e0-750c-037b47fed102%40trustica.cz > . > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/17e9a04a-1648-4c88-8e2e-70691ca0fd0dn%40googlegroups.com.
Re: [racket-users] Typed Racket: type relations
To improve this, we'd have to extend the type of `fxquotient`, which is reasonable, but I'm not sure what the addition would be. In particular, your addition is not sound: (fxquotient 1024 2) produces 512 which is not a Byte. Sam On Thu, Apr 15, 2021 at 6:22 PM Dominik Pantůček wrote: > > Hello Racketeers, > > working on gradually typing some of my modules I encountered an > interesting problem: > > (define-type Color Fixnum) > > (: argb-average (-> Color * Color)) > (define (argb-average . argbs) > (let loop ((as : Fixnum 0) >(rs : Fixnum 0) >(gs : Fixnum 0) >(bs : Fixnum 0) >(n : Fixnum 0) >(argbs : (Listof Color) argbs)) > (if (null? argbs) > (make-argb (fxquotient as n) > (fxquotient rs n) > (fxquotient gs n) > (fxquotient bs n)) > (let-values (((a r g b) (argb-split (car argbs > (loop (fx+ as a) > (fx+ rs r) > (fx+ gs g) > (fx+ bs b) > (fx+ n 1) > (cdr argbs)) > > Type Checker: type mismatch > expected: Byte > given: Fixnum > in: (fxquotient bs n) > > The only way of fixing this issue was using unsafe-fxquotient which is > unsafe-require/typed accordingly: > > (unsafe-require/typed > racket/unsafe/ops > (unsafe-fxquotient (-> Fixnum Fixnum Byte))) > > Is there a better way? > > The relation between Byte and (Nonnegative-)Fixnum is mathematically > sound here, but making TR understand it is apparently pretty hard... > > > Cheers, > Dominik > > -- > You received this message because you are subscribed to the Google Groups > "Racket Users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-users/608fdb93-b2ce-37e0-750c-037b47fed102%40trustica.cz. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2BY3JuW%3DN9paE-n5mm51E1qSde1ZCEa5xuxPE7H1_WPXWA%40mail.gmail.com.
Re: [racket-users] Wheel / touchpad / trackpoint accuracy/speed scrolling fix for DrRacket
Yes! Thank you. Dex From: Matthew Flatt Sent: Friday, April 16, 2021 3:26:19 PM To: Dexter Lagan Cc: Racket Users Subject: Re: [racket-users] Wheel / touchpad / trackpoint accuracy/speed scrolling fix for DrRacket Oh, I think I finally get it. The problem is that the leftover amount is returned by `gen-wheels`. With scaling by `wheel-scale`, the returned leftover has been scaled --- but when the leftover is passed back to `gen-wheels` later, it gets scaled again. Applying the scale to `WHEEL_DELTA` instead of `amt` solves the problem, because then the returned leftover amount is on the same scale as the argument amount. Thanks for working through this, and I'll push this change! At Fri, 16 Apr 2021 01:23:16 -0700 (PDT), Dexter Lagan wrote: > Hi Matt, > > This works because when amt is smaller than WHEEL_DELTA, the amt value is > used directly, see first branch of the cond : > > (cond > * [((abs amt) . < . WHEEL_DELTA_S)* >(case wheel-steps-mode > [(one integer) amt] > [(fraction) > (unless (zero? amt) > (do-key w msg down lParam #f #f void (/ amt > (exact->inexact WHEEL_DELTA_S > 0.0])] > > I logged the values with and without the fix. In both cases, I scrolled > slowly down : > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-8 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-40 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-168 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-48 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-200 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-80 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-332 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-92 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-376 > > Amt is often larger than WHEEL_DELTA. After applying the changes > (dividing WHEEL-DELTA and removing the wheel-scale mul) : > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-2 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-4 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-6 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-8 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-11 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-13 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-15 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-17 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-19 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-22 > > > Amt is never above WHEEL_DELTA, which triggers only the first branch of the > cond. The amt value is used with no adjustment, hense the precise behaviour. > > Dex > > On Thursday, April 15, 2021 at 1:49:53 PM UTC+2 Matthew Flatt wrote: > > > Thanks for this summary! But I remain puzzled... > > > > As I understand it, `wheel-scale` ends up being 4 on your machine. So > > removing the multiplication by `wheel-scale` means that `amt` is 1/4 of > > what it used to be. But `amt` is effectively always divided by > > `WHEEL_DELTA`, which you've also divided by 4 in switching to > > `WHEEL_DELTA_S`. > > > > It seems like those factors of 1/4 would cancel out. Do the numbers > > passed to `do-key` end up being different in some way that I'm missing? > > > > Matthew > > > > At Mon, 12 Apr 2021 04:13:16 -0700 (PDT), Dexter Lagan wrote: > > > I started a new thread as the original topic no longer matched. > > > I installed 8.1.0.2 x64 CS and enabled logging in gen-wheels. Matt was > > > right: wheel-steps-mode is indeed set to 'integer while gen-wheels runs > > in > > > DrRacket's editor. The only two changes required to get smooth/accurate > > > scrolling on touchpad gestures and trackpoint are therefore: > > > > > > In share\pkgs\gui-lib\mred\private\wx\win32\window.rkt's gen-wheels > > private > > > method: > > > > > > (let loop ([amt (* wheel-scale amt)]) > > > to > > > (let loop ([amt amt]) > > > > > > and reduce WHEEL_DELTA by a factor of 4, such as gen-wheels looks like: > > > > > > (define/private (gen-wheels w msg lParam amt down up) > > > (define WHEEL_DELTA_S (/ WHEEL_DELTA 4)) > > > (let loop ([amt amt]) > > > (cond > > > [((abs amt) . < . WHEEL_DELTA_S) > > > (case wheel-steps-mode > > > [(one integer) amt] > > > [(fraction) > > > (unless (zero? amt) > > > (do-key w msg down lParam #f #f void (/ amt (exact->inexact > > > WHEEL_DELTA_S > > > 0.0])] > > > [(negative? amt) > > > (case wheel-steps-mode > > > [(one) > > > (do-key w msg down lParam #f #f void 1.0) > > > (loop (+ amt WHEEL_DELTA_S))] > > > [(integer) > > > (define steps (quotient (- amt) WHEEL_DELTA_S)) > > > (do-key w msg down lParam #f #f void (exact->inexact steps)) > > > (loop (+ amt (* steps WHEEL_DELTA_S)))] > > > [else > > > (do-key w msg down lParam #f #f void (/ (- amt) (exact->inexact > > > WHEEL_DELTA_S))) > > > 0.0])] > > > [else > > > (case wheel-steps-mode > > > [(one) > > > (do-key w msg up lParam #f #f void 1.0) > > > (loop (- amt WHEEL_DELTA_S))] > > > [(integer) > > > (define steps (quotient amt WHEEL_DELTA_S)) > > > (do-key w msg up lParam #f #f void (exac
Re: [racket-users] Wheel / touchpad / trackpoint accuracy/speed scrolling fix for DrRacket
Oh, I think I finally get it. The problem is that the leftover amount is returned by `gen-wheels`. With scaling by `wheel-scale`, the returned leftover has been scaled --- but when the leftover is passed back to `gen-wheels` later, it gets scaled again. Applying the scale to `WHEEL_DELTA` instead of `amt` solves the problem, because then the returned leftover amount is on the same scale as the argument amount. Thanks for working through this, and I'll push this change! At Fri, 16 Apr 2021 01:23:16 -0700 (PDT), Dexter Lagan wrote: > Hi Matt, > > This works because when amt is smaller than WHEEL_DELTA, the amt value is > used directly, see first branch of the cond : > > (cond > * [((abs amt) . < . WHEEL_DELTA_S)* >(case wheel-steps-mode > [(one integer) amt] > [(fraction) > (unless (zero? amt) > (do-key w msg down lParam #f #f void (/ amt > (exact->inexact WHEEL_DELTA_S > 0.0])] > > I logged the values with and without the fix. In both cases, I scrolled > slowly down : > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-8 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-40 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-168 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-48 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-200 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-80 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-332 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-92 > > WHEEL_DELTA_S:120 > wheel-scale:4 > amt:-376 > > Amt is often larger than WHEEL_DELTA. After applying the changes > (dividing WHEEL-DELTA and removing the wheel-scale mul) : > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-2 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-4 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-6 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-8 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-11 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-13 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-15 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-17 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-19 > > WHEEL_DELTA_S:30 > wheel-scale:4 > amt:-22 > > > Amt is never above WHEEL_DELTA, which triggers only the first branch of the > cond. The amt value is used with no adjustment, hense the precise behaviour. > > Dex > > On Thursday, April 15, 2021 at 1:49:53 PM UTC+2 Matthew Flatt wrote: > > > Thanks for this summary! But I remain puzzled... > > > > As I understand it, `wheel-scale` ends up being 4 on your machine. So > > removing the multiplication by `wheel-scale` means that `amt` is 1/4 of > > what it used to be. But `amt` is effectively always divided by > > `WHEEL_DELTA`, which you've also divided by 4 in switching to > > `WHEEL_DELTA_S`. > > > > It seems like those factors of 1/4 would cancel out. Do the numbers > > passed to `do-key` end up being different in some way that I'm missing? > > > > Matthew > > > > At Mon, 12 Apr 2021 04:13:16 -0700 (PDT), Dexter Lagan wrote: > > > I started a new thread as the original topic no longer matched. > > > I installed 8.1.0.2 x64 CS and enabled logging in gen-wheels. Matt was > > > right: wheel-steps-mode is indeed set to 'integer while gen-wheels runs > > in > > > DrRacket's editor. The only two changes required to get smooth/accurate > > > scrolling on touchpad gestures and trackpoint are therefore: > > > > > > In share\pkgs\gui-lib\mred\private\wx\win32\window.rkt's gen-wheels > > private > > > method: > > > > > > (let loop ([amt (* wheel-scale amt)]) > > > to > > > (let loop ([amt amt]) > > > > > > and reduce WHEEL_DELTA by a factor of 4, such as gen-wheels looks like: > > > > > > (define/private (gen-wheels w msg lParam amt down up) > > > (define WHEEL_DELTA_S (/ WHEEL_DELTA 4)) > > > (let loop ([amt amt]) > > > (cond > > > [((abs amt) . < . WHEEL_DELTA_S) > > > (case wheel-steps-mode > > > [(one integer) amt] > > > [(fraction) > > > (unless (zero? amt) > > > (do-key w msg down lParam #f #f void (/ amt (exact->inexact > > > WHEEL_DELTA_S > > > 0.0])] > > > [(negative? amt) > > > (case wheel-steps-mode > > > [(one) > > > (do-key w msg down lParam #f #f void 1.0) > > > (loop (+ amt WHEEL_DELTA_S))] > > > [(integer) > > > (define steps (quotient (- amt) WHEEL_DELTA_S)) > > > (do-key w msg down lParam #f #f void (exact->inexact steps)) > > > (loop (+ amt (* steps WHEEL_DELTA_S)))] > > > [else > > > (do-key w msg down lParam #f #f void (/ (- amt) (exact->inexact > > > WHEEL_DELTA_S))) > > > 0.0])] > > > [else > > > (case wheel-steps-mode > > > [(one) > > > (do-key w msg up lParam #f #f void 1.0) > > > (loop (- amt WHEEL_DELTA_S))] > > > [(integer) > > > (define steps (quotient amt WHEEL_DELTA_S)) > > > (do-key w msg up lParam #f #f void (exact->inexact steps)) > > > (loop (- amt (* steps WHEEL_DELTA_S)))] > > > [else > > > (do-key w msg up lParam #f #f void (/ amt (exact->inexact > > > WHEEL_DELTA_S))) > > > 0.0])]))) > > > > > > Happy Monday, >
Re: [racket-users] Wheel / touchpad / trackpoint accuracy/speed scrolling fix for DrRacket
Hi Matt, This works because when amt is smaller than WHEEL_DELTA, the amt value is used directly, see first branch of the cond : (cond * [((abs amt) . < . WHEEL_DELTA_S)* (case wheel-steps-mode [(one integer) amt] [(fraction) (unless (zero? amt) (do-key w msg down lParam #f #f void (/ amt (exact->inexact WHEEL_DELTA_S 0.0])] I logged the values with and without the fix. In both cases, I scrolled slowly down : WHEEL_DELTA_S:120 wheel-scale:4 amt:-8 WHEEL_DELTA_S:120 wheel-scale:4 amt:-40 WHEEL_DELTA_S:120 wheel-scale:4 amt:-168 WHEEL_DELTA_S:120 wheel-scale:4 amt:-48 WHEEL_DELTA_S:120 wheel-scale:4 amt:-200 WHEEL_DELTA_S:120 wheel-scale:4 amt:-80 WHEEL_DELTA_S:120 wheel-scale:4 amt:-332 WHEEL_DELTA_S:120 wheel-scale:4 amt:-92 WHEEL_DELTA_S:120 wheel-scale:4 amt:-376 Amt is often larger than WHEEL_DELTA. After applying the changes (dividing WHEEL-DELTA and removing the wheel-scale mul) : WHEEL_DELTA_S:30 wheel-scale:4 amt:-2 WHEEL_DELTA_S:30 wheel-scale:4 amt:-4 WHEEL_DELTA_S:30 wheel-scale:4 amt:-6 WHEEL_DELTA_S:30 wheel-scale:4 amt:-8 WHEEL_DELTA_S:30 wheel-scale:4 amt:-11 WHEEL_DELTA_S:30 wheel-scale:4 amt:-13 WHEEL_DELTA_S:30 wheel-scale:4 amt:-15 WHEEL_DELTA_S:30 wheel-scale:4 amt:-17 WHEEL_DELTA_S:30 wheel-scale:4 amt:-19 WHEEL_DELTA_S:30 wheel-scale:4 amt:-22 Amt is never above WHEEL_DELTA, which triggers only the first branch of the cond. The amt value is used with no adjustment, hense the precise behaviour. Dex On Thursday, April 15, 2021 at 1:49:53 PM UTC+2 Matthew Flatt wrote: > Thanks for this summary! But I remain puzzled... > > As I understand it, `wheel-scale` ends up being 4 on your machine. So > removing the multiplication by `wheel-scale` means that `amt` is 1/4 of > what it used to be. But `amt` is effectively always divided by > `WHEEL_DELTA`, which you've also divided by 4 in switching to > `WHEEL_DELTA_S`. > > It seems like those factors of 1/4 would cancel out. Do the numbers > passed to `do-key` end up being different in some way that I'm missing? > > Matthew > > At Mon, 12 Apr 2021 04:13:16 -0700 (PDT), Dexter Lagan wrote: > > I started a new thread as the original topic no longer matched. > > I installed 8.1.0.2 x64 CS and enabled logging in gen-wheels. Matt was > > right: wheel-steps-mode is indeed set to 'integer while gen-wheels runs > in > > DrRacket's editor. The only two changes required to get smooth/accurate > > scrolling on touchpad gestures and trackpoint are therefore: > > > > In share\pkgs\gui-lib\mred\private\wx\win32\window.rkt's gen-wheels > private > > method: > > > > (let loop ([amt (* wheel-scale amt)]) > > to > > (let loop ([amt amt]) > > > > and reduce WHEEL_DELTA by a factor of 4, such as gen-wheels looks like: > > > > (define/private (gen-wheels w msg lParam amt down up) > > (define WHEEL_DELTA_S (/ WHEEL_DELTA 4)) > > (let loop ([amt amt]) > > (cond > > [((abs amt) . < . WHEEL_DELTA_S) > > (case wheel-steps-mode > > [(one integer) amt] > > [(fraction) > > (unless (zero? amt) > > (do-key w msg down lParam #f #f void (/ amt (exact->inexact > > WHEEL_DELTA_S > > 0.0])] > > [(negative? amt) > > (case wheel-steps-mode > > [(one) > > (do-key w msg down lParam #f #f void 1.0) > > (loop (+ amt WHEEL_DELTA_S))] > > [(integer) > > (define steps (quotient (- amt) WHEEL_DELTA_S)) > > (do-key w msg down lParam #f #f void (exact->inexact steps)) > > (loop (+ amt (* steps WHEEL_DELTA_S)))] > > [else > > (do-key w msg down lParam #f #f void (/ (- amt) (exact->inexact > > WHEEL_DELTA_S))) > > 0.0])] > > [else > > (case wheel-steps-mode > > [(one) > > (do-key w msg up lParam #f #f void 1.0) > > (loop (- amt WHEEL_DELTA_S))] > > [(integer) > > (define steps (quotient amt WHEEL_DELTA_S)) > > (do-key w msg up lParam #f #f void (exact->inexact steps)) > > (loop (- amt (* steps WHEEL_DELTA_S)))] > > [else > > (do-key w msg up lParam #f #f void (/ amt (exact->inexact > > WHEEL_DELTA_S))) > > 0.0])]))) > > > > Happy Monday, > > > > Dex > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "Racket Users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email > > to racket-users...@googlegroups.com. > > To view this discussion on the web visit > > > https://groups.google.com/d/msgid/racket-users/28e13460-c86d-4967-aa25-5527d672e > > 711n%40googlegroups.com. > -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/c604a711-b12d-4b82-bb17-819f2ab142d0n%40googlegroups.com.