Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/simple-units|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == simple-units Simple Units [[toc:]] == Documentation Rudimentary support for the concept of ''quantity''. === 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)}}. === Units (Unit-Set) ==== make-units <macro>(make-units NAME BASE-NAME [system: UNITS-SYSTEM] UNIT-SPEC...) => units</macro> Returns a new {{units}}. Also pollutes the {{UNITS-SYSTEM}} with the new {{units}}, unless it already exists by-name. In which case the new {{units}} is said to be ''standalone''. {{NAME}} is a {{symbol}}, the name of the units. {{BASE-NAME}} is a {{symbol}}, the name of the unit with factor {{1}}. {{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* <macro>(make-units* NAME BASE-NAME [system: UNITS-SYSTEM] UNIT-SPEC...) => units</macro> Like {{make-units}} but always creates an ''standalone'' {{units}} instance, i.e. the {{UNITS-SYSTEM}} is not polluted by the created {{units}}. ==== units? <procedure>(units? OBJ) => boolean</procedure> <procedure>(check-units LOC OBJ [ARGNAM]) => *</procedure> <procedure>(error-units LOC OBJ [ARGNAM])</procedure> ==== units-name <procedure>(units-name UNITS) => symbol</procedure> ==== units-base-name <procedure>(units-base-name UNITS) => symbol</procedure> ==== units-unit-names <procedure>(units-unit-names UNITS) => (list-of symbol)</procedure> ==== units-unit-factor <procedure>(units-unit-factor UNITS NAME) => number</procedure> Returns the value for the {{unit}} with {{NAME}} in {{UNITS}} ==== units-units-system <procedure>(units-units-system UNITS) => units-system</procedure> The {{units-system}} defining {{UNITS}}. === Quantity ==== quantity <macro>(quantity N NAME [UNITS]) => number</macro> <macro>(quantity N NAME [system: UNITS-SYSTEM]) => number</macro> <macro>(quantity N NAME UNITS-NAME system: UNITS-SYSTEM) => number</macro> ==== make-quantity <procedure>(make-quantity N NAME UNITS) => number</procedure> === Units System ==== make-units-system <procedure>(make-units-system NAME) => units-system</procedure> ==== units-system? <procedure>(units-system? OBJ) => boolean</procedure> <procedure>(check-units-system LOC OBJ [ARGNAM]) => *</procedure> <procedure>(error-units-system LOC OBJ [ARGNAM])</procedure> ==== units-system-name <procedure>(units-system-name [UNITS-SYSTEM]) => symbol</procedure> ==== units-system-catalog <procedure>(units-system-catalog [UNITS-SYSTEM]) => (list-of units)</procedure> ==== units-system-units <procedure>(units-system-units NAME [UNITS-SYSTEM]) => units</procedure> Returns the {{units}} of {{NAME}} in the {{UNITS-SYSTEM}}. ==== units-system-units/unit <procedure>(units-system-units/unit NAME [UNITS-SYSTEM]) => units</procedure> Returns the {{units}} with {{unit}} of {{NAME}} in the {{UNITS-SYSTEM}}. ==== units-system-add-units! <procedure>(units-system-add-units! UNITS [UNITS-SYSTEM])</procedure> Adds {{UNITS}} to {{UNITS-SYSTEM}} catalog, replacing any existing {{units}} of the same name. ==== default-units-system <procedure>(default-units-system) => units-system</procedure> <procedure>(default-units-system UNITS-SYSTEM)</procedure> Gets and sets the default {{units-system}}. === Unit ==== factor? <procedure>(factor? OBJ) => boolean</procedure> Is {{OBJ}} a ''factor'', as determined by {{(units-number-predicate)}}? <procedure>(check-factor LOC OBJ [ARGNAM]) => *</procedure> <procedure>(error-factor LOC OBJ [ARGNAM])</procedure> ==== units-factor-scale <procedure>(units-factor-scale) => procedure</procedure> <procedure>(units-factor-scale MULTIPLY)</procedure> Gets and sets the {{procedure}} used to scale factors. {{MULTIPLY}} is a {{(procedure (number number) number)}}. Override when using the {{numbers}} extension, for example. ==== units-number-predicate <procedure>(units-number-predicate) => procedure</procedure> <procedure>(units-number-predicate PREDICATE)</procedure> Gets and sets the {{procedure}} used determine what is a {{number}}. {{PREDICATE}} is a {{(procedure (*) boolean)}}. Override when using the {{numbers}} extension, for example. ==== units-number-system <procedure>(units-number-system MULTIPLY PREDICATE)</procedure> <procedure>(units-number-system) => (values procedure procedure)</procedure> Convenience for {{units-factor-scale}} & {{units-number-predicate?}}. When no arguments returns 2 values, the {{(units-factor-scale)}} and {{(units-number-predicate?)}}. == Usage <enscript language=scheme> (require-extension simple-units) </enscript> == Examples * Using a registerd units <enscript language=scheme> (make-units time s m 60 h (60 m) d (24 h) ms (0.0001 s) us (0.0001 ms)) (define 23h23m23s (+ (quantity 23 h) (quantity 23 m) (quantity 23 s))) </enscript> * Using a ''standalone'' units <enscript language=scheme> (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 (+ (quantity 23 h time-units) (quantity 23 m time-units) (quantity 23 s time-units))) </enscript> * Using {{numbers}}. <enscript language=scheme> (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) ; Defined in 1956 yard 9144/10000 foot (1/3 yard) inch (1/12 foot) mile (1760 yard) furlong (1/8 mile) ; Defined in 1929 nautical-mile 1852 cable (1/10 nautical-mile) fathom (2 yard) ; Dropped in 1970 old-british-nautical-mile (6080/3 yard) old-british-cable (1/10 old-british-nautical-mile) old-british-fathom (1/100 old-british-cable)) </enscript> == Notes * This is best viewed as a toy. == Requirements [[record-variants]] [[list-utils]] [[symbol-utils]] [[lookup-table]] [[moremacros]] [[type-checks]] [[setup-helper]] == Bugs and Limitations * A {{unit}} is not 1st-class. * A {{quantity}} is not 1st-class. Requires extending the numeric tower! * No ''dimension'' concept. * Cannot remove a {{units}} from a {{units-system}}. * Cannot extend a {{units}}, only re-define. * The {{units-factor-scale}} & {{units-number-predicate}} variables are a kludge. * Cannot create derived {{units}}. == Author [[/users/kon-lovett|Kon Lovett]] == Version history ; 1.2.4 : New distributed egg repository system cannot update existing release. ; 1.2.3 : Added {{variable-item}} dependency. ; 1.2.2 : Update dependencies, fix version number. ; 1.2.1 : Update dependencies. ; 1.2.0 : Removed dependency on "format-compiler-base". ; 1.1.0 : ; 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 14 from 10?