Hi Mark,

I did some quick cleanup without really trying to change any of your
algorithm or anything here, you can scroll to the bottom for the "cleanest"
one:

    http://paste.factorcode.org/paste?id=3409

Using locals is nice when it makes writing code quickly, but over time
you'll find ways to not need it as often.  In the core, we use it for only
a small percent of the words.  I find locals to be really useful when
trying to port an algorithm from another language without trying to also
rework it into a concatenative style.

Regarding your UI question, we have pop-up menus and table gadgets that can
be used for selection (see for example what happens in the UI if you type
"dup<TAB>" where <TAB> is pressing tab button.  There also is a
ui.gadgets.lists in extras/ that might work for you, although I haven't
used it.

Best,
John.





On Wed, Dec 10, 2014 at 5:14 PM, Mark Green <m...@antelope.nildram.co.uk>
wrote:

> Hi Folks,
>
> I recently had a go at writing a Factor object to pull bitstrings of
> arbitrary length from a bytearray. Since I'm still a bit of a newbie, could
> you give any commentary on the coding or the style and how it could be
> improved?
>
> USING: kernel locals accessors math sequences math.bitwise ;
>
> TUPLE: bitreader bytearray curpos curbit ;: <bitreader> ( bytearray -- 
> bitreader ) 0 0 bitreader boa ;
> : advance ( reader -- reader ) 0 >>curbit [ 1 + ] change-curpos ;
> : check-advance ( reader -- reader ) dup curbit>> 8 = [ advance ] when ;
> :: readsinglevalue ( bits reader -- result ) reader curpos>> reader 
> bytearray>> nth
>                                              reader curbit>> dup bits 1 - + 
> swap bit-range
>                                              reader [ bits + ] change-curbit 
> check-advance drop ;
> : bitsleft ( reader -- result ) curbit>> 8 swap - ;
>
> DEFER: readbits
> :: readmultivalue ( bits reader -- result ) reader bitsleft :> bitsextra
>                                             bitsextra reader readsinglevalue
>                                             bits bitsextra - reader readbits
>                                             bitsextra shift + ;
> :: readbits ( bits reader -- result ) reader curbit>> bits + 8 < [ bits 
> reader readsinglevalue ] [ bits reader readmultivalue ] if ;
>
> Also, is there any widget for the Factor UI that behaves like a combo-box or 
> list-box for entering a string?
>
> Thanks very much,
> Mark.
>
>
>
>
> ------------------------------------------------------------------------------
> 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

Reply via email to