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

Lisp Vs. Python

Name: Anonymous 2012-11-27 21:29

I am looking to learn another programming language, I am a bit of a newbie but I know C, Java, and C++ rather well and am looking to expand.

I am interested in AI so I am considering Lisp.
But I also hear python is on the rise so I am considering that.

Which should I choose and why?

Name: Anonymous 2012-11-28 10:46

Symta (LISP-based language):

Grammar = split “|” «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:xs?=mapc r P; P:rewrites=P,pick,r; P=P
rewrites Category = Grammar|c:[@_ [(Category) “=” @RHS] @_] RHS


Python:

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]
   
def generate_tree(phrase):
    """Generate a random sentence or phrase,
     with a complete parse tree."""
    if isinstance(phrase, list):
        return map(generate_tree, phrase)
    elif phrase in grammar:
        return [phrase] + generate_tree(choice(grammar[phrase]))
    else: return [phrase]

def mappend(fn, list):
    "Append the results of calling fn on each element of list."
    return reduce(lambda x,y: x+y, map(fn, list))

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

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

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