From e17a6fca9d8b8f6ee24274a4afaaa4dbfef8c90b Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Tue, 24 Mar 2026 22:38:12 +0200 Subject: refactor: Move RPNState and related declarations to top of repl.go - Move RPNState type definition before any functions - Move rpnState and rpnStateOnce variable declarations before any functions - Keep REPL struct and NewREPL constructor at the top (as per Go best practices) - Update getRPNState comment to be more descriptive This change follows Go best practices where constants, global variables, and type definitions should be at the top of the file before functions. --- internal/repl/repl.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/repl/repl.go b/internal/repl/repl.go index da264e1..d8b65c3 100644 --- a/internal/repl/repl.go +++ b/internal/repl/repl.go @@ -10,6 +10,19 @@ import ( "github.com/c-bata/go-prompt" ) +// RPNState holds the state for RPN operations in REPL. +// Note: This struct should never be copied - use pointer receivers only. +type RPNState struct { + vars rpn.VariableStore + rpnCalc *rpn.RPN +} + +// rpnState holds the singleton RPN state for REPL operations. +var rpnState *RPNState + +// rpnStateOnce ensures rpnState is initialized exactly once. +var rpnStateOnce sync.Once + // REPL manages the interactive command-line interface. type REPL struct { ttyChecker *TTYChecker @@ -168,21 +181,8 @@ func executor(input string) { defaultExecutor(r, input) } -// RPNState holds the state for RPN operations in REPL -// Note: This struct should never be copied - use pointer receivers only -type RPNState struct { - vars rpn.VariableStore - rpnCalc *rpn.RPN -} - -// rpnState holds the singleton RPN state for REPL operations -var rpnState *RPNState - -// rpnStateOnce ensures rpnState is initialized exactly once -var rpnStateOnce sync.Once - -// getRPNState returns or creates the RPN state -// Thread-safe implementation using sync.Once for simpler singleton initialization +// getRPNState returns or creates the RPN state. +// Thread-safe implementation using sync.Once for simpler singleton initialization. func getRPNState() *RPNState { rpnStateOnce.Do(func() { vars := rpn.NewVariables() -- cgit v1.2.3