| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

SI Units

This version was saved 16 years, 6 months ago View current version     Page history
Saved by PBworks
on September 8, 2007 at 12:06:24 am
 

SI Units

 

This one-file module enforces Standard International unit types. This means that it will not allow a developer to add a time with a length or subtract a volume from a weight. It can also convert units from one prefix to another, i.e. km to cm.

 


 

Unit Prefixes

 

Functions

 

Makers/Constructors

 

make-si-length q unit

 

make-si-mass q unit

 

make-si-time q unit

 

make-si-current q unit

 

make-si-temp q unit

 

make-si-amount q unit

 

make-si-lumint q unit

 

Math

 

.+ x ...

 

.- x ...

 

.* x ...

 

./ x ...

 

Conversion

 

convert-to x new-unit

 

convert-to! x new-unit

 

Destructive version of convert-to.

 

si->string x

 

Examples

 

Example 1

 

Marvin the Martian rover is measuring the distance from one rock to another. He can measure accurately down to 1 mm and up to 1 m.

 

Without using the SI module:

(define (distance x1 y1 x2 y2) ; square root of ((x2 - x1) ^ 2 + (y2 - y1) ^ 2)

(sqrt (+ (expt (- x2 x1) 2)

(expt (- y2 y1) 2))))

(distance 2.0 1.0 0.43 2.4)

The process of conversion must be written in by hand otherwise the results are inaccurate. Also, how do we know that we're getting 2.4 m and not 2.4 mm?

 

Using the SI module:

(define (distance x1 y1 x2 y2) ; square root of ((x2 - x1) ^ 2 + (y2 - y1) ^ 2)

(sqrt (.+ (expt (.- x2 x1) 2)

(expt (.- y2 y1) 2))))

(distance (make-si-length 2.0 'nil) ; 2.0 m

(make-si-length 1.0 'centi) ; 1.0 cm = 0.01 m

(make-si-length 0.43 'nil) ; 0.43 m

(make-si-length 2.4 'milli) ; 2.4 mm = 0.0024 m

 

The difference is that the units are specified and that a different function is used for mathematical operations. Instead of +, we use .+

 

Example 2

Comments (0)

You don't have permission to comment on this page.