#!hacchpsimguile -b
!#
;; "channel-sync-desync-a-33.hacchpsimscm"
;; copy-modified from "channel-sync-desync-a-31.hacchpsimscm"
;; vi: ft=scheme
;;	$Id: channel-sync-desync-a-33.hacchpsimscm,v 1.2 2007/04/20 18:27:09 fang Exp $
;; @haco@ channel-sync-desync-a.haco-a
;; @chpsimtrace@ channel-sync-desync-a-05.chpsimtrace

;; Testing failure to open trace file.

(use-modules (hackt chpsim-trace))
(use-modules (hackt hackt))
(use-modules (hackt streams))
(use-modules (ice-9 streams))
(use-modules (srfi srfi-1)) ; for any

(define x (open-chpsim-state-trace-stream "channel-sync-desync-a-05.chpsimtrace"))
x

; hard-coded predicate for channel[3]
(define (channel-3? t) (and (eq? (caar t) 'channel) (= (cdar t) 3)))

; finds channel.3 modifications
(define y (stream-filter
  (lambda (s)
    (any
      channel-3?
	; caar is the type tag, cdar is the global index
      (chpsim-state-trace-entry-channels s) ; from (hackt chpsim-trace)
    ) ; end any
  ) ; end lambda
  x) ; end stream-filter
)

; displays stream of events that affected channel 3
(stream-for-each-display-newline y)

; cut out non-channel data
(define z (stream-map
  (lambda (x)
    (cons (chpsim-state-trace-entry-index x)
      (chpsim-state-trace-entry-channels x))
  )
y))

(stream-for-each-display-newline z)

; an equivalent construction
(define y2 (stream-filter
  (lambda (s)
    (any
      (lambda (e) (reference-equal? (car e) '(channel . 3)))
	; caar is the type tag, cdar is the global index
      (chpsim-state-trace-entry-channels s) ; from (hackt chpsim-trace)
    ) ; end any
  ) ; end lambda
  x) ; end stream-filter
)

; should be equivalent to y
(stream-for-each-display-newline y2)

