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 21:09

Long live /prog/!

Name: Anonymous 2011-04-01 21:11

/prog/ is dead

Name: Anonymous 2011-04-01 21:13

/prog/ is dead

Name: Anonymous 2011-04-01 21:14

Long live /prog/!

Name: Anonymous 2011-04-01 21:16

Long live /prog/!

Name: Anonymous 2011-04-01 21:17

/prog/ is dead

Name: Anonymous 2011-04-01 21:19

Long live /prog/!

Name: Anonymous 2011-04-01 21:21

/prog/ is dead

Name: Anonymous 2011-04-01 21:22

Long live /prog/!

Name: Anonymous 2011-04-01 21:24

/prog/ is dead

Name: Anonymous 2011-04-01 21:25

/prog/ is dead

Name: Anonymous 2011-04-01 21:27

Long live /prog/!

Name: Anonymous 2011-04-01 21:29

/prog/ is dead

Name: Anonymous 2011-04-01 21:30

Long live /prog/!

Name: Anonymous 2011-04-01 21:32

/prog/ is dead

Name: Anonymous 2011-04-01 21:33

Long live /prog/!

Name: Anonymous 2011-04-01 21:35

/prog/ is dead

Name: Anonymous 2011-04-01 21:37

Long live /prog/!

Name: Anonymous 2011-04-01 21:38

Long live /prog/!

Name: Anonymous 2011-04-01 21:40

Long live /prog/!

Name: Anonymous 2011-04-01 21:41

/prog/ is dead

Name: Anonymous 2011-04-01 21:43

/prog/ is dead

Name: Anonymous 2011-04-04 5:12

>>54
it'd be slightly smaller than
No it wouldn't be smaller. The cited version uses integer-bytes->integer function and Common Lisp lacks it.

Name: Anonymous 2011-04-04 5:20

>>103
He uses some non-portable FFI to cast a buffer to an integer. I wrote my own portable implementation of this last time I needed to write a similar binary data parser, and I've also used a portable floats implementation as well (on SBCL, I have a conditional reader macro which implements this a lot more efficiently using only 1-2 assembly instructions, it's also possible to use the FFI to do it more efficiently, but I have yet to try).

Name: Anonymous 2011-04-04 12:52

>>103
It's trivial to implement if you've got bytevectors/bytestrings and know how integers are stored in memory and the difference between signed/unsigned, big/little endian. (read: basic knowledge).

Let's say it's left as an exercise for the reader.

>>104
Not exactly FFI, but implementation dependent, true.

Name: Anonymous 2011-06-16 6:06

Lisp can only be useful with tons of FFI code for everything...

Name: Anonymous 2011-08-14 2:51

C++ can only be useful with tons of external libraries for everything.

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