Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Real world Common Lisp

Name: Anonymous 2011-03-30 13:42

A simple Stardict client1 in python2, 21 lines with comments. How easy would it be to write an equivalent program in Common Lisp? I think Lisp is not suitable for practical problems.

import re, gzip, struct

idx_file = open('/usr/share/stardict/dic/quick_english-italian.idx', 'r').read()
dic = gzip.open('/usr/share/stardict/dic/quick_english-italian.dict.dz', 'r')

idx_re = r"([\w\W]+?)\x00([\w\W]{8})"

index = {word:struct.unpack('>ii', bytes)
          for (word, bytes) in re.findall(idx_re, idx_file)}

def lookup_word(word):
    if word not in index:
        return False
    pos, size = index[word]
    dic.seek(pos)
    result = dic.read(size)
    return result

while True:
    result = lookup_word(raw_input("Enter a word: "))
    print(result or "Word not found")


_________________
1 - https://github.com/xiangfu/stardict/blob/master/doc/StarDictFileFormat
2 - Requires python 2.7

Name: Anonymous 2011-04-01 12:38

>>57
http://norvig.com/python-lisp.html
Wow! Norvig sucks.


grammar =: '{sentence    -> (noun_phrase verb_phrase)
            ;noun_phrase -> (Article Noun)
            ;verb_phrase -> (Verb noun_phrase)
            ;Article     -> the a
            ;Noun        -> man ball woman table
            ;Verb        -> hit took saw liked}

generate [@p]        -> mappend generate p
        ;p:!rewrites -> generate p.rewrites.rand
        ;p           -> [p]

rewrites category -> grammar.{[@_ [!category '-> @rhs] @_]->rhs}


Now

($eval "generate 'sentence")
(the woman hit the ball)
NIL
($eval "generate 'sentence")
(a ball saw the woman)
NIL
($eval "generate 'sentence")
(a woman hit a ball)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List