5 ms·
Ha! I implemented "concatenative" programming for Java as Binding [1] (or Unit) expressions, but had no idea. Seriously, never came across that term before this
by mckinney 4y ago
Ha! I implemented "concatenative" programming for Java as Binding [1] (or Unit) expressions, but had no idea. Seriously, never came across that term before this post.
The idea with binding expressions is the type of expression A and the type of expression B implement "reactions" with one another in order to form a binding expression when they are lexically adjacent.
65 mph
The type of `mph` defines a post reaction method with the type of `65` as an argument that results in type Rate. As I understand it this is concatenative, right?
Another example:
Money payment = 1.5M USD;
There are tons of these.
Concatenative programming in general feels like it should have a more prominent place in mainstream languages. Just my take.
[1] https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-ext#unit-expressions https://github.com/manifold-systems/manifold/tree/master/man...
- bmitc 4y agoIt is my understanding that the JVM itself uses a stack model at its core.
- opminion 4y agoIf you see units as multiplicative factors: 1.5 USD = 1.5 * USD 65 mph = 65 * mile / hour you can then use simple algebra to solve unit conversion and many other common deductive reasoning questions ("how many miles per gallon...?"), relying on the units to guide you to the solution. There's probably a name for this, and it is indeed built into the SI notation (km/h vs mph).
- chriswarbo 4y agoSounds like https://en.wikipedia.org/wiki/Dimensional_analysis https://en.wikipedia.org/wiki/Dimensional_analysis
- mckinney 4y agoThis is already implemented with manifold's unit expressions, but is made richer and more readable via concatenative features. For instance, '1.5 * USD' is not as readable as simply '1.5 USD'. However, unit expressions leverage operators for dimensional arithmetic: Force f = 5 kg * 9.807 m/s/s; // result: 49.035 Newtons Area space = (20ft + 2in) * (37ft + 7.5in); // result: 758 37/48 ft² All unit expressions internally store amounts as SI units, which enables interunit expressions. Length height = 6 ft + 4 cm; // mix SI and US units out.println(height.to(ft)); // display any unit You aren't limited to units. Generally, any concatenative sequence can be implemented. Like ranges: IntegerRange range = 1 to 5; Here the `to` identifier's type implements reactions to Number types to produce range types, which enables: for (int i: 1 to 5) { out.println(i); } See the manifold project's Unit and Science modules: Units: https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-ext#unit-expressions https://github.com/manifold-systems/manifold/tree/master/man... Science: https://github.com/manifold-systems/manifold/tree/master/manifold-deps-parent/manifold-science https://github.com/manifold-systems/manifold/tree/master/man...