Open Agent-E11 opened 11 months ago
There is a small implementation problem. How will I store user defined functions? The context
HashMap is already kind of cumbersome to have to pass in to all the functions, so I don't want to create another func_context
or something.
Possible solutions:
// Pseudo code
context: HashMap = [
("F", "x^2 + x + 1"),
("G", "\sin(x)"),
];
This would probably rule out multi-variable functions, would force all functions to be uppercase (or another distinguishing feature), and would require the free variable to be x
(or another specific letter/identifier)
// Pseudo code
enum VarEntry = {
Var(String), // Name
UsrFn(String, Vec<String>), // Name, variables
}
use VarEntry::*;
context: HashMap = [
(UsrFn("F", ["x", "y"]), "\sqrt(x^2 + y^2)"),
];
I don't think there are any drawbacks. But, I will need to make a way to index them (Using name probably)
(I just realized this might be a bad idea)
String
as key, enum as valuecontext: HashMap = [
("A", UsrFn(["x", "y"], "\sqrt(x^2 + y^2)")), // ("name", Type([vari, ables], "expression"))
]
Possibly denoted by uppercase characters