Skip to main content

Emulate basic Lisp environment in python for educational reasons.

Project description

Lisp Emulator - Version 1.0.2
-----------------------------
About Lisp
--------------
Lisp is a functional programming language, first introduced in
the end of the 1950's, by John Mcarthy, who was a renowned computer
scientist. Since then, many dozens of dialects of lisp have been developed.
The main dialects of nowadays are Common Lisp and Scheme.

About the project
------------------
The project focuses on emulating a very basic environment of an environment
which resembles common-lisp syntax and other compatiable older versions.
All of the code is written in python.

List of all of the basic methods which is introduced in the release:
Side Notes:
-------------
-Lisp is written in a prefix notation, and the code is inside
paranthesis.
- Like Lisp, this implementation isn't case sensitive.

Arithmetic Operators
------------------------
+ , - , * , / - Addition, Subtraction, Multiplication, Division
Those operators can receive an "infinite" number of parameters.
Examples:
>>> ( + 5 6 8 )
19
>>> ( - 8 2 1 )
5
>>> ( + 6 4 ( - 5 2 ) )
13
>>> ( * 7 3 )
21
>>> ( / 6 2 )
3

Output
-----------------
PRINT or WRITE, for example:

>>> ( print "hello" )
"HELLO"

Predicates
---------------------
predicates return a boolean-like value - T ( for true )
, and NIL ( the equivalent of false ).

ZEROP - evaluates to T if the number is 0, else to NIL
EVENP - evaluates to T if the number is odd, else to NIL
ODDP - evaluates to T if the number is even, else to NIL
LESSP - evaluates to T if the first value is smaller than the other
GREATERP - evaluates to T if the first value is bigger than the other
NUMBERP - evaluates to T if the value is a number, else to NIL
STRINGP - evaluates to T if the value is string ( by the double quotation ".." mark )
else, to NIL

Equality Operation
-----------------------------
Equality can be performed via the = operator that can receive
an indefinite number of parameters or the EQ method that receives only 2 parameters.
Those methods return T if all the expressions are equal, else NIL.

Mathematical Operations And Constants
---------------------------
PI Constant - PI is a global constant, and represents
approximately 3.1415926535.
E Constant - E is a global constant, and represents approximately
2.71828182846.

Trigonometric operations - handled in radians
-----------------------------------------------
SIN- receives a parameter and returns its sine

for example:
>>> ( sin ( / PI 2 ) )
1.0

COS - receives a parameter and returns its cosine

TAN - receives a parameter and returns its tangent

ASIN - The reverse operation of SIN.
receives a parameter within range of -1 and 1 and
returns the angle that its sine equals to the parameter (in radians)

ACOS - The reverse operation of COS.
receives a parameter within range of -1 and 1 and
returns the angle that its cosine equals to the parameter (in radians)

ATAN- The reverse operation of TAN.
receives a parameter within range of -1 and 1 and
returns the angle that the result of its tangent operation equals to the parameter (in radians)

SINH - Hyperbolic sine
COSH - Hyperbolic cosine
TANH - Hyperbolic tangent
ASINH - The reverse operation of SINH
ACOSH - The reverse operation of COSH
ATANH - The reverse operation of TANH

Other mathematical operations
----------------------------------
SQRT - receives a parameter and returns its square root
EXPT - receives two parameters and returns the power of the first
parameter by the second.
EXP - receives one parameter and returns the
power of E ( 2.71828182846 ) by that number.
MAX - receives N parameters and return the value of the biggest.
MIN - receives N parameters and return the value of the smallest.
GCD - receives N parameters and returns their Greatest Common
Denominator Operation.
ABS - receives a parameter, and returns its absolute value.

Creating Variables
--------------------------------
You can define new variables via the SET and SETQ methods
( defvar, defparameter are not implemented yet )

for example:

>>> ( setq number 5 )
5
>>> ( + 3 number 4 )
12

Conditionals
---------------------------
Conditions are created via IF expressions

String Operations
--------------------------------------
Concatenate - receives N strings and evaluates to their concatenation.
For example,

DATA TYPES
-----------------------
str - strings. A sequence of characters, sorrounded by double quotes.
for example: "hello" , "world".
int - integers. for example: 6, -3 ,2.
dec - decimal numbers

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

lisp_emulator-1.0.3.tar.gz (14.3 kB view hashes)

Uploaded Source

Built Distribution

lisp_emulator-1.0.3-py3-none-any.whl (12.6 kB view hashes)

Uploaded Python 3

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