(use eggdoc) (define doc `((eggdoc:begin (name "unitconv") (description "Conversion of units of measurement") (author (url "http://chicken.wiki.br/users/ivan-raikov" "Ivan Raikov")) (history (version "1.5" "Ported to Chicken 4") (version "1.4" "The predefined quantities have been put into unit-definitions.scm") (version "1.3" "Bug fix in unit-convert") (version "1.2" "Changed unit-convert to return a single numeric value given a single conversion argument") (version "1.1" "Added information units [patch by Joshua Griffith]") (version "1.0" "Initial release")) (requires) (usage "(require-extension unitconv)" "(include \"unit-definitions\")") (download "unitconv.egg") (documentation (p "The " (tt "unitconv") " library is an implementation of unit " "conversion routines based on the paper by Gordon S. Novak: " (pre "Conversion of Units of Measurement. IEEE Trans. on Software Engineering, vol. 21, no. 8 (Aug. 1995), pp. 651-661.") "(Available online at " (url "http://www.cs.utexas.edu/users/novak/units95.html") "). ") (p "Correctness of unit conversion is established by the technique of dimensional analysis: " "the source and goal units must have the same dimensions. " "Following Novak, this extension defines a dimension as an 8-vector of " "integral powers of the following base quantities: ") (pre #< 39.3700787401575 (unit-convert meter inch 2 3 4) -> (78.740157480315 118.110236220472 157.48031496063) (unit-convert meter kilogram 1) Error: (unitconv) unit-convert : given units are of different dimensions: source= #(unit meter (m meters) [Length] 1.0) ; dest= #(unit kilogram (kg kilograms) [Mass] 1.0) EOF ) (subsection "Procedures and Macros" (procedure "unit-convert:: SRC * DEST * [VAL1 ...] -> (FACTOR1 ... )" ((p "Converts the given numeric values expressed in unit " (tt "SRC") " to their equivalents in unit " (tt "DEST") ". ") (p "Arguments " (tt "SRC, DEST") " are records of type " (tt "unit") ". " "See the definitions below for information about the units that are " "defined by this extension, as well as for information about creating " "new units."))) (procedure "unit-equal?:: UNIT1 * UNIT2 -> BOOL" "Returns true if the two units have the same dimension and factor, false otherwise. ") (macro "(define-quantity name expr)" ((p "Defines a derivative quantity " (tt "NAME") ". ") (p (tt "EXPR") " is an S-expression with the following syntax: " (pre #< (require-extension unitconv) ;; Unit conversion csi> (unit-convert meter inch 2 3 4) (78.740157480315 118.110236220472 157.48031496063) ;; Unit definition csi> (define-unit pascal Pressure (/ kilogram (* meter second second)) Pa) csi> pascal #(unit pascal (Pa) [Pressure] 1.0) csi> (define-unit pound-force-per-square-inch Pressure (/ pound-force (* inch inch)) psi) csi> pound-force-per-square-inch #(unit pound-force-per-square-inch (psi) [Pressure] 6894.75760251898) csi> (unit-convert pound-force-per-square-inch pascal 1850) 12755301.5646601 ;; Unit prefix definition csi> (define millimeter (make-unit-prefix milli meter mm millimeters)) csi> (unit-convert inch millimeter 12) 304.8 EOF )) (license "Copyright 2007-2009 Ivan Raikov. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at ."))) (define (sexp->str x) (if (list? x) (if (null? x) "" (let ((slst (map ->string x))) (string-append "(" (string-intersperse (cons (car slst) (cdr slst)) " ") ")"))) x)) (if (eggdoc->html doc `( (eggdoc-style . ,(lambda (tag) `(""))) (table-section *macro* . ,(lambda (tag name) `(tr (@ (class "heading")) (td (b ,name))))) (define-quantity *macro* . ,(lambda (tag name def) `(tr (td (tt ,name)) (td (tt ,(sexp->str def)))))) (define-unit *macro* . ,(lambda (tag name q factor . abbrevs) `(tr (td (tt ,name)) (td (tt ,(sexp->str q))) (td (tt ,(sexp->str factor))) (td (tt ,(sexp->str abbrevs))) ))) ,@(eggdoc:make-stylesheet doc) )) (void))