Initializing help system before first use

Working with records


Type: Programming
Rating: 3 (intermediate)
Description:
  • defining records and arrays of records
  • accessing record fields
  • assigning values to record fields
  • initialization with data from file
  • defining records of records (recorddef2.mos)
  • selecting record fields in initializations (recorddef2.mos)
File(s): recorddef.mos, recorddef2.mos
Data file(s): recorddef.dat, recorddef2.dat


recorddef.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file recorddef.mos 
   `````````````````` 
   Defining and initializing records.
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Nov. 2006, rev. Sep. 2018
*******************************************************!)

model "Defining records"

 public declarations 
  R = 1..10
  D: public record
   name: string
   values: array(R) of real
  end-record
 end-declarations

 public declarations 
  mydata = public record                   ! Define a named record
   name: string
   values: array(R) of real
  end-record
  M: mydata
  A: dynamic array(T:range) of mydata
 end-declarations
 
 D.name:= "D"
 forall(i in R) D.values(i):= i
 writeln("Values of ", D.name, ": ", D.values)

 initializations from "recorddef.dat"
  A
 end-initializations

 writeln("An entry of A: ", A(1))
 writeln("'name' of an entry of A: ", A(4).name)
 writeln("'values' of an entry of A: ", A(3).values)
 writeln("First entry of 'values' of 'A4': ", A(4).values(1))

 forall(i in T | exists(A(i))) writeln(A(i).name)

end-model 

recorddef2.mos
(!******************************************************
   Mosel User Guide Example Problems
   ================================= 

   file recorddef2.mos 
   ``````````````````` 
   Defining and initializing records.
   - Records within records,
     selection of fields in initializations -
 
   (c) 2008 Fair Isaac Corporation
       author: S. Heipcke, Sep. 2007, rev. Sep. 2018
*******************************************************!)

model "Defining records"

 public declarations 
  R = 1..10

  mydata = public record                      ! Define a named record
   name: string
   values: array(R) of real
  end-record

  B: dynamic array(T:range) of public record  ! Define an unnamed record
   val: real
   rd: mydata                          ! Record field containing a record
  end-record
 end-declarations
 
 initializations from "recorddef2.dat"
  B(rd) as "B"
  B(val) as "C"
  B(rd(name)) as "D"
  B(rd(values)) as "E"
  B(rd(values)) as "F"
 end-initializations

 writeln(B)

end-model 

© 2001-2023 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.