<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Phil Dawes' Stuff - Latest Comments in More factor: tabular to triples</title><link>http://phildawesstuff.disqus.com/</link><description></description><language>en</language><lastBuildDate>Mon, 15 Oct 2007 23:01:39 -0000</lastBuildDate><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753624</link><description>I prefer the Haskell list comprehension version:&lt;br&gt;&lt;br&gt;[(i,col,cell)|(i,row)&amp;lt;-zip [startid..] rows, (col,cell) &amp;lt;- zip cols row]&lt;br&gt;&lt;br&gt;Now I wonder how this will get formatted? Need a preview button.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Greg M</dc:creator><pubDate>Mon, 15 Oct 2007 23:01:39 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753619</link><description>Hi,&lt;br&gt;&lt;br&gt;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.&lt;br&gt;&lt;br&gt;Don'write a big loop, instead break it up into multiple iterations over the data and use library words where possible.&lt;br&gt;&lt;br&gt;USE: math.ranges&lt;br&gt;&lt;br&gt;: (column-names) ( cols row -- pairs )&lt;br&gt;    2array flip ;&lt;br&gt;&lt;br&gt;: column-names ( cols rows -- seqs-of-pairs )&lt;br&gt;    [ (column-names) ] curry* map ;&lt;br&gt;&lt;br&gt;: (number-rows) ( pairs n -- triples )&lt;br&gt;    [ add* ] curry map ;&lt;br&gt;&lt;br&gt;: number-rows ( seqs-of-pairs -- triples )&lt;br&gt;    tuck length [a,b] [ (number-rows) ] 2map concat ;&lt;br&gt;&lt;br&gt;: tabular&amp;gt;triples ( start-rowid cols rows -- triples )&lt;br&gt;    column-names number-rows ;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Slava Pestov</dc:creator><pubDate>Mon, 15 Oct 2007 14:56:26 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753621</link><description>Thanks Christopher - it was a missing close brace in the factor link preventing it from being displayed.&lt;br&gt;I'll definitely check out both Cat and ripple - thanks for the links</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Phil Dawes</dc:creator><pubDate>Sat, 13 Oct 2007 15:32:33 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753623</link><description>Hi Phil,&lt;br&gt;&lt;br&gt;Small typo in the first sentence: "I’ve been playing with  for a couple of weeks.", I believe you meant "factor" instead of "for".&lt;br&gt;&lt;br&gt;If you are interested in concatenative languages and the semantic web have you seen Ripple? &lt;a href="http://ripple.fortytwo.net/" rel="nofollow"&gt;http://ripple.fortytwo.net/&lt;/a&gt;&lt;br&gt;&lt;br&gt;There is also my own relatively immature language Cat (&lt;a href="http://www.cat-language.com" rel="nofollow"&gt;http://www.cat-language.com&lt;/a&gt;), which will be stable "real soon now".&lt;br&gt;&lt;br&gt;Cheers,&lt;br&gt;Christopher Diggins</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christopher Diggins</dc:creator><pubDate>Fri, 12 Oct 2007 16:21:52 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753622</link><description>I thought from the input format and the output that a Python list comprehension would be the way I'd solve it and came up with this:&lt;br&gt;&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; from pprint import pprint as pp&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; tabular = [["col1","col2","col3"],[["a","b","c"],["e","f","g"]]]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; triples = [(row[0], col[1], row[1][col[0]])  &lt;br&gt;  for row in enumerate(tabular[1]) &lt;br&gt;  for col in enumerate(tabular[0])]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; pp(triples)&lt;br&gt;[(0, 'col1', 'a'),&lt;br&gt; (0, 'col2', 'b'),&lt;br&gt; (0, 'col3', 'c'),&lt;br&gt; (1, 'col1', 'e'),&lt;br&gt; (1, 'col2', 'f'),&lt;br&gt; (1, 'col3', 'g')]&lt;br&gt;&amp;gt;&amp;gt;&amp;gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;(I added a couple of newlines to the list comprehension to get it into the comment box).&lt;br&gt;&lt;br&gt;If I were using it then I might wrap it in a function and add a docstring to test/explain it.&lt;br&gt;&lt;br&gt;- Paddy.</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">paddy3118</dc:creator><pubDate>Fri, 12 Oct 2007 00:55:43 -0000</pubDate></item><item><title>Re: More factor: tabular to triples</title><link>http://www.phildawes.net/blog/2007/10/11/more-factor-tabular-to-triples/#comment-2753620</link><description>Just for a laugh, here it is in Haskell. You can type this at the interpreter.&lt;br&gt;&lt;br&gt;let insertList x = map (insert x) where insert x (y,z) = (x,y,z)&lt;br&gt;&lt;br&gt;let cols = ["col1","col2","col3"]&lt;br&gt;&lt;br&gt;let rows = [["a","b","c"],["e","f","g"]]&lt;br&gt;&lt;br&gt;concat $ zipWith insertList [0..] $ map (zip cols) rows&lt;br&gt;&lt;br&gt;This prints [(0,"col1","a"),(0,"col2","b"),(0,"col3","c"),(1,"col1","e"),(1,"col2","f"),(1,"col3","g")]&lt;br&gt;&lt;br&gt;No preview available so I don't know if your blog software is going to mangle that!</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Neil Bartlett</dc:creator><pubDate>Thu, 11 Oct 2007 17:58:48 -0000</pubDate></item></channel></rss>