;; -*-theme-d-*-

;; Copyright (C) 2014  Tommi Höynälänmaa
;; Distributed under GNU General Public License version 3,
;; see file doc/GPL-3.

;; Expected results: translation and running OK


(define-proper-program (tests test264)


  (import (standard-library core)
	  (standard-library list-utilities)
	  (standard-library console-io))


  (define-class <my-record> <object> #t #f #f public ()
    ((name <string> public public)
     (address <string> public public)))


  (define-class <my-database> <object> #t #f #f public ()
    ((contents (:uniform-list <my-record>) public module)))



  (define-simple-proc add-record (((db <my-database>) (rec <my-record>))
				  <none>
				  (nonpure))
    (field-set! db 'contents
		(cons rec (field-ref db 'contents))))


  (define-simple-proc display-record (((rec <my-record>)) <none> (nonpure))
    (console-display-string "name: ")
    (console-display-string (field-ref rec 'name))
    (console-newline)
    (console-display-string "address: ")
    (console-display-string (field-ref rec 'address))
    (console-newline))


  (define-simple-proc display-database (((db <my-database>)) <none> (nonpure))
    (for-each display-record (field-ref db 'contents))
    (console-newline))


  (define main
    (lambda (() <none> nonpure)
      (let-mutable ((db (:maybe <my-database>) null))
	(let ((rec1 (make <my-record> "Tommi" "PL 0"))
	      (rec2 (make <my-record> "Janne" "PL 1"))
	      (rec3 (make <my-record> "Jukka" "PL 2")))
	(set! db (make <my-database> null))
	(let ((db1 (cast <my-database> db)))
	  (add-record db1 rec1)
	  (add-record db1 rec2)
	  (add-record db1 rec3)
	  (display-database db1)))))))
