laurent.orseau
2020-10-16 08:51:28

@anything If you stick to a named let, you can write it this way: (define (cloudflare-email-decode hex-string) (define k (string->number (substring hex-string 0 2) 16)) (let loop ([hx-str (substring hex-string 2)] [decoded '()]) (if (empty-string? hx-str) (apply string (reverse decoded)) (loop (substring hx-str 2) (cons (integer->char (bitwise-xor k (string->number (substring hx-str 0 2) 16))) decoded))))) Note that string is called only once, at the end.


laurent.orseau
2020-10-16 08:54:00

I would probably define this intermediate function though: (define (first-num hex-string) (string->number (substring hex-string 0 2) 16)) because it’s used twice and also makes the code more readable.


laurent.orseau
2020-10-16 08:59:00

But probably the best thing to do is to define a new in-substring form with an argument n, that iteratively consumes the first n characters of the string, to be used in a for/string loop, or in a for/list loop and (apply string …)


kokou.afidegnon
2020-10-16 10:36:50

@kokou.afidegnon has joined the channel


kokou.afidegnon
2020-10-16 11:19:39

hi, i’m trying to build a layout as posted but i’m still trying to improve on my code. can you please give some guidance on how the classes to implement?

here is my sample code #general #lang racket (require racket/gui/base) (define nil '()) (define application-frame (new frame% [label "Example"] [width 400] [height 300])) (define menu-bar (new menu-bar% [parent application-frame])) (define file-menu (new menu% [label "&File"] [parent menu-bar])) (new menu% [label "&Edit"] [parent menu-bar]) (new menu% [label "&Help"] [parent menu-bar]) (new menu-item% [label "E&xit"] [parent file-menu] [callback (λ (m event) (exit nil))]) (define tab-panel (new tab-panel% [parent application-frame] [choices '("&Lookup" "&Training")] [callback (λ (tp event) (case (send tp get-item-label (send tp get-selection)) [("&Lookup") (send tp change-children (get-lookup-panel5 tp))] [("&Training") (send tp change-children (λ (children) (list training-panel)))]))])) (define (get-lookup-panel children) (lambda (children) (let [(lookup-panel (new panel% [parent tab-panel]))] [(new message% [parent lookup-panel] [label "The content of the lookup panel for the lookup tab."]) (list lookup-panel)]))) (define get-lookup-panel2 (lambda (children) (list (new panel% [parent tab-panel])))) (define (get-lookup-panel3 children) (list (new panel% [parent tab-panel]))) (define (get-lookup-panel4 children) (define lookup-panel (new panel% [parent tab-panel])) (define lookup-panel-message (new message% [parent lookup-panel] [label "LOOKUP"])) (list lookup-panel)) (define (get-lookup-panel5 parent-elem) (define lookup-panel (new panel% [parent parent-elem])) (define lookup-panel-message (new message% [parent lookup-panel] [label "LOOKUP"])) (lambda (children) (list lookup-panel))) (define lookup-panel (new panel% [parent tab-panel])) (define lookup-panel-content (new message% [parent lookup-panel] [label "The content of the lookup panel for the lookup tab."])) (define training-panel (new panel% [parent tab-panel])) (define training-panel-content (new message% [parent training-panel] [label "The content of the training panel for the training tab."])) (define status-message (new message% [parent application-frame] [label "No events so far..."] [auto-resize #t])) ;; Derive a new canvas (a drawing window) class to handle events ;(define my-canvas% ; (class canvas% ; The base class is canvas% ; ; Define overriding method to handle mouse events ; (define/override (on-event event) ; (send msg set-label "Canvas mouse")) ; ; Define overriding method to handle keyboard events ; (define/override (on-char event) ; (send msg set-label "Canvas keyboard")) ; ; Call the superclass init, passing on all init args ; (super-new))) ;(new my-canvas% ; [parent frame]) (define panel (new horizontal-panel% [parent application-frame])) (new button% [parent panel] [label "Left"] [callback (lambda (button event) (send msg set-label "Left click"))]) (define msg (new message% [parent panel] [label ""])) ;(new button% [parent panel] ; [label "Right"] ; [callback (lambda (button event) ; (send msg set-label "Right click"))]) (send application-frame show #t)


laurent.orseau
2020-10-16 11:24:11

Not what you asked for, but you can comment a whole parenthesized expression with a single #; special comment: #;(my (nested) expression (+ 3 5) on (several) lines)


kokou.afidegnon
2020-10-16 11:25:00

thanks, noted


laurent.orseau
2020-10-16 11:28:49

Instead of exit, you should merely hide the frame (which is more graceful): [callback (λ (m event) (send application-frame show #f) #;(exit nil))] The application will exit if no other frame is shown.


kokou.afidegnon
2020-10-16 11:31:25

i was hesitating on that, thanks for the hint


laurent.orseau
2020-10-16 11:31:59

Not sure why you have so many lookup variants. Was that for trying out things?


kokou.afidegnon
2020-10-16 11:32:09

yes


laurent.orseau
2020-10-16 11:32:54

Ok. In general, if you want more meaningful feedback, it’s better to offer cleaned-up code, to lessen the burden of the reader


laurent.orseau
2020-10-16 11:34:18

In your current code, the left and right margins don’t appear. Is that something you want but didn’t know how to do?


kokou.afidegnon
2020-10-16 11:34:55

yes,


kokou.afidegnon
2020-10-16 11:36:20

a cleaner code #lang racket (require racket/gui/base) (define nil '()) (define application-frame (new frame% [label "Example"] [width 400] [height 300])) (define menu-bar (new menu-bar% [parent application-frame])) (define file-menu (new menu% [label "&File"] [parent menu-bar])) (new menu% [label "&Edit"] [parent menu-bar]) (new menu% [label "&Help"] [parent menu-bar]) (new menu-item% [label "E&xit"] [parent file-menu] [callback (λ (m event) (exit nil))]) (define status-message (new message% [parent application-frame] [label "No events so far..."] [auto-resize #t])) ;; Derive a new canvas (a drawing window) class to handle events ;(define my-canvas% ; (class canvas% ; The base class is canvas% ; ; Define overriding method to handle mouse events ; (define/override (on-event event) ; (send msg set-label "Canvas mouse")) ; ; Define overriding method to handle keyboard events ; (define/override (on-char event) ; (send msg set-label "Canvas keyboard")) ; ; Call the superclass init, passing on all init args ; (super-new))) ;(new my-canvas% ; [parent frame]) (define panel (new horizontal-panel% [parent application-frame])) (new button% [parent panel] [label "Left"] [callback (lambda (button event) (send msg set-label "Left click"))]) (define msg (new message% [parent panel] [label ""])) ;(new button% [parent panel] ; [label "Right"] ; [callback (lambda (button event) ; (send msg set-label "Right click"))]) (send application-frame show #t)


laurent.orseau
2020-10-16 11:37:06

great, thanks. The tab panel is gone?


kokou.afidegnon
2020-10-16 11:37:22

yes, i removed it for the mean time


laurent.orseau
2020-10-16 11:37:53

ok. What kind of widgets do you want in the middle box and the bottom box?


kokou.afidegnon
2020-10-16 11:38:40

the middle box will be a canvas, the buttom box will be kind of property editor,


laurent.orseau
2020-10-16 11:39:12

And the margins should be empty, but of fixed size?


kokou.afidegnon
2020-10-16 11:39:57

fixed size, provided, it will be extensible based on different monitors


laurent.orseau
2020-10-16 11:44:19

Add this just above (define panel ...): (define margin-width 50) (define canvas-panel (new horizontal-panel% [parent application-frame])) (define margin-left (new panel% [parent canvas-panel] [min-width margin-width] [stretchable-width #f] [stretchable-height #t])) (define cv (new canvas% [parent canvas-panel])) (define margin-right (new panel% [parent canvas-panel] [min-width margin-width] [stretchable-width #f] [stretchable-height #t]))


kokou.afidegnon
2020-10-16 11:45:15

ok, that was quick :slightly_smiling_face: C++ wouldn’t give us this luxury :slightly_smiling_face:


laurent.orseau
2020-10-16 11:45:38

:slightly_smiling_face:


laurent.orseau
2020-10-16 11:46:18

Also check out MrEd Designer if you want a wysiwyg interface: https://github.com/Metaxal/MrEd-Designer


kokou.afidegnon
2020-10-16 11:47:22

ok, I will surely need a WYSIGWG interface too,


kokou.afidegnon
2020-10-16 11:55:39

What comes first? a Dialog before the main window? or the other way round? or both, on on top of the other ?


laurent.orseau
2020-10-16 11:56:47

Main window first


laurent.orseau
2020-10-16 11:56:53

The dialog should be a child of the main window (usually a frame%)


kokou.afidegnon
2020-10-16 12:08:55

is there a way those items can be styled ?


kokou.afidegnon
2020-10-16 12:08:59

i.e adding a color


laurent.orseau
2020-10-16 12:23:55

unfortunately not. Color is left to be controlled by the window manager (which is OS dependent)


kokou.afidegnon
2020-10-16 12:43:51

ok


kokou.afidegnon
2020-10-16 12:47:14

please, can you throw more light on the difference between panel and pane?


laurent.orseau
2020-10-16 12:49:12

Light: Use panel% :slightly_smiling_face:


laurent.orseau
2020-10-16 12:49:30

From the docs: > A <file:///usr/share/racket–7.8.0.9/doc/gui/pane_.html?q=pane%25|pane%> cannot be hidden or disabled like a <file:///usr/share/racket–7.8.0.9/doc/gui/panel_.html?q=pane%25|panel%> object.


kokou.afidegnon
2020-10-16 12:52:01

ok,


kokou.afidegnon
2020-10-16 13:02:25

i’m currently using https://github.com/Metaxal/MrEd-Designer, apart from the listed controls, i needed a custom button which will contain an icon as the label instead of text. i.e a paint icon


laurent.orseau
2020-10-16 13:07:58

In MED, after you have added a button, click on it. This updates the properties panel. There you can see a label field, where you can either type text or select an image


kokou.afidegnon
2020-10-16 13:09:34

ok


kokou.afidegnon
2020-10-16 13:10:04

i’m still struggling to visualize the position of the selected panels,


laurent.orseau
2020-10-16 13:11:11

MED can do a lot of things, you need a little time to get accustomed to it. But it’s fairly simple once you get the idea


kokou.afidegnon
2020-10-16 13:14:22

i’m picking up gradually :slightly_smiling_face:


laurent.orseau
2020-10-16 13:19:12

that’s the way to go :slightly_smiling_face:


laurent.orseau
2020-10-16 13:19:29

feel free to ask for help


kokou.afidegnon
2020-10-16 13:29:17

ok, i will be back, will you be online tomorrow ?


laurent.orseau
2020-10-16 13:29:43

Not sure yet


kokou.afidegnon
2020-10-16 13:30:24

ok


anything
2020-10-16 14:36:11

Thanks, Laurent. I see your concern with string-append. You seem to have effectively replaced it by reverse. That’s probably faster and smarter. Thanks! I think I get your last idea as well. I’m gonna take a look at for/string in 2htdp/abstractions because that procedure it apparently not in racket/base.