From d3d17484012dc603ae326bec419cff990898e6a0 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Apr 2023 13:48:15 +0100 Subject: Adds the reciprocal operator --- subex/subexast.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'subex/subexast.go') diff --git a/subex/subexast.go b/subex/subexast.go index 3c807ee..78c9aff 100644 --- a/subex/subexast.go +++ b/subex/subexast.go @@ -223,3 +223,18 @@ func (ast SubexASTNegate) compileWith(next SubexState) SubexState { }), } } + +// Runs the content Subex and collects the output +// If it is a list of atoms castable to numbers, it takes the reciprocal of them all and outputs them +// Else it rejects +type SubexASTReciprocal struct { + content SubexAST +} +func (ast SubexASTReciprocal) compileWith(next SubexState) SubexState { + return &SubexCaptureBeginState { + next: ast.content.compileWith(&SubexArithmeticEndState { + next: next, + calculate: reciprocalValues, + }), + } +} -- cgit v1.2.3