Hi Lindsay,
> Bijective Burrows Wheeler Transform
> https://github.com/thinknlive/picolisp-bbwt
Cool! This code looks very good! :)
> As I was working on this I realized I need to start thinking about how to
> organize my code...
>
> The two main functions, encodeBBWT and decodeBBWT feel larger than they
> should be because I have defined smaller functions within them that use
> variables in the same scope.
>
> My question: Is there an 'idiomatic' or recommended way to organize module
> or project code in picolisp?
Binding the functions 'Put' and 'Bwt' locally is perfectly legal, but not really
necessary here, as they never change. So they just create (minimal) runtime
overhead. I would define them the normal way, perhaps as transient symbols if I
want to hide them from the outside world:
(de "put" (B C)
(let (V ...
(de "bwt" (W)
(let (C ...
Using a namespace is also possible, but too much overhead in my feeling for such
a small file. It would go like this:
(symbols 'bbwt 'pico)
(local put bwt)
(de put (B C) # Shadows the built-in 'put', use with care
(let (V ...
(de bwt (W)
(let (C ...
(de pico~encodeBBWT (L)
...
(de pico~decodeBBWT (L)
...
This creates the symbol 'encodeBBWT' in the 'pico' namespace. Another (I think
better) way is:
(de encode (L)
...
(de decode (L)
...
and later, when used from another namespace, call it as
(bbwt~encode ...)
(bbwt~decode ...)
Concerning 'Debug', I would omit it here, and call (trace 'encodeBBWT) or (trace
'bbwt~encode) or (mapc trace '(bbwt~encode bbwt~decode bbwt~put bbwt~bwt) to
debug it.
Other minor improvements:
V2 (car (cdr V)) )
->
V2 (cadr V) )
(while (car W)
(if (not (cdr W))
(Put C (car W))
(Put (car (cdr W)) (car W)) )
->
(while (car W)
(Put
(ifn (cdr W) C (cadr W))
(car W) )
and some similar cases :)
♪♫ Alex
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe