You are looking at historical revision 19252 of this page. It may differ significantly from its current revision.
simple-units
Very rudimentary support for the concept of quantity.
- simple-units
- Documentation
- Argument Conventions
- make-units
- units?
- units-name
- units-base-name
- units-unit-names
- units-unit
- units-units-system
- make-quantity
- make-units-system
- units-system?
- units-system-name
- units-system-catalog
- units-system-units
- units-system-units/unit
- default-units-system
- unit?
- unit-name
- unit-factor
- units-scale
- units-number?
- Usage
- Examples
- Notes
- Requirements
- Bugs and Limitations
- Author
- Version history
- License
Documentation
Argument Conventions
OBJ is a Scheme object
NAME is a symbol
BASE-NAME is a symbol, the name of unit with the unit value of 1.
UNITS-NAME is a symbol
UNITS is an instance of units (Read as unit-set.)
UNITS-SYSTEM is an instance of units-system, the default is (default-units-system).
make-units
[syntax] (make-units NAME BASE-NAME [system: UNITS-SYSTEM] UNIT-SPEC...) => units[syntax] (make-units NAME BASE-NAME [system: UNITS-SYSTEM] UNIT-SPEC...) => units
[syntax] (make-units* NAME BASE-NAME [system: UNITS-SYSTEM] UNIT-SPEC...) => units
UNIT-SPEC is the form <unit-spec>.
<unit-spec> := <unit-name> <unit-value>
<unit-value> ::= <unit-factor> <unit-value> ::= <unit-name> <unit-value> ::= (<unit-factor> <unit-name>)
<unit-name> ::= <symbol>
<unit-factor> ::= <number>
make-units* creates an anonymous units instance.
units?
[procedure] (units? OBJ) => boolean[procedure] (check-units LOC OBJ [ARGNAM]) => *
[procedure] (error-units LOC OBJ [ARGNAM]
units-name
[procedure] (units-name UNITS) => symbolunits-base-name
[procedure] (units-base-name UNITS) => symbolunits-unit-names
[procedure] (units-unit-names UNITS) => (list-of symbol)units-unit
[procedure] (units-unit UNITS NAME) => unitReturns the unit with unit-name of NAME.
units-units-system
[procedure] (units-units-system UNITS) => units-systemThe units-system defining UNITS.
make-quantity
[syntax] (make-quantity N NAME [UNITS]) => number[syntax] (make-quantity N NAME [system: UNITS-SYSTEM]) => number
[syntax] (make-quantity N NAME UNITS-NAME system: UNITS-SYSTEM) => number
make-units-system
[procedure] (make-units-system NAME) => units-systemunits-system?
[procedure] (units-system? OBJ) => boolean[procedure] (check-units-system LOC OBJ [ARGNAM]) => *
[procedure] (error-units-system LOC OBJ [ARGNAM]
units-system-name
[procedure] (units-system-name [UNITS-SYSTEM]) => symbolunits-system-catalog
[procedure] (units-system-catalog [UNITS-SYSTEM]) => (list-of units)units-system-units
[procedure] (units-system-units NAME [UNITS-SYSTEM]) => unitsunits-system-units/unit
[procedure] (units-system-units/unit NAME [UNITS-SYSTEM]) => unitsdefault-units-system
[procedure] (default-units-system) => units-system[procedure] (default-units-system UNITS-SYSTEM)
Gets and sets the default units-system.
unit?
[procedure] (unit? OBJ) => boolean[procedure] (check-unit LOC OBJ [ARGNAM]) => *
[procedure] (error-unit LOC OBJ [ARGNAM])
unit-name
[procedure] (unit-name UNIT) => symbolunit-factor
[procedure] (unit-factor UNIT) => numberunits-scale
[procedure] (units-scale) => procedure[procedure] (units-scale MULTIPLY) => procedure
MULTIPLY is a (procedure (number number) number).
Override when using the numbers extension, for example.
units-number?
[procedure] (units-number?) => procedure[procedure] (units-number? PREDICATE) => procedure
PREDICATE is a (procedure (*) boolean).
Override when using the numbers extension, for example.
units-number-system
[procedure] (units-number-system MULTIPLY PREDICATE)Convenience for units-scale & units-number?.
Usage
(require-extension simple-units)
Examples
- Using a registerd units
(make-units time s m 60 h (60 m) d (24 h) ms (0.0001 s) us (0.0001 ms)) (define 23h23m23s (+ (make-quantity 23 h) (make-quantity 23 m) (make-quantity 23 s)))
- Using an unregisterd units
(define time-units (make-units* time s m 60 h (60 m) d (24 h) ms (0.0001 s) us (0.0001 ms))) (define 23h23m23s (+ (make-quantity 23 h time-units) (make-quantity 23 m time-units) (make-quantity 23 s time-units)))
- Using numbers.
(use numbers) (units-number-system * number?) ;must override (make-units time s m 60 h (60 m) d (24 h) ms (1/1000 s) us (1/1000 ms)) (make-units distance m km 1000 cm 1/100 mm (1/10 cm) nm (1/1000 mm) yard 9144/10000 ; Defined in 1956 foot (1/3 yard) inch (1/12 foot) mile (1760 yard) furlong (1/8 mile) fathom (2 yard) ; Defined in 1929 nautical-mile 1852 cable (1/10 nautical-mile) old-brit-nautical-mile ; Dropped in 1970 (6080/3 yard) old-brit-cable (1/10 old-brit-nautical-mile) old-brit-fathom (1/100 old-brit-cable))
Notes
Requirements
format-compiler-base record-variants list-utils type-checks
Bugs and Limitations
- The quantity is not 1st-class. Requires extending the numeric tower!
- No dimension concept.
- No units-systems catalog.
- Cannot remove a units from a units-system.
- Cannot extend a units.
- The units-scale variable is a kludge.
- Cannot create derived units.
This would be nice:
(define mile/h (make-derived-unit mile / h)) (define 23mile/h (make-quantity 23 mile/h))
Author
Version history
- 1.0.0
- Hello.
License
Copyright (C) 2010 Kon Lovett. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.