Comments (13)
Ok did some digging on the Discord history and found the answer:
I've just added basic support for units written in accented quotes (
`kg*m*s^-2`
etc.). For arguments to procedures one needs to define essentially all units usingdefUnit
before once (or use them using.
operator before, which defines them automatically.
from unchained.
Okay here comes a list of some (hopefully) useful units:
- Foot
- Full name:
Foot
- Shorthand:
ft
- Quantity:
Length
- Conversion:
1 ft = 0.3048 m
- Full name:
- Yard
Yard
yd
Length
1 yd = 0.9144 m
- Acre
Acre
acre
(couldn't find any shorthand)Area
1 acre = 4046.8564224 m²
- Ounce
Ounce
oz
Mass
1 oz = 28.349523125 g
- Slug
Slug
slug
Mass
1 slug = 14.59390294 kg
- Pound-force
PoundForce
lbf
Force
1 lbf = 4.44822162 N (= g.to(ft•s⁻²) * 1.lbs)
That should be it for units. Noticed you didn't have the gravitational acceleration among the constants, I guess that should be added as well?
g0 = 9.80665.m•s⁻²
G = 6.67430.m³•kg⁻¹•s⁻²
from unchained.
Ah, I forgot the constants. Will add them later. And I'll be so prudent as to use the correct value for G
. 🙊
from unchained.
Oh that tiny thing... 😆🙈
from unchained.
Well, on my part I'm pretty indifferent about what units to actually add. I suppose the common imperial ones are important. Of the more esoteric ones like chain
I really don't care.
If you (or someone else) provides:
- a full name
- a shorthand
- what quantity it is
- a conversion to SI units
I'll happily implement it.
If someone wants me to implement too many, I'll probably think about a small rewrite of the internal code. New units are a bit annoying to add right now as the stuff needs to be inserted into too many places. It's not a lot of work, but it gets tiring. It should be rather easy to automate most of that away with a DSL for unit definitions (which would be great, as it might eventually allow for arbitrary systems of units based on user defined unit classes).
edit: on a more practical side for a possible blog: think about the units you want to include in it. Tell me about them 1-2 days in advance and I'll have them ready by the time you want to use them. :)
from unchained.
Well, on my part I'm pretty indifferent about what units to actually add. I suppose the common imperial ones are important. Of the more esoteric ones like chain I really don't care.
Well then we'll just implement the units I need at the moment 😜
If you (or someone else) provides: [...] I'll happily implement it.
That's nice of you :)
If someone wants me to implement too many, I'll probably think about a small rewrite of the internal code. New units are a bit annoying to add right now as the stuff needs to be inserted into too many places. It's not a lot of work, but it gets tiring. It should be rather easy to automate most of that away with a DSL for unit definitions (which would be great, as it might eventually allow for arbitrary systems of units based on user defined unit classes).
Oh that does sound quite tiring 🤔 A DSL for it is inevitable sometime in the future either way I guess? Just imagine how many lines of code that PR will remove 🤣
edit: on a more practical side for a possible blog: think about the units you want to include in it. Tell me about them 1-2 days in advance and I'll have them ready by the time you want to use them. :)
Again, very kind of you!:D I'm still doing some research into real-world examples where units caused trouble so I don't have a definite list yet but I can't imagine it being out of the most common units so I'll write you a list of the ones I think I'll use tomorrow.
On the topic of the blog, do you think Define custom units
is something that should be included in a Units Basics
tutorial in the current state of Unchained? (Referring to the fact you think it's quite verbose atm without a DSL)
from unchained.
If someone wants me to implement too many, I'll probably think about a small rewrite of the internal code. New units are a bit annoying to add right now as the stuff needs to be inserted into too many places. It's not a lot of work, but it gets tiring. It should be rather easy to automate most of that away with a DSL for unit definitions (which would be great, as it might eventually allow for arbitrary systems of units based on user defined unit classes).
Oh that does sound quite tiring A DSL for it is inevitable sometime in the future either way I guess? Just imagine how many lines of code that PR will remove
It probably won't remove any, because the macro magic required will eat those. But by now at least I have an idea that the whole implementation works and I can implement a macro. Originally it was more "exploratory research" and the hard part was the parsing, simplifications etc. Those will all remain unchanged fortunately (as all of that is independent of the actual units).
edit: on a more practical side for a possible blog: think about the units you want to include in it. Tell me about them 1-2 days in advance and I'll have them ready by the time you want to use them. :)
Again, very kind of you!:D I'm still doing some research into real-world examples where units caused trouble so I don't have a definite list yet but I can't imagine it being out of the most common units so I'll write you a list of the ones I think I'll use tomorrow.
You're welcome!
On the topic of the blog, do you think
Define custom units
is something that should be included in aUnits Basics
tutorial in the current state of Unchained? (Referring to the fact you think it's quite verbose atm without a DSL)
By defining a custom unit you mean some combination of existing ones (so just calling defUnit
?) or adding completely new ones?
If the former, yes I'd include it, because it's just one macro call and people will need it.
If it's the latter, no. That is too clumsy at the moment and shouldn't be needed for most use cases (for that people should open issues for the time being).
from unchained.
It probably won't remove any, because the macro magic required will eat those. But by now at least I have an idea that the whole implementation works and I can implement a macro. Originally it was more "exploratory research" and the hard part was the parsing, simplifications etc. Those will all remain unchanged fortunately (as all of that is independent of the actual units).
Fair enough :)
By defining a custom unit you mean some combination of existing ones (so just calling defUnit?) or adding completely new ones?
I'm not sure tbh I'm still a bit confused when you need defUnit
and when you don't 😅 But I guess it's the first case.
from unchained.
And no hurry, I won't be able to do much work this weekend either way :)
from unchained.
Lots of thanks! :D No hurry! You mean the value I got from Wikipedia is wrong? 🤣 (Or shouldn't I have ignored the uncertainty perhaps :P)
from unchained.
Lots of thanks! :D No hurry! You mean the value I got from Wikipedia is wrong? (Or shouldn't I have ignored the uncertainty perhaps :P)
You forgot a tiny ⁻¹¹ in there. ;)
G = 6.67430.m³•kg⁻¹•s⁻²
vs
G = 6.67430e-11.m³•kg⁻¹•s⁻²
almost the same, haha.
from unchained.
Not imperial, but noting it here: Consider adding Percent
as an additional UnitLess
unit.
from unchained.
I have to copypaste si_units.nim to add
declareQuantities:
Derived:
SpecificEnergy:
[(Length, 2), (Time, -2)]
declareUnits:
Derived:
BritishThermalUnit:
short:
btu
quantity:
Energy
conversion:
1055.06.J
from unchained.
Related Issues (14)
- Tests fail on non Nim devel HOT 1
- Degree to Radians conversion fails HOT 1
- Division of (some?) units is broken HOT 1
- UFCS breaks type checking of proc arguments HOT 1
- Add `*=`, `+=` and friends HOT 1
- Math with SI & imperial mix don't convert in some cases HOT 1
- Add remaining derived SI units HOT 5
- Control the precision of units HOT 12
- Combining unchained and cligen.dispatch results in extremely long compilation HOT 20
- Can't use two generic parameters of the same quantity HOT 3
- `const` variables lose their type information HOT 1
- Declarative unit definitions and unit systems HOT 8
- Unit math with certain compounds HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unchained.