Giter VIP home page Giter VIP logo

lisp-concepts-in-programming-languages-mitchell's Introduction

Pure Lisp Starter Pack

This repo contains the source codes in Part 1-3 (Lisp: Functions, Recursion, and Lists) of Concepts in Programming Languages By John C. Mitchell.

Plus:

  • an internal representation of lisp
  • a minimal cheat sheet of pure lisp commands

You can find the source codes in the codes directory.

Install Clisp

  • On Ubuntu/Debian: sudo apt install clisp
  • On Mac: brew install clisp
  • On Windows: Download

Internal Representation

Lisp lists are represented internally using a tree-like structure of nodes. Each node has two pointers, a left pointer and a right pointer. The left pointer points to a list element (which can be either an atom or another list) and the right pointer points to the remainder of the list.

internal representation of common lisp - cons cell in common lisp - lists in common lisp - atom in common lisp

Cheat Sheet

Form in Lisp:

A Lisp object that is intended to be evaluated is called a form (or an expression).

You can execute functions in lisp using this syntax:

(function_name_or_operator arg1 arg2 ...)
Function/Operator Description Example Output Output Type
cons create a new Cons Cell - - -
(cons atom list) (cons 1 '(2)) (1 2) List
(cons list atom) (cons '(2) 5) ((2) . 5) Cons Cell
(cons atom atom) (cons 1 2) (1 . 2) Cons Cell
(cons list list) (cons '(1 2) '(3)) ((1 2) 3) List
car returns first element of the list (car '(1 2)) 1 Atom
cdr returns everything after first element of list as a list (cdr '(1 2)) (2) List
eq returns T if equal else NIL (eq 2 2) T Atom
equal/eql/equalp Read here - - -
cond condition (cond (cond1 (exp)) (cond2 (exp)) ... (T (last))) - -
lambda Read here - - -
funcall/apply Read here - - -
quote Create a list (quote(1 2 3)) or '(1 2 3) (1 2 3) List
eval expects a form to be evaluated and executed as argument. (eval '(+ 1 2)) 3 depends on form
defun define function - - -
"+ - * / mod" mathematic operators (+ 1 2) 3 Atom
"< > = <= >=" boolean operators (< 2 5) T Atom
rplaca replaces the car of the cons with object (rplaca '(1 2) 5) (5 2) -
rplacd replaces the cdr of the cons with object - - -
(rplacd list atom) (rplacd '(1 2) 5) (1 . 5) Cons Cell
(rplacd list list) (rplacd '(1 2) '(4 5)) (1 4 5) List

lisp-concepts-in-programming-languages-mitchell's People

Contributors

danialkeimasi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.