~oubiwann/graph-lisp/pylisp-ng-fork

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
========
Features
========

* A tiny Lisp dialect, easy to integrate into other Python projects.

* Includes an interactive Lisp interpreter.

* Expression introspection specifically designed for use in genetic
  programming.


============
Introduction
============

pyLisp-NG is an immediate descendant of PyLisp, which had its accidental birth
as a result of William Annis' desire to build a CLIPS-like [#]_ syntax for a
simple expert system intended for the monitoring tool, Mom. As a result of Lisp
interest on the Python news group [#]_, William released the software and
announced it to the group [#]_.

Several years later, the Evolver [#]_ and txEvolver [#]_ projects needed a
functional programming language implementation in Python, as inspecting
Python's AST was too much of a hassle. The author wanted to distribute,
process, and manage evolutionary algorithms/programs across multiple remote
Twisted servers, and manipulating permutations of partial programs was much
easier to integrate with Twisted if the programs themselves could be evaluated
and introspected easily with Python. PyLisp was eventually chosen to meet this
need, and in pyLisp-NG we have several new features and improvements.

pyLisp-NG inherits PyLisp's idiosyncratic characteristics. For example, the
booleans are true and false and it doesn't follow the convention that
everything that isn't false is true (common to many Lisps). In fact, all
booleans in pyLisp-NG are based on fuzzy logic, so you can do trickier things.
Macros are, quite strangely, first class objects in PyLisp which maybe novel to
Lisps [#]_::

    lisp> (setq foo 22)
    22
    lisp> ((macro (x) `(setq ,x (+ ,x 1))) foo)
    23

pyLisp-NG, like its predecessor, has no intent of becoming a full-fledged,
robust Lisp implementation. All progress is governed solely by the interest of
contributing developers; right now, that's strictly for use as a genetic
programming tool.


============
Installation
============

pyLisp-NG is setuptools-friendly; you can install it with the following:

  $ easy_install pyLisp-NG

You can also get the full source code from Launchpad:

  $ bzr lp:pylisp-ng

The latter option greatly encouraged for interested users, as the repository
contains extra files that are not included in the distribution tarballs (such as
the test runner and test utils).


=====
Usage
=====

To use the interpreter from a full checkout, do this:

    $ cd <branch directory>
    $ ./bin/pylisp-ng

If you've installed with easy_install, and your Python scripts directory is in
your PATH, all you'll need to do is this:

    $ pylisp-ng

At this point, you'll be able to enter Lisp expressions::

    lisp> ((lambda (x) (* x x)) 2)
    4
    lisp>

You can use the s-expression code from Python::

    >>> from pylispng import sexpr
    >>> l = sexpr.SExpression('((lambda (x) (* x x)) 2)')
    >>> str(l)
    '((lambda (x) (* x x)) 2)'
    >>> number = l.eval()
    >>> number
    <number 4>
    >>> number.value
    4

Building an expression one symbol at a time or by adding chunks at a time::

    >>> l = sexpr.SExpression()
    >>> l.append('+')
    >>> l.append('3')
    >>> l.append('5')
    >>> l.append('(* 3 3)')
    >>> str(l)
    '(+ 3 5 (* 3 3))'

You can examine various properties of the s-expression::

    >>> l.eval().value
    17
    >>> l.getDepth()
    2
    >>> len(l)
    4
    >>> l.getSize()
    2