<div><div><div class="gmail_quote">On Sat, Jun 4, 2011 at 12:50, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org">eli@barzilay.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">11 hours ago, Rodolfo Carvalho wrote:<br>
><br>
</div><div class="im">> Imagine an scenario that instead of 2 (as above) we had 20 columns<br>
> of a table, and we wanted to return a table of the squares of the<br>
> values for all columns, except for columns 12 and 15 (of course we<br>
> could parse them out and ignore then when processing/returning, but<br>
> you get the idea...)<br>
<br>
</div>A classical mistake that people do when they start playing with<br>
regexps is they forget about the rest of the language and try to do<br>
too much with regexps. If you have a table with more than 2 numbers,<br>
I'd do it like this:<br>
<br>
(define t "<br>
23 12 72367 2772 7272 7777 2.342<br>
15 45 1e2 1e3 1e4<br>
32 27 3.1415926")<br>
<br>
(map (λ(l) (map string->number (regexp-match* #px"\\d+" l)))<br>
(regexp-split #rx"\n" t))<br></blockquote><div><br></div><div><br></div><div>This fails to read "2.342", "1e4" ...</div><div><br></div><div><div><br></div><div>Following your advice and the piece of code above, I wrote it like this:</div>
</div><div><br></div><div><div>;; Split lines, match numbers and filter-out invalid lines</div><div>(define parsed-data</div><div> (filter</div><div> (λ (l) (> (length l) 1))</div><div> (map (λ (l)</div><div> (map string->number (regexp-match* #px"\\b[\\d.e+]+\\b" l)))</div>
<div> (regexp-split #rx"\n" t))))</div><div><br></div><div>;; Sort by Gflops, convert back to string, attach header and display</div><div>(displayln (string-join</div><div> (cons</div><div> "N<span class="Apple-tab-span" style="white-space:pre"> </span>NB<span class="Apple-tab-span" style="white-space:pre"> </span>P<span class="Apple-tab-span" style="white-space:pre"> </span>Q<span class="Apple-tab-span" style="white-space:pre"> </span>Time<span class="Apple-tab-span" style="white-space:pre"> </span>Gflops"</div>
<div> (map (λ (row) (string-join (map number->string row) "\t"))</div><div> (sort parsed-data</div><div> ></div><div> #:key last</div>
<div> #:cache-keys? #t)))</div><div> "\n"))</div></div><div><br></div><div><br></div><div>[]'s</div><div><br></div><div>Rodolfo</div><div><br></div></div></div></div>