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


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


  (define <my-list> (:uniform-list <integer>))

  (define <my-nonempty-list> (:nonempty-uniform-list <integer>))

  (declare-method my-map
		  (:simple-proc ((:procedure (<integer>) <integer> pure) <null>)
				<null>
				pure))

  (declare-method my-map
		  (:simple-proc ((:procedure (<integer>) <integer> pure)
				 <my-nonempty-list>)
				<my-nonempty-list>
				pure))

  (add-method my-map
    (lambda (((proc (:procedure (<integer>) <integer> pure))
	      (lst <my-list>))
	     <my-list>
	     pure)
      (raise 'abstract-method)))

  (add-method my-map
    (lambda (((proc (:procedure (<integer>) <integer> pure))
	      (lst <my-nonempty-list>))
	     <my-nonempty-list>
	     pure)
      (cons (proc (car lst)) (my-map proc (cdr lst)))))

  (add-method my-map
    (lambda (((proc (:procedure (<integer>) <integer> pure))
	      (lst <null>))
	     <null>
	     pure)
      null))

  (define main
    (lambda (() <integer> nonpure)
      (let* ((lst (list 1 2 3 4 5))
	     (proc (lambda (((n <integer>)) <integer> pure) (+ n 2)))
	     (result (my-map proc lst)))
	(console-display result)
	(console-newline))
      0)))
