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 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
type Lognormal struct {
@ -64,7 +64,7 @@ func parseLine(line string, vars map[string]Dist) (string, Dist, error) {
case err1 == nil:
dist = Dist{Type: "Lognormal", Lognormal: Lognormal{low: single_float, high: single_float}, Samples: nil}
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:
new_low, err1 := strconv.ParseFloat(words[0], 64)
@ -161,12 +161,11 @@ func prettyPrintDist(dist Dist) {
/* Main event loop */
func main() {
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)
// Could eventually be a more complex struct with:
// { Dist, VariableMaps, ConfigParams } or smth
// fmt.Printf("Hello world")
EventForLoop:
for {
input, _ := reader.ReadString('\n')
@ -187,13 +186,26 @@ EventForLoop:
fmt.Printf("Vars: %v\n", vars)
continue EventForLoop
case words[0] == "=:" && len(words) == 2:
// fmt.Println("Variables not yet implemented")
vars[words[1]] = old_dist // is this a copy?
vars[words[1]] = old_dist
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
// Other possible cases:
// Save to file
// Sample n samples
// Save stack to a variable?
// clean stack
// Define a function? No, too much of a nerdsnipea
}
}