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: not >>39 2011-03-31 10:57

>>40
You have go(to)'s and all kinds of local/non-local exit stuff, along with various options for stack unwinding. TCO is nice, but not absolutely needed. Most implementations provide it.

Name: Anonymous 2011-03-31 11:03

>>41
I can live with go as replacement. I was referring to iterate vs loop in >>40, though.

Name: Anonymous 2011-03-31 11:29

>>18
It's not about me, it's about facts. And it remains a fact until you actually prove it otherwise. With code.
How cute, you believe that something happens to the facts when you subjectively experience a proof.

Name: Anonymous 2011-03-31 11:41

>>18
it's about facts.

(define (facts m)
  (do ((n 1 (add1 n))
       (x 1 (* n x))
       (r '() (cons x r)))
    ((= n m) (reverse r))))

Name: Anonymous 2011-03-31 12:35

Bampu

Name: Anonymous 2011-03-31 13:05

Lithp ith for huge faggotth.

Name: Anonymous 2011-03-31 13:39

>>46
Thuth the fuck up, thupid cockthucker.

Name: Anonymous 2011-03-31 16:13

>>47
Truth hurtth.

Name: Anonymous 2011-03-31 16:20

>>48
You're a faggot, faggot.

Name: Anonymous 2011-03-31 16:26

>>46,48
HAHAHAHA
YOU THINK YOURE THOUGH UH ?
I HAVE ONE WORD FOR YOU
 THE FORCED INDENTATION OF THE CODE
GET IT ?
I DONT THINK SO
YOU DONT KNOW ABOUT MY OTHER CAR I GUESS ?
ITS A CDR
AND IS PRONOUNCED ``CUDDER''
OK YOU FUQIN ANGERED AN EXPERT PROGRAMMER
THIS IS /prog/
YOU ARE ALLOWED TO POST HERE ONLY IF YOU HAVE ACHIEVED SATORI
PROGRAMMING IS ALL ABOUT ``ABSTRACT BULLSHITE'' THAT YOU WILL NEVER COMPREHEND
I HAVE READ SICP
IF ITS NOT DONE YOU HAVE TO
TOO BAD RUBY ON RAILS IS SLOW AS FUCK
BBCODE AND ((SCHEME)) ARE THE ULTIMATE LANGUAGES
ALSO
WELCOME TO /prog/
EVERY THREAD WILL BE REPLIED TO
NO EXCEPTION

Name: Anonymous 2011-03-31 16:53

>>50
autistic faggot detected

Name: Anonymous 2011-03-31 17:30

>>51
go fuck and autistic nigger

Name: Anonymous 2011-04-01 5:32

50+ posts and still not a single Common Lisp implementation was posted. Something that takes only 20min to write in Python can't be reproduced in Lisp for more than a day! Common Lisp and its fans are pathetic.

Name: Anonymous 2011-04-01 5:42

>>53
I'm too busy doing real work to bother implementing your toy dict lookup. If I were to implement it, it'd be slightly smaller than >>9's scheme implementation.

Name: Anonymous 2011-04-01 5:51

It's funny how >>54 almost implies that he is the only CLisper on this board.

Name: Anonymous 2011-04-01 5:52

>>53

You used 20 minutes on that?

Name: Anonymous 2011-04-01 9:50

>>55
That's because most CLispers now CLisp in Python:
http://norvig.com/python-lisp.html

>>54 just trying to show us, that he is a white crow.

Name: Anonymous 2011-04-01 9:51

Python can be seen as a dialect of Lisp
you see?

Name: Anonymous 2011-04-01 10:22

Ignore troll posts.

Name: Anonymous 2011-04-01 10:39

>>58
APL can be seen as a dialect of Chinese.

Name: Anonymous 2011-04-01 10:40

>>60
Perl 6 can be seen as a dialect of APL.

Name: Anonymous 2011-04-01 10:48

Chinese can be seen as dialect of autism.

Name: Anonymous 2011-04-01 10:57

>>62
Thinking of it, symbolic communication is inherently a dialect of autistic savants. We should go back to grunts and growls.

Name: Anonymous 2011-04-01 11:03

The only real "autism dialect" is Lojban. Everything else is amateur scribbles and incoherent imitations.

Name: Anonymous 2011-04-01 11:44

>>64
confirmed. i learned lojbn ND GOT AUTISM  IN 4 DAYS

Name: Anonymous 2011-04-01 11:49

>>64
Extremely synthetic Ithkuil is much more precise and concise, which proves that analtic languages are inferior.

Name: Anonymous 2011-04-01 12:00

a fluent speaker of Ithkuil, accordingly, would think “about five or six times as fast” as a speaker of a typical natural language.

Name: Anonymous 2011-04-01 12:12

>>67
Ok, thinking very fast but having no ability to communicate with others. Maximal autism.

Name: Anonymous 2011-04-01 12:16

>>67
WRONG! Visual representation of ideas, which is typical of HFA spectrum, is faster and more precise. Ithkuil only reduces the semantic noise, which makes faster writing and speaking, thinking with same lexemes does not magically become faster.
What you are thinking of is verbalization speed. You can train faster reading and verbalization skills with speed reading without any Ithkuil.
c.f. http://en.wikipedia.org/wiki/Speed_reading

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)

Name: Anonymous 2011-04-01 12:38

Name: Anonymous 2011-04-01 12:39

>>70

from random import choice

def Dict(**args): return args

grammar = Dict(
        S = [['NP','VP']],
        NP = [['Art', 'N']],
        VP = [['V', 'NP']],
        Art = ['the', 'a'],
        N = ['man', 'ball', 'woman', 'table'],
        V = ['hit', 'took', 'saw', 'liked']
        )

def generate(phrase):
    "Generate a random sentence or phrase"
    if isinstance(phrase, list):
        return mappend(generate, phrase)
    elif phrase in grammar:
        return generate(choice(grammar[phrase]))
    else: return [phrase]



>>> generate('S')
['the', 'man', 'saw', 'the', 'table']

>>> ' '.join(generate('S'))
'the man saw the table'

Name: Anonymous 2011-04-01 12:41

>>70
http://norvig.com/python-lisp.html

Did he bloat the Lisp code on purpose or what?

Name: Anonymous 2011-04-01 13:07

>>72

(define grunnur
  '((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)))

(define (list-ref/random l)
  (list-ref l (random (length l))))

(define (generate phrase)
  (cond ((list? phrase)
         (append-map generate phrase))
        ((assq phrase grunnur)
         => (compose generate list-ref/random cdr))
        (else (list phrase))))

Name: Anonymous 2011-04-01 13:28

>>74
Beautiful!

Name: Anonymous 2011-04-01 21:02

Long live /prog/!

Name: Anonymous 2011-04-01 21:03

Long live /prog/!

Name: Anonymous 2011-04-01 21:05

/prog/ is dead

Name: Anonymous 2011-04-01 21:06

/prog/ is dead

Name: Anonymous 2011-04-01 21:08

/prog/ is dead

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