#!/bin/sh
# exec magic \
exec tclsh8.6 "$0" ${1+"$@"}

namespace eval chan {
  namespace ensemble create -command prefix -map {
    initialize {::apply {{channelId mode} {
      if {$mode ne {write}} {
        error "$mode mode not supported"
      }
      return {initialize finalize watch write}
    }}}
    finalize {::apply {{channelId} {
    }}}
    watch {::apply {{channelId eventSpec} {
    }}}
    write {::apply {{channelId data} {
      puts $data
      return [string length $data]
    }}}
  }
} 

set c [chan create {write} chan::prefix]
exec echo hello >@ $c
