From 0b9e8f6ab4eef2a43703ed68766303be9542e0fe Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 13 Nov 2013 00:09:39 -0800 Subject: [PATCH] trying --- library/css/math.rkt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 library/css/math.rkt diff --git a/library/css/math.rkt b/library/css/math.rkt new file mode 100644 index 0000000..52df91d --- /dev/null +++ b/library/css/math.rkt @@ -0,0 +1,21 @@ +#lang racket/base +(require "core.rkt") + +(struct cssq (num unit) + #:methods gen:custom-write + [(define write-proc + (λ(x port mode) (display (format "~a~a" (cssq-num x) (cssq-unit x)) port)))]) + +(define (string->cssq str) + (apply cssq + (let ([str (string-trim str "s" #:left? #f)]) + (regexp-split #px"(?<=[.\\d])(?=[A-Za-z])" str)))) + + +(define (css+ left right) + (string->cssq (format "~a~a" (apply + (map string->number (list (cssq-num left) (cssq-num right))))(cssq-unit left)))) + +(module+ main + (define q1 (string->cssq "51.2rems")) + (define q2 (string->cssq "10rem")) + (css+ q1 q2)) \ No newline at end of file