Fixed coding errors in unit example

This commit is contained in:
btracey
2013-10-09 10:12:57 -07:00
parent 52e857f38a
commit 7cae6014b0
2 changed files with 7 additions and 3 deletions

8
doc.go
View File

@@ -66,15 +66,17 @@
// used, however, to create the unit of 'Slide', because in this case slide // used, however, to create the unit of 'Slide', because in this case slide
// is just a measurement of area. Instead, a constant could be defined. // is just a measurement of area. Instead, a constant could be defined.
// const Slide unit.Area = 0.001875 // m^2 // const Slide unit.Area = 0.001875 // m^2
// var WhiteBloodCellDim unit.Dimension
// func init(){ // func init(){
// WhiteBloodCellDim := unit.NewDimension() // WhiteBloodCellDim = unit.NewDimension()
// } // }
// type WbcPerArea float64 // type WbcPerArea float64
// func (w WbcPerArea) Unit() *Unit{ // func (w WbcPerArea) Unit() *Unit{
// return NewUnit(w, Dimensions{WhiteBloodCellDim: 1, LengthDim: -2}) // return unit.NewUnit(float64(w), unit.Dimensions{WhiteBloodCellDim: 1, unit.LengthDim: -2})
// } // }
// func main(){ // func main(){
// // Add in something about using Unit // v := WbcPerArea(15)
// fmt.Println(v.Unit())
// } // }
// Please note that Unit cannot catch all errors related to dimensionality. // Please note that Unit cannot catch all errors related to dimensionality.
// Different physical ideas are sometimes expressed with the same dimensions // Different physical ideas are sometimes expressed with the same dimensions

View File

@@ -35,6 +35,8 @@ type Dimensions map[Dimension]int
var lastCreatedDimension Dimension = lastPackageDimension var lastCreatedDimension Dimension = lastPackageDimension
var newUnitMutex *sync.Mutex = &sync.Mutex{} // so there is no race condition for dimension var newUnitMutex *sync.Mutex = &sync.Mutex{} // so there is no race condition for dimension
//var dimensionStrings map[Dimension]string = make()
// NewDimension returns a new dimension variable which will have a // NewDimension returns a new dimension variable which will have a
// unique representation across packages to prevent accidental overlap. // unique representation across packages to prevent accidental overlap.
// NewDimension should only be called for unit types that are orthogonal // NewDimension should only be called for unit types that are orthogonal