11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.2 Records • 71b> evalb( % = b );falseThe usefulness of this is that the entire record can be passed as anaggregate data structure.The record constructor accepts initializers for record slots. That is,you can specify an initial value for any slot in a new or in an unassignedrecord by passing an equation with the slot name on the left side and theinitial value on the right.> r := Record( ’a’ = 2, ’b’ = sqrt( 3 ) );r := module() export a, b; option record ; end module> r:-b;√3Record Types Expressions created with the Record constructor are oftype record.> type( rec, ’record’ );trueThis is a structured type that works the same way that type ‘module‘does but recognizes records specifically.Using Records to Represent Quaternions Records are useful for implementingsimple aggregate data structures for which named access toslots is wanted. For example, four real numbers can be combined to forma quaternion, and you can represent this using a record structure, as follows.> MakeQuaternion := proc( a, b, c, d )> Record( ’re’ = a, ’i’ = b, ’j’ = c, ’k’ = d )> end proc:> z := MakeQuaternion( 2, 3, 2, sqrt( 5 ) );

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!