summaryrefslogtreecommitdiff
path: root/internal/repl
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-24 22:38:12 +0200
committerPaul Buetow <paul@buetow.org>2026-03-24 22:38:12 +0200
commite17a6fca9d8b8f6ee24274a4afaaa4dbfef8c90b (patch)
tree0ad8a8a4fe36c6494bc1cf64ce85fa945c0c9271 /internal/repl
parent67d04283196dcbff59d1eb343e4fc949c329a695 (diff)
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.
Diffstat (limited to 'internal/repl')
-rw-r--r--internal/repl/repl.go30
1 files 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()