Quick Guide to Lisp Implementation



Similar documents
Words Symbols Diagram. abcde. a + b + c + d + e

Chapter. Contents: A Constructing decimal numbers

The remaining two sides of the right triangle are called the legs of the right triangle.

Angles 2.1. Exercise Find the size of the lettered angles. Give reasons for your answers. a) b) c) Example

Maximum area of polygon

KEY SKILLS INFORMATION TECHNOLOGY Level 3. Question Paper. 29 January 9 February 2001

Graphs on Logarithmic and Semilogarithmic Paper

32. The Tangency Problem of Apollonius.

OxCORT v4 Quick Guide Revision Class Reports

The Cat in the Hat. by Dr. Seuss. A a. B b. A a. Rich Vocabulary. Learning Ab Rhyming

MATH PLACEMENT REVIEW GUIDE

1 GSW IPv4 Addressing

MA Lesson 16 Notes Summer 2016 Properties of Logarithms. Remember: A logarithm is an exponent! It behaves like an exponent!

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

Volumes by Cylindrical Shells: the Shell Method

1 Fractions from an advanced point of view

Enterprise Digital Signage Create a New Sign

Experiment 6: Friction

c b N/m 2 (0.120 m m 3 ), = J. W total = W a b + W b c 2.00

1. Definition, Basic concepts, Types 2. Addition and Subtraction of Matrices 3. Scalar Multiplication 4. Assignment and answer key 5.

Section 7-4 Translation of Axes

Algebra Review. How well do you remember your algebra?

Unit 6: Exponents and Radicals

Helicopter Theme and Variations

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Density Curve. Continuous Distributions. Continuous Distribution. Density Curve. Meaning of Area Under Curve. Meaning of Area Under Curve

The art of Paperarchitecture (PA). MANUAL

Integration by Substitution

Factoring Polynomials

End of term: TEST A. Year 4. Name Class Date. Complete the missing numbers in the sequences below.

Integration. 148 Chapter 7 Integration

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Module 5. Three-phase AC Circuits. Version 2 EE IIT, Kharagpur

Chapter. Fractions. Contents: A Representing fractions

WHAT HAPPENS WHEN YOU MIX COMPLEX NUMBERS WITH PRIME NUMBERS?

OUTLINE SYSTEM-ON-CHIP DESIGN. GETTING STARTED WITH VHDL August 31, 2015 GAJSKI S Y-CHART (1983) TOP-DOWN DESIGN (1)

Operations with Polynomials

Vectors. The magnitude of a vector is its length, which can be determined by Pythagoras Theorem. The magnitude of a is written as a.

McAfee Network Security Platform

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

Binary Representation of Numbers Autar Kaw

ELEVATION CERTIFICATE

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

LECTURE #05. Learning Objective. To describe the geometry in and around a unit cell in terms of directions and planes.

9 CONTINUOUS DISTRIBUTIONS

EQUATIONS OF LINES AND PLANES

Student Access to Virtual Desktops from personally owned Windows computers

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

AREA OF A SURFACE OF REVOLUTION

Lesson 2.1 Inductive Reasoning

If two triangles are perspective from a point, then they are also perspective from a line.

One Minute To Learn Programming: Finite Automata

4.5 Signal Flow Graphs

Lecture 3 Gaussian Probability Distribution

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

- DAY 1 - Website Design and Project Planning

LISTENING COMPREHENSION

SECTION 7-2 Law of Cosines

Arc-Consistency for Non-Binary Dynamic CSPs

50 MATHCOUNTS LECTURES (10) RATIOS, RATES, AND PROPORTIONS

Math 135 Circles and Completing the Square Examples

The Pythagorean Theorem

Warm-up for Differential Calculus

Introduction to Integration Part 2: The Definite Integral

Exponential and Logarithmic Functions

GENERAL OPERATING PRINCIPLES

Physics 43 Homework Set 9 Chapter 40 Key

SOLVING EQUATIONS BY FACTORING

Reasoning to Solve Equations and Inequalities

NQF Level: 2 US No: 7480

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

Released Assessment Questions, 2015 QUESTIONS

