;; -*-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 test260)


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


  (define-param-proc my-sum (%number)
		     (((v1 (:mutable-value-vector %number))
		       (v2 (:mutable-value-vector %number)))
		      (:mutable-value-vector %number)
		      (force-pure))
    (let ((len1 (mutable-value-vector-length v1))
	  (len2 (mutable-value-vector-length v2)))
      (assert (= len1 len2))
      (let ((result (make-mutable-value-vector %number len1 (zero %number))))
	(do ((i <integer> 0 (+ i 1)))
	    ((>= i len1))
	  (mutable-value-vector-set!
	   result i
	   (+ (mutable-value-vector-ref v1 i)
	      (mutable-value-vector-ref v2 i))))
	result)))


  (define-param-method display-vector (%number)
		       (((v (:mutable-value-vector %number)))
			<none>
			(nonpure))
    (let ((len (mutable-value-vector-length v)))
      (do ((i <integer> 0 (+ i 1))) ((>= i len))
	(console-display
	 (mutable-value-vector-ref v i))
	(if (< i (- len 1))
	    (console-display-string " ")))))


  (define main
    (lambda (() <none> nonpure)
      (let* ((v1 (mutable-value-vector <real> 1.0 2.0 3.0))
	     (v2 (mutable-value-vector <real> -1.5 6.0 2.5))
	     (v-sum (my-sum v1 v2)))
	(display-vector v-sum)
	(console-newline)))))
