Replies: 3 comments
-
Thanks for bringing this up. Right now the expression parser doesn't know about units, for the parser everything is just a symbol that will be resolved at evaluation time by first looking in the Your suggestion of distinguishing between variables and units isn't something obvious to implement. I don't think it's possible to sometimes interpret a symbol One option would be to give an error or when overriding a unit or built-in constant or function (like Related: #792 |
Beta Was this translation helpful? Give feedback.
-
Yes, it would. What about some other syntax to force evaluation as unit first? A key word? Wrapped in parentheses?
Not sure how I feel loosing some of the conventional symbols of physics. In one way, Just struck me that (after writing the above), I could force units by using it's full name: $ node bin/repl.js
> scope = {}
{}
> math.eval("m = 10 kg", scope).toString()
'10 kg'
> math.eval("v = 10 meter / s", scope).toString()
'10 meter / s' // <-- as expected In light of the last example, a warning would probably suffice. Is this something you would want implemented? |
Beta Was this translation helpful? Give feedback.
-
Yes, having an option to disable overriding existing symbols/functions and throw an error if you try makes sense. It has bitten me too a couple of times :) |
Beta Was this translation helpful? Give feedback.
-
Hi!
I expected that the unit
m
for meter not to be overridden by scope when usingmath.eval
.Example in REPL:
I guess this a weakness with
eval
because:math.unit(10, 'm/s')
.To give it some context, I wanted to do some physics calculations in a web REPL I made:
Of course I could call the mass
mass
instead ofm
, but as this is quite a common way to name symbols in physics I guess others might fall in the same trap.Any ideas? Could the "unit-syntax" be in some other way? For example:
Beta Was this translation helpful? Give feedback.
All reactions