Vectors Recap of vectors

Homework 3 Solutions

Towards Zero-Overhead Static and Adaptive Indexing in Hadoop

MATH 150 HOMEWORK 4 SOLUTIONS

6.2 Volumes of Revolution: The Disk Method

Lesson 4.1 Triangle Sum Conjecture

BUSINESS OWNERS PACKAGE INSURANCE APPLICATION

P.3 Polynomials and Factoring. P.3 an 1. Polynomial STUDY TIP. Example 1 Writing Polynomials in Standard Form. What you should learn

Interior and exterior angles add up to 180. Level 5 exterior angle

Reinforced Concrete Design RECTANGULAR R/C CONCRETE BEAMS: TENSION STEEL ONLY

How To Set Up A Network For Your Business

Start Here. Quick Setup Guide. the machine and check the components. NOTE Not all models are available in all countries.

Cypress Creek High School IB Physics SL/AP Physics B MP2 Test 1 Newton s Laws. Name: SOLUTIONS Date: Period:

Welch Allyn CardioPerfect Workstation Installation Guide

Object Semantics Lecture 2

Math 314, Homework Assignment Prove that two nonvertical lines are perpendicular if and only if the product of their slopes is 1.

Practice Test 2. a. 12 kn b. 17 kn c. 13 kn d. 5.0 kn e. 49 kn

Active Directory Service

VMware Horizon FLEX Administration Guide

Lecture 3: orientation. Computer Animation

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

Transcription:

isp Implementtion Hndout Pge 1 o 10 Quik Guide to isp Implementtion Representtion o si dt strutures isp dt strutures re lled S-epressions. The representtion o n S-epression n e roken into two piees, the tg (whih stores tpe inormtion) nd the tul dt. There re two kinds o S- epression, toms nd lists. The s-epression r (the tom r) would e stored s: r With the '' tg signiing tht this is n tom (s opposed to list), nd the smol r eing the tul tom (in most lisp sstems, the string "r" would e stored somewhere else, nd the tom would just e pointer to tht lotion, ut to keep things simple we will ssume tht the string n e stored in the dt setion o the lisp dt struture) Sine lisp stores everthing s pointers, the tom r would rell e pointer to the ove dt struture. r ists re uilt up using list struture tht hs two pointers pointer to the irst element o the list, nd pointer to the rest o the list. So, the list ( ) would e represented the ollowing: et's get little more omplited, nd look t lists inside o lists. For emple, the representtion o the s- epression ( ( ) ()) is

isp Implementtion Hndout Pge 2 o 10 ist within ists within ists Here re even more emples o lists tht ontin lists, inluding the empt list: ( ()) ( ( ( d) e) ( ) ( ) ) e d Our Friend Rell tht '<sepr> is just shorthnd or ( <sepr>), so tht ' is shorthnd or ( ) nd '( ) is shorthnd or ( ( )) Hene, the internl representtion o ' is the internl representtion o ( ), whih is:

isp Implementtion Hndout Pge 3 o 10 ikewise, the internl representtion o '( ) is the sme s the internl representtion o ( ( )), whih is: Red-Evl-Print loop The lisp interpreter is elegnt in its simpliit. n s-epression is red in (nd onverted to the internl representtion), evluted, nd the result is printed out. So, it the user tped in: ( ' '( )) First, the interpreter would onvert this s-epression to the pproprite internl representtion [ rememer tht ( ' '( )) is shorthnd or ( ( ) ( ( ))) ] : Net, the epression is evluted. Sine the epression is list, the interpreter irst looks t the irst element o the list (whih is ) to see i it is vlid untion nme. Sine is vlid untion nme, eh o the rguments to re evluted. The 2 rguments to re the 2 nd nd 3 rd elements o the list, whih re:

isp Implementtion Hndout Pge 4 o 10 nd Tking the irst rgument irst, this is list. whih mens it is untion ll. Chek the irst element o the list to mke sure tht it is vlid untion nme nd is vlid single rgument untion nme. We re lling with single rgument, so we re OK so r. Quote is speil untion tht returns its rgument unevluted. So, this ll to will return its one rgument (the seond element o the list) whih is: OK, so now we evlute the seond rgument to, whih is list, whih mens untion ll. First, hek the irst element o the list (the tom ), whih is vlid untion nme. The untion returns its single rgument (the seond element in the list) unevluted, to get: So, we n ll, with the ove two rguments. Cons retes new list element, sets the r equl to the irst element nd the dr equl to the seond element, to get:

