Skip to content

Instantly share code, notes, and snippets.

@jessealama
jessealama / MeasureAndDecimalAndNormalizedDecimal.mts
Created January 22, 2025 14:24
Type definitions for a three-class approach to Measure & Decimal
// Sketching a three-class world for Measure + Decimal with
//
// 1. IEEE 754 Decimal128 class, with no arithmetic, (mathematical) equality checking only, formatting
// 2. Decimal class (normalized subset of IEEE 754 Decimal128), with arithmetic, comparisons, formatting
// 3. Measure class (minimal in 262, fleshed out in 402), no arithmetic
type RoundingMode =
| "ceil"
| "floor"
| "trunc"
@jessealama
jessealama / MeasureAndDecimal.mts
Created January 22, 2025 14:12
Type definitions for a two-class approach to Measure & Decimal
// Sketching a two-class world for Measure + Decimal with
//
// 1. A Decimal class (normalized subset of IEEE 754 Decimal128), with arithmetic, comparisons, formatting
// 2. A Measure class (minimal in 262, fleshed out in 402), no arithmetic
type RoundingMode =
| "ceil"
| "floor"
| "trunc"
| "halfEven"
@jessealama
jessealama / Decimal128.d.mts
Last active January 13, 2025 15:29
A first stab at combining measure, decimal, and normalized decimal data types
export declare class Decimal128 {
constructor(value: string | number | bigint | NormalizedDecimal128);
// predicates
isFinite(): boolean;
isNegative(): boolean;
isNaN(): boolean;
isZero(): boolean;
// comparison
#lang racket/base
(require racket/list
web-server/http
web-server/servlet-env
web-server/dispatch
json)
#|
Our database will be an (eq) hash table whose keys are symbols.
#lang racket
(require http) ;; not installed by default
;; do raco pkg install http
(define (http-request uri
#:redirects [redirects 10]
#:http-version [http-version "1.1"]
#:method [method "GET"]
#:data [data #""]
#lang racket
(require web-server/servlet
web-server/servlet-env
web-server/templates)
(define html-utf-8-mime-type
"text-html; charset=utf-8")
(define html-utf-8-mime-type/bytes
#lang racket
(define (env)
;; Association list of the current environvment variables and their values.
;;
;; NB: Both the car and the cdr of the returned cons cells are byte strings,
;; not simply strings. If you're looking for strings, you'll need to do
;; a bit of work.
(define (names env)
(environment-variables-names env))
<reddit-user-info status="public" date="YYYY-MM-DD" timezone="UTC" username="USERNAME">
<karma posts="postkarma" comments="commentkarma" total="totalkarma"/>
<subreddit-catalog>
<subreddit name="name" status="status" link="https://www.reddit.com/r/Example/">
<modstatus permissions="none"/>
</subreddit>
</subreddit-catalog>
</reddit-user-info>