From 1d90d466a8f6f23c4cedcfc97438fc10bbd80d3e Mon Sep 17 00:00:00 2001 From: demo Date: Sat, 30 May 2026 22:51:24 -0400 Subject: feat: use Present/Absent instead of New --- hamlet.go | 22 ++++++++++++---------- hamlet_test.go | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hamlet.go b/hamlet.go index 3315433..8cdc578 100644 --- a/hamlet.go +++ b/hamlet.go @@ -3,38 +3,40 @@ package hamlet import "reflect" type Assertion struct { - value bool + truth bool } func (a Assertion) Assert() bool { - return a.value + return a.truth } -// New returns a new Assertion. An assertion is true iff its -// underlying value is non-zero in the Go sense. -func New(v any) Assertion { +func Present(v any) Assertion { return Assertion{!reflect.ValueOf(v).IsZero()} } +func Absent(v any) Assertion { + return Assertion{reflect.ValueOf(v).IsZero()} +} + // Not computes ~a, given assertion a. func Not(a Assertion) Assertion { - negation := !a.value + negation := !a.truth return Assertion{negation} } // Or computes a v b, given assertions a and b. func Or(a Assertion, b Assertion) Assertion { - av := a.value - bv := b.value + av := a.truth + bv := b.truth return Assertion{av || bv} } // And computes a ^ b, given assertions a and b. func And(a Assertion, b Assertion) Assertion { - av := a.value - bv := b.value + av := a.truth + bv := b.truth return Assertion{av && bv} } diff --git a/hamlet_test.go b/hamlet_test.go index ca69425..bbd50fe 100644 --- a/hamlet_test.go +++ b/hamlet_test.go @@ -5,8 +5,8 @@ import ( ) func TestAssertion(t *testing.T) { - p := New("") - q := New(4) + p := Present("") + q := Present(4) theorem1 := If(p, q) if !theorem1.Assert() { -- cgit v1.2.3