Hi David,

> What would you recommend I do to store a list of 3 values as the value of a
> relation in a class?  A class for the list of 3 values or some other better
> way?
> (class +ALH +Entity)
> (rel actual (+Need +Number))         # Actual value
> (rel lo (+Need +Number))               # Low value
> (rel hi (+Need +Number))               # High value
> ...
> (class +Scores +Entity)
> (rel round1 (+Need +ALH))          # Round 1
> (rel round2 (+Need +ALH))          # Round 2
> (rel round3 (+Need +ALH))          # Round 3

The "natural" way is the '+List' relation in combination with '+Bag',
defining a two-dimensional list:

   (class +Scores +Entity)
   (rel rnd (+List +Bag)            # Rounds
      ((+Number) 2)                    # Actual value
      ((+Number) 2)                    # Low value
      ((+Number) 2) )                  # High value

Advantages are that the list is not limited in length, and that it
directly maps to the GUI with a +Chart:

   (gui '(+E/R +Chart) '(rnd : home obj) 5)
   (<table> NIL NIL
      '((NIL "Actual") (NIL "Low") (NIL "High"))
      (do 8
         (<row> NIL
            (gui 1 '(+FixField) 2 10)        # Actual value
            (gui 2 '(+FixField) 2 10)        # Low value
            (gui 3 '(+FixField) 2 10)        # High value
            (gui 4 '(+DelRowButton))         # Delete-row button
            (gui 5 '(+BubbleButton)) ) ) )   # Bubble-button
   (scroll 8 T)

> Then use a helper function as sugar when creating a +Scores object:
> (de new-ALH (actual lo hi)
>    (new '(+ALH) 'actual actual 'lo lo 'hi hi) )

Note that this is not quite correct. Calling 'new' in this way will
create an object in memory, not a DB object. You probably meant

   (new (db: +ALH) '(+ALH) ...


   (new! '(+ALH) ...

With the above model, you could do (assuming a '*Scl' of 2):

   (new! '(+Scores) 'rnd '((2.0 0.0 3.0) (4.0 1.0 7.0)) ...)

At runtime, you can also set the 'rnd' value either completely

   (put!> MyScores 'rnd '((2.0 0.0 3.0) (4.0 1.0 7.0) ...))

or partially

   (put!> MyScores 'rnd (4.0 1.0 7.0))

In the second case the +Bag will take care of 'cons'ing the
one-dimensional list into the two-dimensional bag.

> this.  Also, how could I handle floats rather than integers, say to two
> places?  With the format function?  Thank you in advance for your help.

Yes. Internally it all boils down to 'format'. An E/R definition like

   (rel x (+Number) 2)

tells the system that you expect a scaled integer with two decimal
places, but it is the programmer's duty to take care of it, i.e. using
the right '*Scl' for the reader, and GUI components like

   (gui '(+FixField) 2 10)
to handle the formatting.

♪♫ Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to