isp Implementtion Hndout Pge 5 o 10 Finll, the interpreter prints out the result, whih is ( ). Getting new memor the ree list How do we get new memor lotion when we need one? When is lled, where does tht memor lotion ome rom? ll ville memor is stored in ree list. The ree list is list o memor lotions tht re ville. This list is little dierent thn stndrd lisp list, like ( ). To store the list ( ), we need spe or the three toms,, nd, s well s 3 list truts to glue everthing together. It seems wste to use 6 memor lotions to store 3 memor lotions or ree list, so we will use slightl dierent method. The ree list pointer will point to the irst element o the ree list, nd the r o tht element will point to the net element in the ree list, nd so on. So, the ree list might look something like: Free ist n time new piee o memor is needed, the irst element o the ree list is used, nd the ree list pointer is dvned. Memor lotion to use or, et Free ist O ourse, eventull we re going to run out o memor. Wht hppens then? The interpreter will do mrk nd sweep grge olletion. Ever piee o memor tht is urrentl eing used is mrked. Then the interpreter does sweep through memor, dding ever unmrked element to the ree list. Then the ree list should no longer e empt, nd the interpreter will ontinue. et's emine omplete emple. Consider the untion : (deun ( ) ( ( ( ( ))))) et's s the ree list looks like the ollowing:

isp Implementtion Hndout Pge 6 o 10 Free ist nd we mke the untion ll ( ' ' ') [whih is shorthnd or ( ( ) ( ) ( )) ] The ll ( ' ' ') is irst red into memor: Free ist Evl. ep Now we hve to evlute the epression. "" is untion tht hs een deined, so we evlute eh o the rguments, ple them on the stk, then ll the untion: Free ist Evl. ep The irst rgument is ( ), whih evlutes to, the seond rgument is ( ), whih evlutes to, nd the third rgument is ( ), whih evlutes to

isp Implementtion Hndout Pge 7 o 10 Now we ll the untion. Tht untion returns o two rguments: Free ist Evl. ep The irst rgument is, ut the seond rgument is nother, whih needs to e evluted (the rther lrge grphil spe lloted or the irst on the stk is merel to mke the pointers esier to see) The irst rgument to this is, ut the seond rgument is nother Free ist Evl. ep

isp Implementtion Hndout Pge 8 o 10 The rguments to this re nd () : Free ist Evl. ep Now tht we hve evluted the rguments or the inl, we n eeute the untion od. Cons tkes new piee o memor rom the ree list, opies the irst rgument into the r nd the seond rgument into the dr, nd returns this lok o memor, whih is used s the seond rgument to the seond : Free ist Evl. ep

isp Implementtion Hndout Pge 9 o 10 Now tht we hve evluted oth rguments or the seond, we n eeute the untion od. Cons tkes new memor lotion o the ree list ut the ree list is empt! So, we need to do grge olletion step. First we go through the stk nd mrk ever piee o memor tht is rehle rom some pointer on the stk, s ollows: Free ist Evl. ep O ourse, eh memor lotion will need to hve n etr it reserved to store these mrks. Now, we sweep through memor, dding everthing tht is not mrked to the ree list (we might s well lso ler the mrks on this pss, to e red or the net time we wnt to do grge olletion). Free ist Evl. ep

isp Implementtion Hndout Pge 10 o 10 Now the ree list is no longer empt, so we n inish the ll to the seond : Free ist Evl. ep Finll, we n omplete the ll to the irst, nd return tht vlue (whew!) Free ist Evl. ep Now we n print out the vlue o the epression, whih is ( ), s epeted. Note tht now the ree list is gin empt, nd there is whole lot o grge. The net time we wnt to evlute n epression, we will need to run mrk-nd-sweep grge olletion gin, to ree up some more memor.