So let me ask the question a different way. mp-units
is a C++, compile time library. So it has to do compile time checking of all quantity expressions to ensure type safety and quantity types are necessary to express compatibility (units of the same kind). And It’s an essential concept for runtime checking as implemented in library(units)
, but that doesn’t necessarily mean it’s useful concept in a quantities DSL which is about expressing relationships between quantities. By extension, I haven’t seen any examples where the qeval
DSL offers any more “safety” or “expressivity” than the qty
DSL.
I think you underestimate the qty
DSL - see above. I think it’s just as expressive and safety is ensured through runtime checks whenever a quantity is used in an expression. Using as
might enable earlier error detection but I’m not convinced that offers much value given runtime checking whenever a quantity is used. That’s not to say I couldn’t be convinced to add it given a compelling use case.
What I’m trying to do is define a simple, minimalist DSL for evaluating quantity expressions, not just for me but for most potential users. What I’m not seeing at the moment is where the qeval
DSL offers any advantages (safety or expressivity), and simpler is almost always better IMO. Clearly a wrapper approach incurs overhead, but whether the qty
DSL continues to exist, and where, is of secondary importance at the moment.
BTW, this no longer works for me; I’m sure it did once:
?- qeval(S is D / T as isq:speed).
ERROR: Domain error: `1' expected, found `isq:speed'
ERROR: In:
ERROR: [17] throw(error(domain_error(1,...),_4962))
ERROR: [16] error:domain_error(1,isq:speed) at /Applications/SWI-Prolog9.3.25.app/Contents/Resources/swipl/library/error.pl:106
ERROR: [15] units:eval_(user,_5050/_5052 as isq:speed,_5040) at /Users/rworkman/.local/share/swi-prolog/pack/units/prolog/units.pl:735
E
Sorry, this still seems wrong to me. So if you think this works as intended (notwithstanding the confusing units in a dimensionless quantity):
?- qeval(X is m/yd).
X = 1*kind_of(1)[si:metre/imperial:yard].
what about:
?- qeval(X is (1*m)/(1*yd)).
X = 1*kind_of(1)[si:metre/imperial:yard].
Here I’m clearly dividing the quantity 1*m
by 1*yd
; the resulting quantity should not have magnitude 1
.
Also:
?- qeval(X =:= m/yd).
X = 1250r1143.
?- qeval(X =:= (1*m)/(1*yd)).
X = 1250r1143.
leading to more confusion.
IMO, it looks like they’re not so useless after all. And floating point errors may be a concern at some point but I don’t think we’re there yet.