What do you want to contribute?
Geoff Canyon
gcanyon at gmail.com
Mon Feb 18 01:13:45 EST 2013
Here's an interesting real(ish) world example:
http://www.leancrew.com/all-this/2011/12/more-shell-less-egg/
The goal is to find the ten most common words in a text file.
Donald Knuth wrote something in literate code form, in Pascal. The result
was ten pages of code. In the article, Doug McIlroy wrote it in shell
script as:
1 tr -cs A-Za-z '\n' |2 tr A-Z a-z |3 sort |4 uniq -c |5 sort -rn
|6 sed ${1}q
and called out Knuth on his supposedly more clear, ten-page solution.
It turns out six lines of transcript accomplishes the same thing:
repeat for each word w in replacetext(url ("file:" &
filePath),"(?i)[^a-z]"," ")
add 1 to c[w]
end repeat
combine c using cr and comma
sort lines of c descending numeric by item 2 of each
put line 1 to 10 of c
If anyone can do it more elegantly, I'm curious to know how. But in a
language where we can write our own syntax, this seems likely to be
possible:
put file filePath with all non-alphabetic characters replaced with space
into fileString
for each unique word w in fileString, put w,the count of w & cr after
countList
put the first 10 lines of countList sorted numeric descending by item 2
Maybe that's not clearer, but it should be possible.
On Thu, Feb 14, 2013 at 4:14 PM, Geoff Canyon <gcanyon at gmail.com> wrote:
>
> On Thu, Feb 14, 2013 at 2:08 PM, Monte Goulding <
> monte at sweattechnologies.com> wrote:
>
>> In my example I used "each line OF x" rather than "each line IN x". I
>> often get caught on repeat for each line X IN y when I write OF. Could I
>> add OF to the repeat syntax so it didn't matter? It seems natural to me
>> either way. If not then perhaps our syntax should be:
>>
>> trim each line in X
>>
>
>
> The impression I got was that the new language ability would make it
> fairly simple (or at least possible) to allow for either of or in. I'm
> right there with you -- I don't actually code that often anymore, but
> nearly every time I do, I mix up of and in. In my perfect world the
> prepositions would be interchangeable and likely not significant, so of,
> in, through, across, within, and maybe others.
>
> gc
>
More information about the use-livecode
mailing list