From 8bbd598025d52fe66613dedec5e1a990a88953b8 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sun, 15 Dec 2024 22:40:15 +0100 Subject: simulation: match on records --- simulation.scm | 52 +++++++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'simulation.scm') diff --git a/simulation.scm b/simulation.scm index c667750..ca30041 100644 --- a/simulation.scm +++ b/simulation.scm @@ -120,33 +120,31 @@ (lambda () (forever (let ((ev (get-message in))) - (match (event-type ev) - ('start - (let ((msg (event-data ev))) - (ll "Device ~a started ~a of message ~a" - (message-device-id msg) - (message-body msg) - (message-id msg)) - (set! started (cons msg started)))) - ('end - (let ((msg (event-data ev))) - (ll "Device ~a finished ~a of message ~a" - (message-device-id msg) - (message-body msg) - (message-id msg)) - (set! started - (remove! (lambda (x) - (and (= (message-id msg) (message-id x)) - (= (message-device-id msg) (message-device-id x)))) started)) - (if (interference? msg started) - (ll "Interference!!!!!!") - (if (message-uplink? msg) - (hash-table-walk gateways - (lambda (k gateway) - (put-message (device-channel gateway) msg))) - (put-message - (device-channel (hash-ref end-devices (message-device-id msg))) - msg)))))))))) + (match ev + (($ 'start msg) + (ll "Device ~a started ~a of message ~a" + (message-device-id msg) + (message-body msg) + (message-id msg)) + (set! started (cons msg started))) + (($ 'end msg) + (ll "Device ~a finished ~a of message ~a" + (message-device-id msg) + (message-body msg) + (message-id msg)) + (set! started + (remove! (lambda (x) + (and (= (message-id msg) (message-id x)) + (= (message-device-id msg) (message-device-id x)))) started)) + (if (interference? msg started) + (ll "Interference!!!!!!") + (if (message-uplink? msg) + (hash-table-walk gateways + (lambda (k gateway) + (put-message (device-channel gateway) msg))) + (put-message + (device-channel (hash-ref end-devices (message-device-id msg))) + msg))))))))) -- cgit v1.2.3