Starting with the helloworld, I am trying to learn me some pony by making an app which echoes back to the user what they have typed in. This works, except for the one line where I _env.out.print(_buffer)
.
class MyInput iso is StdinNotify
var _env: Env
var _buffer: Array[U8]
new iso create(env: Env) =>
_env = env
_buffer = Array[U8].create()
fun ref apply(data: Array[U8] iso) =>
for item in (consume data).values() do
if item == 0x0A then
_env.out.print(_buffer)
_buffer = Array[U8].create()
end
_buffer.push(item)
end
The compile errors I get are:
argument not a subtype of parameter
_env.out.print(_buffer)
^
parameter type: ByteSeq val
be print(data: ByteSeq) =>
^
argument type: Array[U8 val] ref
_env.out.print(_buffer)
From reading the source in github I think that Array[U8] should qualify as a ByteSeq, so I guess that it's a problem with the capabilities. I've tried a few things but I can't seem to copy my ref Array into a val Array. The closest I got was let out: Array[U8] box = _buffer
thanks to the pony mailing list and more trial and error I've got it to work. (thanks sean allen)
so in case any of this needs explaining,
val
argument, it will take aniso
, for reasons I don't fully understandiso
, you need to understandrecover
blocks and destructive readrecover iso
block