On Wed, Apr 10, 2013 at 12:38 AM, leonard <leonard14...@gmail.com> wrote:

> We need to actually parse each word definition into an abstract syntax
> tree.
>
> We need to traverse each tree, from top to bottom, BFS.
>
> For each node, check whether an equivalent subtree occurs elsewhere.
>
> In code that doesn't use variables, equivalence should be easy to
> determine.
>

Luckily, building the AST is work you don't need to do, because that's how
Factor code is already represented:

: usage ( -- ) "Usage: move source ... target" print ;

: move-to-dir ( args -- )
    dup last file-info directory?
    [ unclip-last move-files-into ] [ drop usage ] if ;

IN: scratchpad \ move-to-dir def>> .
[
    dup last file-info directory?
    [ unclip-last move-files-into ] [ drop usage ] if
]
IN: scratchpad [ ] sequence? . ! quotations are sequences
t

Really, Factor words are just nested sequences (quotations), so they're
already a tree structure.

Wikipedia ( http://en.wikipedia.org/wiki/Duplicate_code ) points to an
interesting and very relevant paper:
http://www.semanticdesigns.com/Company/Publications/ICSM98.pdf

Regards,
--Alex Vondrak
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to