blerner
2021-4-10 13:51:09

Pict question: when using pict/tree-layout , is it possible to specify that the edges should be drawn with arrowheads (either incoming or outgoing, or both)? if not…is there some other tree-layout helper that might?


blerner
2021-4-10 13:54:13

Looking in the source, I see some mentions of arrow-looking names in the private/ directory, but I don’t see them carried up through to the public API…


soegaard2
2021-4-10 14:01:28

Hi All,

I am attempting to use gui-widget-mixins to add a tooltip to one of the options in a preferences menu. It sort of works - the tooltip appears after 500ms, but it seems it doesn’t disappear in the way I expected. See below for a screen recording.

Here is how I used the mixin: ;; add-check : panel symbol string (boolean -> any) (any -> boolean) -> void ;; adds a check box preference to `main'. (define (add-check main pref title #:tooltip [tooltip #f] [bool->pref values] [pref->bool values]) (let* ([callback (λ (check-box _) (preferences:set pref (bool->pref (send check-box get-value))))] [pref-value (preferences:get pref)] [initial-value (pref->bool pref-value)] [c (cond [tooltip (new (tooltip-mixin check-box%) [label title] [parent main] [callback callback] [tooltip tooltip] [tooltip-delay 500])] [else (new check-box% [label title] [parent main] [callback callback])])]) (send c set-value initial-value) (preferences:add-callback pref (λ (p v) (send c set-value (pref->bool v)))) (void))) Any ideas?

@alexharsanyi


sschwarzer
2021-4-10 14:30:55

Can I wrap begin-encourage-inline (see https://docs.racket-lang.org/reference/performance-hint.html ) around several functions at once or do I need to wrap each function individually?


sschwarzer
2021-4-10 14:44:01

Another question:

I have the following function: (define (next-index-for-empty-cell board) (let find-empty-cell ([index 0]) (cond [(= index BOARD-SIZE) #f] [else (define item (board-ref board index)) (cond [(eq? item EMPTY-CELL) index] [else (find-empty-cell (add1 index))])]))) At the moment, it seems I need a nested cond because of the (define item ...) in the outer cond’s else branch. In this particular case, item is only needed once, so it would be easy to substitute it in (eq? item ...). However, I’ve come across similar code before and I wonder if there’s a way to avoid nesting conds only because I need a define for some of the branches. (By the way, I can’t put the define before the outer cond because then board-ref tries to access an index outside the vector that makes up board’s data.)


ryanc
2021-4-10 14:55:43

Yes, you can wrap it around multiple definitions.


ben.knoble
2021-4-10 15:49:15

In this particular case, you could follow the Java-like idiom from string != null && … to write (let find-empty-cell ([index 0]) (and (not (= index BOARD-SIZE)) (let ([item (board-ref board index)]) (cond …)))) (I might use >= if I was being defensive, gives a stronger condition on the else-branch. There might also be a way to express this with something like the for forms or other “functional” constructs, given that you know the sequence of indexes to check ahead of time. Whether they’re as efficient is another story—if the board-size is small, say, 8x8, manifesting the list of indices for a filter + first might not be too much overhead. Otherwise, you might want streaming operations to get the sort of lazy index generation you get with the let-loop version.)


sorawee
2021-4-10 15:49:51

Yep, people have been complaining about this and people have been creating various macros to solve the problem


ben.knoble
2021-4-10 15:51:24

I suppose another option would be to have board-ref-err or whatever a good name is that returns #f when the index is out-of-bounds, like an optional return value. Easy enough to write yourself if stdlib doesn’t have it.


sorawee
2021-4-10 15:56:01

Here’s an example of the said macro:

#lang racket (require syntax/parse/define) (define-syntax-parser cond* [(_ [#:let x v] xs ...) #'(let ([x v]) (cond* xs ...))] [(_ [#:else x ...]) #'(let () x ...)] [(_ [c x ...] xs ...) #'(if c (let () x ...) (cond* xs ...))]) (define (next-index-for-empty-cell board) (let find-empty-cell ([index 0]) (cond* [(= index BOARD-SIZE) #f] [#:let item (board-ref board index)] [(eq? item EMPTY-CELL) index] [#:else (find-empty-cell (add1 index))])))


samth
2021-4-10 15:59:53

@notjack can you take a look at the open rackunit PRs and tell what state they’re in?


sorawee
2021-4-10 16:01:15

If there’s a PR to fix this, great!

The problem with my above approach is that it will definitely break rackunit, and I don’t think it’s easy to fix this while maintaining backward compatibility.


joel
2021-4-10 16:59:09

What is the objection to nesting conds?


sorawee
2021-4-10 17:00:29

Nesting creates rightward drift, making code more difficult to read.


joel
2021-4-10 17:06:01

What about making board-ref return false if the index is out of bounds and using match on the result of that call


sschwarzer
2021-4-10 17:32:13

Many thanks for your ideas. I need to process them when I’m more focused. :slightly_smiling_face:


sschwarzer
2021-4-10 17:36:01

> What is the objection to nesting conds? I find a flat sequence of cases easier to read/scan than nested sequences, in some cases much easier.


notjack
2021-4-10 20:26:35

@samth yes, but I’m not likely to get to it until after the weekend


samth
2021-4-10 20:27:56

Ok awesome


rajan.yadav
2021-4-11 05:00:53

@ryanc I did not know about PLTSTDERR (something new learnt :slightly_smiling_face:). I tried your suggestion, mypkg is the product of raco distribute and I shoved desired shared libs (libblas, libgfortran …) into lib subdirectory using ++collects-copy and --collects-path options $ PLTSTDERR="debug@ffi-lib" ./mypkg/bin/myexe ffi-lib: loaded "libgmp.so.10" ffi-lib: loaded "libmpfr.so.6" ffi-lib: failed for (ffi-lib "libblas" '("3" #f)), tried:  #<path:/me/mypkg/lib/libblas.so.3> (exists)  #<path:/me/mypkg/lib/libblas.so> (exists)  #<path:/me/mypkg/lib/libblas> (no such file)  "libblas.so.3" (using OS library search path)  "libblas.so" (using OS library search path)  "libblas" (using OS library search path)  #<path:/me/libblas.so.3> (no such file)   #<path:/me/libblas.so> (no such file)   #<path:/me/libblas> (no such file)  ffi-lib: couldn't open "libblas.so.3" (libblas.so.3: cannot open shared object file: No such file or directory)  context...:   /usr/share/racket/collects/ffi/unsafe.rkt:131:0: get-ffi-lib   '#%embedded:flomat/flomat:: [running body]   temp35_0   for-loop   run-module-instance!   for-loop   [repeats 1 more time]   run-module-instance!   for-loop   [repeats 1 more time]   run-module-instance!   for-loop   [repeats 1 more time]   run-module-instance!   for-loop   [repeats 1 more time]   ...


rajan.yadav
2021-4-11 05:01:41

So it seems to be finding the library but can’t use it for some reason ?


rajan.yadav
2021-4-11 05:09:32

After setting LD_LIBRARY_PATH: $ PLTSTDERR="debug@ffi-lib" ./mypkg/bin/myexe ffi-lib: loaded "libgmp.so.10" ffi-lib: loaded "libmpfr.so.6" ffi-lib: loaded #<path:/me/mypkg/lib/libblas.so.3> ffi-lib: loaded #<path:/me/mypkg/lib/libgfortran.so.3> ffi-lib: loaded "libquadmath.so.0" ffi-lib: loaded #<path:/me/mypkg/lib/liblapack.so.3> (flomat:  ((1.0 0.0 0.0 0.0 0.0)  (0.0 1.0 0.0 0.0 0.0)  (0.0 0.0 1.0 0.0 0.0)  (0.0 0.0 0.0 1.0 0.0)  (0.0 0.0 0.0 0.0 1.0)))