DISQUS

DISQUS Hello!  The comments on this profile are unclaimed and thus are unverified.

Do they belong to you? Claim these comments.

Slava Pestov's picture

Unregistered

Feeds

aliases

  • Slava Pestov

Slava Pestov

1 year ago

in Tidying up factor code on Phil Dawes' Stuff
Hi Phil,

To get all words used by a word, recursively, use

[ word-def quot-uses ] closure

Also words list>hashtable is just vocab-words

And list>hashtable can be written as

: list>hashtable [ "" ] H{ } map>assoc ;

Assuming you want "" as the values, but usually we use equal keys/values when representing a set as a hashtable:

: list>hashtable [ dup ] H{ } map>assoc ;

1 year ago

in More factor: tabular to triples on Phil Dawes' Stuff
Hi,

I had a go at implementing this. The key, as you've noticed, is to decompose the problem into steps where you're working with no more than a handful of values at once.

Don'write a big loop, instead break it up into multiple iterations over the data and use library words where possible.

USE: math.ranges

: (column-names) ( cols row -- pairs )
2array flip ;

: column-names ( cols rows -- seqs-of-pairs )
[ (column-names) ] curry* map ;

: (number-rows) ( pairs n -- triples )
[ add* ] curry map ;

: number-rows ( seqs-of-pairs -- triples )
tuck length [a,b] [ (number-rows) ] 2map concat ;

: tabular>triples ( start-rowid cols rows -- triples )
column-names number-rows ;
Returning? Login