In the list of esoteric languages, racket scheme has his place.
cat explicit.rkt
to build & run:
cat explicit.rkt
Code:
#lang typed/racket/gui
(require typed/racket/class) ; Adds 'new', 'send', 'get-field', etc.
;; Define the main dialog window
(define dialog : (Instance Dialog%)
(new dialog% [label "Temperature Converter"]))
;; Input field for the numeric value
(define textField : (Instance Text-Field%)
(new text-field% [parent dialog] [label "Enter value: "]))
;; Label to display the result
(define output : (Instance Message%)
(new message% [parent dialog] [label "Result will appear here"] [auto-resize #t]))
;; Container for the controls
(define panel : (Instance Horizontal-Panel%)
(new horizontal-panel% [parent dialog] [alignment '(center center)]))
;; Checkbox to determine direction (True = Fahrenheit)
(define check : (Instance Check-Box%)
(new check-box% [parent panel] [label "to Fahrenheit"]))
;; Calculate button with explicit callback types
(define calc-button : (Instance Button%)
(new button% [parent panel]
[label "Calculate"]
[callback (lambda ([button : (Instance Button%)] [event : (Instance Control-Event%)])
(let* ([val-str : String (send textField get-value)]
[num : (Option Number) (string->number val-str)]
[to-f? : Boolean (send check get-value)])
(cond
[(not num)
(send output set-label "Invalid Input")]
[to-f?
;; Celsius to Fahrenheit: (C * 9/5) + 32
(let ([f : Number (+ (* num (/ 9 5.0)) 32)])
(send output set-label (number->string (real-part f))))]
[else
;; Fahrenheit to Celsius: (F - 32) * 5/9
(let ([c : Number (* (- num 32) (/ 5 9.0))])
(send output set-label (number->string (real-part c))))])))]))
;; Display the GUI
(send dialog show #t)
to build & run:
Code:
#!/bin/sh
set -e
rm ./explicit
rm -vfR ./build
echo "make"
raco make -j 6 explicit.rkt
echo "exe"
raco exe explicit.rkt
echo "distribute"
raco distribute ./build ./explicit
echo "done"
./build/bin/explicit