Closed dsbw closed 3 years ago
Now included on README.md:
(def hypot
(from-string [x y]
"sqrt(x**2 + y**2)"))
; => #'user/hypot
(hypot 3 4)
; => 5
(meta hypot)
; => {:params [:x :y], :doc "sqrt(x**2 + y**2)"}
[This will be built into the next published release]
Okay, that's cool! But what if it's...
(def area
(from-string [r]
"pi * (r**2)"))
And you want to know that it uses "pi"?
At the point of invoking the function, the only thing that can affect the output is the value of r
. As long as pi
Is bound in the environment it will compile. If you had pie
instead for example, it would throw an error along the lines of pie is not bound in environment
.
I guess we have the grammar, so rather than just evaluating the expression it could additionally return the AST in the metadata.
Just to clarify, I want the users to be able to enter something like "=(pi * r**2)
" and when they go to evaluate, to be able to say, "Hey, you asked for r but didn't supply r." If I make them supply the parameters, like "=[r](pi * r**2)
" it's a thing that can go wrong. For two variables, like "bmi=[wt ht](wt/ht**2)*703
", I have the additional possibility of passing in the parameters in the wrong order, like "bmi(ht, wt)
".
I'm trying to give my users a way to script formulae, a la Excel. Let's say one puts in the formula for Body Mass Index (BMI) which is:
Is there a way I can find that the symbols wt and ht are needed? Basically, I'm going to be coming in with a map of values and I want to be able to say "Hey, bub, your map has wt but not ht.
(I edited this to remove an extraneous issue).