readByte

55 views
Skip to first unread message

RedDevil

unread,
Dec 7, 2012, 7:10:08 PM12/7/12
to clay-l...@googlegroups.com
I am back looking at Clay again and I am having trouble getting readByte() to work.  The following cone snippet works:

var f1 = File("mbi-file-clay",READ);
var b = Byte();
read(f1,@b,1);

but how do I can the 'readByte()' function instead of the low-level 'read' one?  I don't understand the 'Maybe' and 'nothing' constructs so that may be what I am missing.  Any help would be appreciated.  RD

Stepan Koltsov

unread,
Dec 7, 2012, 7:36:55 PM12/7/12
to clay-l...@googlegroups.com
Something like this should work:

===
    var f = File("/etc/passwd", READ);
    while (true) {
        var b = readByte(f);
        if (nothing?(b))
            break;
        writeByte(stdout, just(b));
    }
===

Maybe is a regular type defined in core.maybe module. See https://github.com/jckarter/clay/blob/master/lib-clay/core/maybe/maybe.clay .

--
Stepa

RedDevil

unread,
Dec 7, 2012, 8:30:04 PM12/7/12
to clay-l...@googlegroups.com
Thanks Stepa,

Thanks for clarifying.  What does 'just(b)' do over using only 'b' in the writeByte call.

Also I am having trouble with 2D Arrays - I need to set up a 2D Byte Array and then read the values from a file - should I make another post?
Reply all
Reply to author
Forward
0 new messages