@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.
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.
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 has joined the channel
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)
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)
thanks, noted
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.
i was hesitating on that, thanks for the hint
Not sure why you have so many lookup variants. Was that for trying out things?
yes
Ok. In general, if you want more meaningful feedback, it’s better to offer cleaned-up code, to lessen the burden of the reader
In your current code, the left and right margins don’t appear. Is that something you want but didn’t know how to do?
yes,
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)
great, thanks. The tab panel is gone?
yes, i removed it for the mean time
ok. What kind of widgets do you want in the middle box and the bottom box?
the middle box will be a canvas, the buttom box will be kind of property editor,
And the margins should be empty, but of fixed size?
fixed size, provided, it will be extensible based on different monitors
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]))
ok, that was quick :slightly_smiling_face: C++ wouldn’t give us this luxury :slightly_smiling_face:
:slightly_smiling_face:
Also check out MrEd Designer if you want a wysiwyg interface: https://github.com/Metaxal/MrEd-Designer
ok, I will surely need a WYSIGWG interface too,
What comes first? a Dialog before the main window? or the other way round? or both, on on top of the other ?
Main window first
The dialog should be a child of the main window (usually a frame%)
is there a way those items can be styled ?
i.e adding a color
unfortunately not. Color is left to be controlled by the window manager (which is OS dependent)
ok
please, can you throw more light on the difference between panel and pane?
Light: Use panel%
:slightly_smiling_face:
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.
ok,
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
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
ok
i’m still struggling to visualize the position of the selected panels,
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
i’m picking up gradually :slightly_smiling_face:
that’s the way to go :slightly_smiling_face:
feel free to ask for help
ok, i will be back, will you be online tomorrow ?
Not sure yet
ok
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.