Skip to main content

A very simple implementation of Lisp in Python that is perfectly suitable for Python projects needing Lisp-like capabilities.

Project description

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 [1] syntax for a simple expert system intended for the monitoring tool, Mom. As a result of Lisp interest on the Python news group [2], William released the software and announced it to the group [3].

Several years later, the Evolver [4] and txEvolver [5] 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-NG inherits PyLisp’s idiosyncratic charaateristics. 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 [6]:

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

pyLisp-NG, like its predecessor, has no intent of becomming 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 ditribution tarballs (such as the test runner and test utils).

Usage

To use the interpretter 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 lisp
>>> l = lisp.SExpression('((lambda (x) (* x x)) 2)')
>>> str(l)
'((lambda (x) (* x x)) 2)'
>>> l.eval()
4

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

>>> l = lisp.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()
17
>>> l.getDepth()
2
>>> len(l)
4
>>> l.getSize()
2

Known Bugs

None currently known.

TODO

  • support testing .l files

  • support lisp interpreter tests in doctests?

  • add http://www.biostat.wisc.edu/~annis/creations/PyLisp/tests.txt to tests

  • split up monolithic lisp.py file into separate files

  • replace fragile interpreter that originally came with PyLisp with one based on the Python interpreter

    • graceful quit

    • command history

    • auto-completion

  • add support for getting expressions by index (and thus slicing as well)

  • add support for getting sub-expressions

Changes

From PyLisp 1.17 to 2.0.0 (pyLisp-NG)

  • Added introspection code that’s useful for genetic programming.

  • A couple small bug fixes and some code cleanup.

From PyLisp 0.0 to 1.17

There doesn’t seem to be any history from which to extract code changes between previous versions and 1.17.

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyLisp-NG-2.0.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distributions

pyLisp_NG-2.0.0-py2.5.egg (53.0 kB view details)

Uploaded Source

pyLisp_NG-2.0.0-py2.4.egg (53.7 kB view details)

Uploaded Source

File details

Details for the file pyLisp-NG-2.0.0.tar.gz.

File metadata

  • Download URL: pyLisp-NG-2.0.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyLisp-NG-2.0.0.tar.gz
Algorithm Hash digest
SHA256 d14dee540c78d2b2a21ccfe09b1e9bab86cd060451545946555eb2ccbf9735d5
MD5 84141318cde6bf4e4f10ac4a920531be
BLAKE2b-256 a28800b7100011f7fde00ad590dc6c6e64aa936a0d9b7152f97597c96f105f2e

See more details on using hashes here.

File details

Details for the file pyLisp_NG-2.0.0-py2.5.egg.

File metadata

File hashes

Hashes for pyLisp_NG-2.0.0-py2.5.egg
Algorithm Hash digest
SHA256 36a063149df76a87098a3eaf139546498eaaa3b26835d276ba2d4086de1408ff
MD5 4b6fb5e6b5879dabac2e7fbd5da7236d
BLAKE2b-256 6eb6e5ec8588b86f7b0cdb172bc5287f22cb0ed3acef52da9806921e7b063046

See more details on using hashes here.

File details

Details for the file pyLisp_NG-2.0.0-py2.4.egg.

File metadata

File hashes

Hashes for pyLisp_NG-2.0.0-py2.4.egg
Algorithm Hash digest
SHA256 f58d8381d666166c8f05105efad48e13c8605a8fc17338fd42cece84b7d91c15
MD5 e341de022b25121b49a68398a4f94c4c
BLAKE2b-256 9115e2e3eba8a206b3db60c5a98daccfd0c30a14d0d9449bdc06ce24ce239c29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page