fengshui tweaks

This commit is contained in:
NunoSempere 2024-06-09 15:14:44 +02:00
parent 84a195a29f
commit ae6ad02b56

26
f2.go
View File

@ -11,7 +11,7 @@ import (
) )
const NORMAL90CONFIDENCE = 1.6448536269514727 const NORMAL90CONFIDENCE = 1.6448536269514727
const general_err_msg = "Valid inputs: 2 || * 2 || / 2 || 2 20 || * 2 20 || / 2 20 || i || e" const general_err_msg = "Valid inputs: 2 || * 2 || / 2 || 2 20 || * 2 20 || / 2 20 || clean || =: var || op var || clean || help || debug || exit"
// Actually, I should look up how do do a) enums in go, b) union types // Actually, I should look up how do do a) enums in go, b) union types
type Lognormal struct { type Lognormal struct {
@ -64,7 +64,7 @@ func parseLine(line string, vars map[string]Dist) (string, Dist, error) {
case err1 == nil: case err1 == nil:
dist = Dist{Type: "Lognormal", Lognormal: Lognormal{low: single_float, high: single_float}, Samples: nil} dist = Dist{Type: "Lognormal", Lognormal: Lognormal{low: single_float, high: single_float}, Samples: nil}
case err1 != nil && !var_word_exists: case err1 != nil && !var_word_exists:
return parseLineErr("Trying to operate on a scalar, but scalar is neither a float nor a variable") return parseLineErr("Trying to operate on a scalar, but scalar is neither a float nor an assigned variable")
} }
case 2: case 2:
new_low, err1 := strconv.ParseFloat(words[0], 64) new_low, err1 := strconv.ParseFloat(words[0], 64)
@ -161,12 +161,11 @@ func prettyPrintDist(dist Dist) {
/* Main event loop */ /* Main event loop */
func main() { func main() {
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
old_dist := Dist{Type: "Lognormal", Lognormal: Lognormal{low: 1, high: 1}, Samples: nil} // Could also just be a scalar init_dist := Dist{Type: "Lognormal", Lognormal: Lognormal{low: 1, high: 1}, Samples: nil} // Could also just be a scalar
old_dist := init_dist
vars := make(map[string]Dist) vars := make(map[string]Dist)
// Could eventually be a more complex struct with: // Could eventually be a more complex struct with:
// { Dist, VariableMaps, ConfigParams } or smth // { Dist, VariableMaps, ConfigParams } or smth
// fmt.Printf("Hello world")
EventForLoop: EventForLoop:
for { for {
input, _ := reader.ReadString('\n') input, _ := reader.ReadString('\n')
@ -187,13 +186,26 @@ EventForLoop:
fmt.Printf("Vars: %v\n", vars) fmt.Printf("Vars: %v\n", vars)
continue EventForLoop continue EventForLoop
case words[0] == "=:" && len(words) == 2: case words[0] == "=:" && len(words) == 2:
// fmt.Println("Variables not yet implemented") vars[words[1]] = old_dist
vars[words[1]] = old_dist // is this a copy? fmt.Printf("%s ", words[1])
prettyPrintDist(old_dist)
continue EventForLoop
case words[0] == "." || words[0] == "clean" || words[0] == "c":
old_dist = init_dist
fmt.Println()
continue EventForLoop
case words[0] == "=." && len(words) == 2:
vars[words[1]] = old_dist
fmt.Printf("%s ", words[1])
prettyPrintDist(old_dist)
old_dist = init_dist
fmt.Println()
continue EventForLoop continue EventForLoop
// Other possible cases: // Other possible cases:
// Save to file // Save to file
// Sample n samples // Sample n samples
// Save stack to a variable? // Save stack to a variable?
// clean stack
// Define a function? No, too much of a nerdsnipea // Define a function? No, too much of a nerdsnipea
} }
} }