Hi Maxim,
I like your idea and think it's worth further exploration.
You're right that the stream-read method you show is a little more awkward
than it should be.
Here's one way I might go about implementing stream-read:
Use inheritance
Factor out the counter update code
Use new slot accessors
The 'adjust-counter' factor might look like this:
: adjust-counter ( dns-stream string -- string )
tuck
length
over counter>> + >>counter drop ;
Or in terms of a slot changer:
: adjust-counter ( dns-stream string -- string )
tuck length [ + ] curry change-counter ;
Then the 'stream-read' method becomes (using the new syntax):
METHOD: stream-read { integer dns-stream -- str/f }
tuck
stream-read
adjust-counter ;
Which isn't so bad.
Using fry in 'adjust-counter' would yield:
: adjust-counter ( dns-stream string -- string )
tuck length '[ , + ] change-counter ;
I'm experimenting with the idea of having quotations automatically fry if they
contain fry directives, so the above would be:
: adjust-counter ( dns-stream string -- string )
tuck length [ , + ] change-counter ;
If inheritance turns out to not be a good solution here, you can just keep the
underlying stream in a slot and access it like you do via 'delegate'.
By the way, I'm not making these suggestions to detract from your idea. I
think it's pretty cool and might come in handy in more complex cases.
Ed
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk