Hi Mark,
Just a couple comments:
Those buttons are "border buttons":
IN: scratchpad "The Label" [ "the action" print ] <border-button>
gadget.
(also note the use of gadget. for displaying a gadget inline with the
listener, kinda neat way to test UI stuff)
Your code looks pretty nice, I would only add a couple things:
- we tend to use less than 80 characters wide, and try for 64 or less.
- we also tend to use 4 character spaces at the beginning for indentation,
although it doesn't matter
- there are currying concepts that can reduce duplicate code
[ "size" get-int-attr ] [ "number" get-int-attr ] [ "offset"
get-int-attr ] tri
"size" "number" "offset" [ get-int-attr ] tri-curry@ tri
- learn about replicate and fried quotations and other higher level ways of
building sequences (produce, selector, collector, follow, etc.)
instead of this:
[ name>> V{ } ] [ size>> ] [ count>> ] tri
[ [ read suffix ] keep ] times drop
do this:
[ name>> ] [ count>> ] [ size>> ] tri '[ _ read ] replicate
(or use ``V{ } replicate-as`` if you need it to be a vector)
Best,
John.
On Fri, Dec 12, 2014 at 2:04 PM, Mark Green <m...@antelope.nildram.co.uk>
wrote:
> Thanks. I've worked out a few of the basics of how bitstreams works but
> I'm not sure about the whole thing.. I do have another bit of code that I'd
> be very grateful if folks could look at and tell me if it could be done
> better, because I'm really not used to this language at all!
>
> Also, is there somewhere in the UI library the prefabs for the neat
> rounded coloured buttons that the Factor UI uses?
>
> Mark
>
>
> USING: kernel locals accessors math sequences math.bitwise bitstreams
> io.files io xml io.encodings.binary xml.traversal strings
> assocs math.parser combinators ;
> FROM: io => read ;
>
> IN: fr8x
>
> TUPLE: chunkinfo
> { name string }
> { size integer }
> { count integer }
> { offset integer } ;
>
> TUPLE: chunkdata name data ;
>
> : get-header ( -- bin ) "\x8d" read-until drop ;
>
> : chop-junk ( bin -- slice ) 4 tail-slice ;
>
> : get-chunk-tags ( head -- vector ) children>> 1 swap nth children-tags ;
>
> : get-int-attr ( attrs name -- int ) swap at* drop string>number ;
>
> : parse-chunk-tag ( tag -- chunkspec )
> [ name>> main>> ] keep
> attrs>>
> [ "size" get-int-attr ] [ "number" get-int-attr ] [ "offset"
> get-int-attr ] tri
> chunkinfo boa ;
>
> : parse-chunk-tags ( vector -- chunks ) [ parse-chunk-tag ] map ;
>
> : parse-header ( -- chunks ) get-header chop-junk bytes>xml get-chunk-tags
> parse-chunk-tags ;
>
> : load-chunk ( chunkinfo offset -- chunkdata )
> swap
> [ offset>> + seek-absolute seek-input ] keep
> [ name>> V{ } ] [ size>> ] [ count>> ] tri
> [ [ read suffix ] keep ] times
> drop chunkdata boa ;
>
> : load-chunks ( chunkinfos -- chunkdatas ) tell-input [ load-chunk ] curry
> map ;
>
> : parse-set-file ( -- head ) parse-header load-chunks ;
>
> : load-set-file ( fn -- head ) binary [ parse-set-file ] with-file-reader
> ;
>
> : test ( -- head ) "FR-8X_SET_001.ST8" load-set-file ;
>
>
>
> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
>
> http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk