A Lisp Machine with Very Compact Programs

Total Page:16

File Type:pdf, Size:1020Kb

A Lisp Machine with Very Compact Programs Session 25 Hardware and Software for Artificial Intelligence A LISP MACHINE WITH VERY COMPACT PROGRAMS L. Peter Deutsch Xerox corporation, Palo Alto Research center (PARC) Palo Alto, California 94304 Abstract Data Types This paper presents a machine designed for LISP has many data types (e.g. list, compact representation and rapid execution symbolic atom, integer) but no declarations. of LISP programs. The machine language is a The usual implementation of languages with factor of 2 to 5 more compact than this property affixes a tag to each datum to S-expressions or conventional compiled code, indicate its type, in LISP, however, the , and the.compiler is extremely simple. The vast majority of data are pointers to lists encoding scheme is potentially applicable to or atoms, and it would be wasteful to leave data as well as program. The machine also room for a full word plus tag (the space provides for user-defined data structures. needed for an integer datum, for example) in every place where a datum can appear such as Introduction the CAR and CDR of list cells. Consequently, in BBN-LISP every datum is a Pew existing computers permit convenient or pointer; integers, strings, etc. are all efficient implementation of dynamic storage referenced indirectly. Storage is allocated in quanta, and each quantum holds data of allocation, recursive procedures, or only one type, so what type of object a operations on data whose type is represented given pointer references is just a function explicitly at run time rather than of the object's address, i.e. the pointer determined at compile time. This mismatch itself. between machine and language design plagues every implementor of languages designed for manipulation of structured information. The chief drawback of this scheme is that Neither of the usual software solutions to every built-in function which produces a this problem is entirely satisfactory. number as a result (such as PLUS, the Interpretive systems are easy to build and addition function) must allocate a word to flexible, but intrinsically inefficient; hold the result. This leads to frequent, compilers which approach the efficiency of time-consuming garbage collections. those for conventional languages are hard to BBN-LISP circumvents this problem for the write and often force the implementor (and most part by permanently storing all the user) to sacrifice valuable but expensive integers from -1536 to +1535 in consecutive language features for the sake of cells and just returning a pointer to one of efficiency. On many machines compiled code these cells if a numerical result is in this also occupies at least as much space as a range, rather than allocating a new cell. structured representation of the source In MicroLISP, which is intended as a program. reasonably efficient numerical language, data on the stack (temporary results and An alternative approach to this problem is variable bindings) carry a type tag to design machines whose code structure more identifying them as integers, floating point closely resembles that of their major numbers, or pointers. In this way, long programming language(s). This approach of numerical calculations can take place tailoring the machine to the language was without any consumption of allocated space. first used in the Burroughs B5000 and successor machines, which were designed to No existing LISP system permits the user to execute ALGOL 60 programs.' In recent years, define his own packed data structures. the availability of microprogrammed MicroLISP includes such a facility, since it processors and the continuing decline in the can be made inexpensive when implemented in cost of processor hardware and design have the machine language and since its absence prompted several experiments of this sort at from LISP is one of the reasons most universities* and at least one successful frequently cited for choosing other experiment by a large company* and one languages for complex symbolic computation. unsuccessful new commercial venture.3 The details are presented in Appendix A, since they are somewhat peripheral to the The present paper describes a machine design rest of this paper. It is worth noting that for efficient representation and execution the scheme could be implemented within of BBN-LISP programs. BBN-LISP is an BBN-LISP and even lends itself to efficient interactive system developed from the Lisp compilation in the usual case. language.* 10 Readers unfamiliar with LISP should consult weissman's excellent primer5; Control and Binding Structure some details particular to BBN-LISP appear in the next sections of this paper. A MicroLISP uses a single stack structure for both control and variable bindings, complete and well-maintained but voluminous 1 reference manual for BBN-LISP is also essentially as described in a recent paper. available." The machine design presented A function call allocates a "basic frame" here will be referred to as MicroLISP, a for the arguments and a "frame extension" name intended to connote both code for control information and temporary compactness and possible microprogrammed values* The basic frame contains the implementation. function name, the argument values 697 (bindings), and a pointer to the argument In both BBN-LISP and MicroLISP, all variable names. The frame extension holds a pointer bindings appear in the basic frame. In to the caller's frame extension and a BBN-LISP half of each word in the basic variety of other bookkeeping information. frame is reserved for the name, In The FUNARG capability of LISP 1.5, i.e. the MicroLISP, the basic frame contains a single ability to construct a data object pointer to a table of names (the LNT; see comprising a function and a binding below). Either scheme requires that any environment, is provided through a primitive PROG or open LAMBDA which does not function which creates an "environment constitute the entire body of a function be descriptor" pointing to a specified frame. made a separate subfunction, since PROG As long as there are accessible references variables are bound at the time the frame is to this descriptor, the frame continues to created, i.e. when the function is entered. exist. Environment descriptors also allow The MicroLISP scheme may slow down free the user to construct cooperating sequential variable searches, since a name table may processes (coroutines); the stack becomes not be in core any longer when the search tree-structured rather than linear, as in wants to scan it. Its advantages are that the Burroughs B6500.1* it is not necessary to insert the name of each variable at function entry time, and BBN-LISP, like most programming languages, that the entire word is available for recognizes two kinds of accesses to holding the binding, which (with the help of variables: "load" and "store". This duality a few type bits elsewhere in the frame) may actually exists for data structures as well thus be a full-word integer or real number. (CAR-RPLACA, GET-POT, etc.) but is not treated systematically. MicroLISP Code Design systematizes this concept by allowing a function to have, in effect, two Conventional machines generally take the definitions, one for the (normal) "load" attitude that it must be convenient for any context, one for the "store" context. The instruction to reference any word in the SET function is extended so that if the overall address space. This approach tends first argument is a list to produce instruction formats in which a (fn argl ... argn) large fraction (half or more) of the bits rather than a variable, the function fn is are devoted to a memory address. MicroLISP called in "store" mode with arguments argl takes advantage of the observed fact that a ... argn and newvalue (the second argument given LISP function references rather few of SET). SETQ is alsO extended in the functions and variables and therefore can obvious way, but is not particularly useful. make do with very short addresses which just A more useful function is index a global table (of commonly used (SETFQ (f n argl ... argn) newvalue) functions) or a function-local table (of which quotes the function name and evaluates local variables and less common functions). everything else. This allows RPLACA, for Furthermore, a given name is usually only example, to be defined as used as either a function or a variable, not (LAMBDA (X Y) (SETFQ (CAR X) Y>) - both. MicroLISP tags each name in the tables with a function/variable flag, which The semantics of variables are simple in eliminates the need for levels of list principle: search the current basic frame, structure as a syntactic device, and tags then the caller's frame, etc. for a binding functions with an argument count, which of a variable with the desired name; if none eliminates the need for sublists as scope is found, consult the "value cell" of the delimiters. Thus MicroLISP code is variable; if this contains the special value essentially a string of byte-sized NOBIND, the variable is unbound. (In fact, instructions, representing the original the search follows a chain through an s-expression in postfix form, where most "access link" pointer in the frame extension bytes reference either a "global name table" rather than the caller pointer or (GNT) or a "local name table" (LNT) as just "control link", to cover application of described. FUNARGs.) MicroLISP (and compiled BBN LISP) actually use three variations of this The LNT actually has additional internal searching strategy depending on the structure: argument names come first, then situation. Searching for the arguments of PROG and free variables, then everything the current function is pointless: their else. The "binding" of a free variable is a relative locations in the basic frame are pointer to the true binding, and the known to the compiler and they can be variable searching algorithm uses this accessed by indexing.
Recommended publications
  • The Development of Smalltalk Topic Paper #7
    The Development of Smalltalk Topic Paper #7 Alex Laird Max Earn Peer CS-3210-01 Reviewer On Time/Format 1 2/4/09 Survey of Programming Languages Correct 5 Spring 2009 Clear 2 Computer Science, (319) 360-8771 Concise 2 [email protected] Grading Rubric Grading Total 10 pts ABSTRACT Dynamically typed languages are easier on the compiler because This paper describes the development of the Smalltalk it has to make fewer passes and the brunt of checking is done on programming language. the syntax of the code. Compilation of Smalltalk is just-in-time compilation, also known Keywords as dynamic translation. It means that upon compilation, Smalltalk code is translated into byte code that is interpreted upon usage and Development, Smalltalk, Programming, Language at that point the interpreter converts the code to machine language and the code is executed. Dynamic translations work very well 1. INTRODUCTION with dynamic typing. Smalltalk, yet another programming language originally developed for educational purposes and now having a much 5. IMPLEMENTATIONS broader horizon, first appeared publically in the computing Smalltalk has been implemented in numerous ways and has been industry in 1980 as a dynamically-typed object-oriented language the influence of many future languages such as Java, Python, based largely on message-passing in Simula and Lisp. Object-C, and Ruby, just to name a few. Athena is a Smalltalk scripting engine for Java. Little Smalltalk 2. EARLY HISTORY was the first interpreter of the programming language to be used Development for Smalltalk started in 1969, but the language outside of the Xerox PARC.
    [Show full text]
  • The Evolution of Lisp
    1 The Evolution of Lisp Guy L. Steele Jr. Richard P. Gabriel Thinking Machines Corporation Lucid, Inc. 245 First Street 707 Laurel Street Cambridge, Massachusetts 02142 Menlo Park, California 94025 Phone: (617) 234-2860 Phone: (415) 329-8400 FAX: (617) 243-4444 FAX: (415) 329-8480 E-mail: [email protected] E-mail: [email protected] Abstract Lisp is the world’s greatest programming language—or so its proponents think. The structure of Lisp makes it easy to extend the language or even to implement entirely new dialects without starting from scratch. Overall, the evolution of Lisp has been guided more by institutional rivalry, one-upsmanship, and the glee born of technical cleverness that is characteristic of the “hacker culture” than by sober assessments of technical requirements. Nevertheless this process has eventually produced both an industrial- strength programming language, messy but powerful, and a technically pure dialect, small but powerful, that is suitable for use by programming-language theoreticians. We pick up where McCarthy’s paper in the first HOPL conference left off. We trace the development chronologically from the era of the PDP-6, through the heyday of Interlisp and MacLisp, past the ascension and decline of special purpose Lisp machines, to the present era of standardization activities. We then examine the technical evolution of a few representative language features, including both some notable successes and some notable failures, that illuminate design issues that distinguish Lisp from other programming languages. We also discuss the use of Lisp as a laboratory for designing other programming languages. We conclude with some reflections on the forces that have driven the evolution of Lisp.
    [Show full text]
  • The Cedar Programming Environment: a Midterm Report and Examination
    The Cedar Programming Environment: A Midterm Report and Examination Warren Teitelman The Cedar Programming Environment: A Midterm Report and Examination Warren Teitelman t CSL-83-11 June 1984 [P83-00012] © Copyright 1984 Xerox Corporation. All rights reserved. CR Categories and Subject Descriptors: D.2_6 [Software Engineering]: Programming environments. Additional Keywords and Phrases: integrated programming environment, experimental programming, display oriented user interface, strongly typed programming language environment, personal computing. t The author's present address is: Sun Microsystems, Inc., 2550 Garcia Avenue, Mountain View, Ca. 94043. The work described here was performed while employed by Xerox Corporation. XEROX Xerox Corporation Palo Alto Research Center 3333 Coyote Hill Road Palo Alto, California 94304 1 Abstract: This collection of papers comprises a report on Cedar, a state-of-the-art programming system. Cedar combines in a single integrated environment: high-quality graphics, a sophisticated editor and document preparation facility, and a variety of tools for the programmer to use in the construction and debugging of his programs. The Cedar Programming Language is a strongly-typed, compiler-oriented language of the Pascal family. What is especially interesting about the Ce~ar project is that it is one of the few examples where an interactive, experimental programming environment has been built for this kind of language. In the past, such environments have been confined to dynamically typed languages like Lisp and Smalltalk. The first paper, "The Roots of Cedar," describes the conditions in 1978 in the Xerox Palo Alto Research Center's Computer Science Laboratory that led us to embark on the Cedar project and helped to define its objectives and goals.
    [Show full text]
  • MVC Revival on the Web
    MVC Revival on the Web Janko Mivšek [email protected] @mivsek @aidaweb ESUG 2013 Motivation 30 years of Smalltalk, 30 years of MVC 34 years exa!tly, sin!e "#$# %ot in JavaScri&t MVC frameworks 'or Sin(le)*age and +ealtime web a&&s ,e Smalltalkers s-ould respe!t and revive our &earls better Contents MVC e &lained %istory /sa(e in !.rrent JavaScri&t frameworks /sa(e in Smalltalk C.rrent and f.t.re MVC in 0ida/Web MVC Explained events Ar!hite!tural desi(n &attern - Model for domain s&e!ifi! data and logi! View updates Controller ) View for &resentation to t-e .ser ) Controller for intera!tions wit- t-e .ser UI and .&datin( domain model Domain changes Main benefit: actions observing ) se&aration of !on!erns Model MVC based on Observer pattern subscribe ) 3bserver looks at observee Observer changed - 3bservee is not aware of t-at s u 4e&enden!y me!-anism2 B t n - 3bserver is de&endent on 3bservee state e observing v - 3bservee m.st re&ort state !-an(es to 3bserver E b - *.b/S.b Event 6.s de!ou&les 3bservee from u S / 3bserver to &reserve its .nawarnes of observation b u changed P Observee Main benefit: (Observable) ) se&aration of !on!erns Multiple observers subscribe - M.lti&le observers of t-e same 3bservee Observer changed - 7n MVC an 3bservee is View and 3bservee is domain Model, t-erefore2 s u B t - many views of t-e same model n e observing v - many a&&s E b - many .sers u S / - mix of all t-ree !ases b u Observee changed P (Observable) Example: Counter demo in Aida/Web M.lti.ser realtime web !ounter exam&le -ttp://demo.aidaweb.si – !li!k Realtime on t-e left – !li!k De!rease or In!rease to c-an(e counter – !ounter is c-an(ed on all ot-er8s browsers History of MVC (1) 7nvented by 9rygve +eenska.g w-en -e worked in "#$:1$# wit- Alan ;ay's group on <ero *arc on Smalltalk and Dynabook – 'inal term Model)View)Controller !oined 10.
    [Show full text]
  • Dynamic Object-Oriented Programming with Smalltalk
    Dynamic Object-Oriented Programming with Smalltalk 1. Introduction Prof. O. Nierstrasz Autumn Semester 2009 LECTURE TITLE What is surprising about Smalltalk > Everything is an object > Everything happens by sending messages > All the source code is there all the time > You can't lose code > You can change everything > You can change things without restarting the system > The Debugger is your Friend © Oscar Nierstrasz 2 ST — Introduction Why Smalltalk? > Pure object-oriented language and environment — “Everything is an object” > Origin of many innovations in OO development — RDD, IDE, MVC, XUnit … > Improves on many of its successors — Fully interactive and dynamic © Oscar Nierstrasz 1.3 ST — Introduction What is Smalltalk? > Pure OO language — Single inheritance — Dynamically typed > Language and environment — Guiding principle: “Everything is an Object” — Class browser, debugger, inspector, … — Mature class library and tools > Virtual machine — Objects exist in a persistent image [+ changes] — Incremental compilation © Oscar Nierstrasz 1.4 ST — Introduction Smalltalk vs. C++ vs. Java Smalltalk C++ Java Object model Pure Hybrid Hybrid Garbage collection Automatic Manual Automatic Inheritance Single Multiple Single Types Dynamic Static Static Reflection Fully reflective Introspection Introspection Semaphores, Some libraries Monitors Concurrency Monitors Categories, Namespaces Packages Modules namespaces © Oscar Nierstrasz 1.5 ST — Introduction Smalltalk: a State of Mind > Small and uniform language — Syntax fits on one sheet of paper >
    [Show full text]
  • Lisp: Program Is Data
    LISP: PROGRAM IS DATA A HISTORICAL PERSPECTIVE ON MACLISP Jon L White Laboratory for Computer Science, M.I.T.* ABSTRACT For over 10 years, MACLISP has supported a variety of projects at M.I.T.'s Artificial Intelligence Laboratory, and the Laboratory for Computer Science (formerly Project MAC). During this time, there has been a continuing development of the MACLISP system, spurred in great measure by the needs of MACSYMAdevelopment. Herein are reported, in amosiac, historical style, the major features of the system. For each feature discussed, an attempt will be made to mention the year of initial development, andthe names of persons or projectsprimarily responsible for requiring, needing, or suggestingsuch features. INTRODUCTION In 1964,Greenblatt and others participated in thecheck-out phase of DigitalEquipment Corporation's new computer, the PDP-6. This machine had a number of innovative features that were thought to be ideal for the development of a list processing system, and thus it was very appropriate that thefirst working program actually run on thePDP-6 was anancestor of thecurrent MACLISP. This earlyLISP was patterned after the existing PDP-1 LISP (see reference l), and was produced by using the text editor and a mini-assembler on the PDP-1. That first PDP-6 finally found its way into M.I.T.'s ProjectMAC for use by theArtificial lntelligence group (the A.1. grouplater became the M.I.T. Artificial Intelligence Laboratory, and Project MAC became the Laboratory for Computer Science). By 1968, the PDP-6 wasrunning the Incompatible Time-sharing system, and was soon supplanted by the PDP-IO.Today, the KL-I 0, anadvanced version of thePDP-10, supports a variety of time sharing systems, most of which are capable of running a MACLISP.
    [Show full text]
  • As We May Communicate Carson Reynolds Department of Technical Communication University of Washington
    As We May Communicate Carson Reynolds Department of Technical Communication University of Washington Abstract The purpose of this article is to critique and reshape one of the fundamental paradigms of Human-Computer Interaction: the workspace. This treatise argues that the concept of a workspace—as an interaction metaphor—has certain intrinsic defects. As an alternative, a new interaction model, the communication space is offered in the hope that it will bring user interfaces closer to the ideal of human-computer symbiosis. Keywords: Workspace, Communication Space, Human-Computer Interaction Our computer systems and corresponding interfaces have come quite a long way in recent years. We no longer patiently punch cards or type obscure and unintelligible commands to interact with our computers. However, out current graphical user interfaces, for all of their advantages, still have shortcomings. It is the purpose of this paper to attempt to deduce these flaws by carefully examining our earliest and most basic formulation of what a computer should be: a workspace. The History of the Workspace The modern computerized workspace has its beginning in Vannevar Bush’s landmark article, “As We May Think.” Bush presented the MEMEX: his vision of an ideal workspace for researchers and scholars that was capable of retrieving and managing information. Bush thought that machines capable of manipulating information could transform the way that humans think. What did Bush’s idealized workspace involve? It consists of a desk, and while it can presumably be operated from a distance, it is primarily the piece of furniture at which he works. On top are slanting translucent screens, on which material can be projected for convenient reading.
    [Show full text]
  • A History of Clojure
    A History of Clojure RICH HICKEY, Cognitect, Inc., USA Shepherd: Mira Mezini, Technische Universität Darmstadt, Germany Clojure was designed to be a general-purpose, practical functional language, suitable for use by professionals wherever its host language, e.g., Java, would be. Initially designed in 2005 and released in 2007, Clojure is a dialect of Lisp, but is not a direct descendant of any prior Lisp. It complements programming with pure functions of immutable data with concurrency-safe state management constructs that support writing correct multithreaded programs without the complexity of mutex locks. Clojure is intentionally hosted, in that it compiles to and runs on the runtime of another language, such as the JVM. This is more than an implementation strategy; numerous features ensure that programs written in Clojure can leverage and interoperate with the libraries of the host language directly and efficiently. In spite of combining two (at the time) rather unpopular ideas, functional programming and Lisp, Clojure has since seen adoption in industries as diverse as finance, climate science, retail, databases, analytics, publishing, healthcare, advertising and genomics, and by consultancies and startups worldwide, much to the career-altering surprise of its author. Most of the ideas in Clojure were not novel, but their combination puts Clojure in a unique spot in language design (functional, hosted, Lisp). This paper recounts the motivation behind the initial development of Clojure and the rationale for various design decisions and language constructs. It then covers its evolution subsequent to release and adoption. CCS Concepts: • Software and its engineering ! General programming languages; • Social and pro- fessional topics ! History of programming languages.
    [Show full text]
  • Lisp and Scheme I
    4/10/2012 Versions of LISP Why Study Lisp? • LISP is an acronym for LISt Processing language • It’s a simple, elegant yet powerful language • Lisp (b. 1958) is an old language with many variants • You will learn a lot about PLs from studying it – Fortran is only older language still in wide use • We’ll look at how to implement a Scheme Lisp and – Lisp is alive and well today interpreter in Scheme and Python • Most modern versions are based on Common Lisp • Scheme is one of the major variants • Many features, once unique to Lisp, are now in – We’ll use Scheme, not Lisp, in this class “mainstream” PLs: python, javascript, perl … Scheme I – Scheme is used for CS 101 in some universities • It will expand your notion of what a PL can be • The essentials haven’t changed much • Lisp is considered hip and esoteric among computer scientists LISP Features • S-expression as the universal data type – either at atom (e.g., number, symbol) or a list of atoms or sublists • Functional Programming Style – computation done by applying functions to arguments, functions are first class objects, minimal use of side-effects • Uniform Representation of Data & Code – (A B C D) can be interpreted as data (i.e., a list of four elements) or code (calling function ‘A’ to the three parameters B, C, and D) • Reliance on Recursion – iteration is provided too, but We lost the documentation on quantum mechanics. You'll have to decode recursion is considered more natural and elegant the regexes yourself. • Garbage Collection – frees programmer’s explicit memory management How Programming Language Fanboys See Each Others’ Languages 1 4/10/2012 What’s Functional Programming? Pure Lisp and Common Lisp Scheme • The FP paradigm: computation is applying • Lisp has a small and elegant conceptual core • Scheme is a dialect of Lisp that is favored by functions to data that has not changed much in almost 50 years.
    [Show full text]
  • Session 1: Introducing Extreme Java
    Extreme Java G22.3033-006 Session 1 – Main Theme Introducing Extreme Java Dr. Jean-Claude Franchitti New York University Computer Science Department Courant Institute of Mathematical Sciences Agenda • Course Logistics, Structure and Objectives • Java Programming Language Features • Java Environment Limitations • Upcoming Features in “Tiger” 1.5 • Model Driven Architectures for Java Systems • Java Enterprise Application Enabling • Agile Modeling & eXtreme Programming • Aspect-Oriented Programming & Refactoring • Java Application Performance Enhancement • Readings, Class Project, and Assignment #1a 2 1 Course Logistics • Course Web Site • http://cs.nyu.edu/courses/spring03/G22.3033-006/index.htm • http://www.nyu.edu/classes/jcf/g22.3033-007/ • (Password: extjava) • Course Structure, Objectives, and References • See detailed syllabus on the course Web site under handouts • See ordered list of references on the course Web site • Textbooks • Mastering Java 2, J2SE 1.4 • J2EE: The Complete Reference • Expert One-on-One: J2EE Design and Development 3 Part I Java Features 4 2 Java Features Review • Language Categories • Imperative • Functional • Logic-based • Model-based PL Comparison Framework • Data Model • Behavioral Model • Event Model • Execution, Persistence, etc. • See Session 1 Handout on Java Review 5 J2SE 1.4 Features http://java.sun.com/j2se/1.4/index.html 6 3 J2SE 1.4 Features (continued) • HotSpot virtual machine • Full 64-bit support • Improved garbage collection • Ability to exploit multiprocessing • Optimization of the Java2D
    [Show full text]
  • Creating Graphical User Interfaces
    i i \main" 2004/6/14 page 355 i i C H A P T E R 15 Creating Graphical User Interfaces 15.1 WHERE DO GRAPHICAL USER INTERFACES COME FROM? 15.2 CREATING A BASIC GRAPHICAL USER INTERFACE 15.3 CALLBACKS AND LAYOUT MANAGERS 15.4 USING SCROLLING LISTS Chapter Learning Objectives ² To make graphical user interfaces out of components such as windows, text ¯elds, buttons, and scrolling lists. ² To use callbacks to handle user interface events. ² To use trees for conceptualizing user interface structure. 15.1 WHERE DO GRAPHICAL USER INTERFACES COME FROM? The ¯rst computers were incredibly painful and tedious to work with. You \pro- grammed" them by literally rewiring them. There wasn't a screen, so you couldn't have a \graphical" user interface at all. Our common experience of using a keyboard to interact with the computer didn't come until much later. In the late 1960's, the dominant mode of interaction with the computer was through punched cards. Using a keyboard on a card punch machine, you prepared your instructions for the computer on pieces of cardboard that were then ordered in the right sequence and loaded into the computer. Heaven help the person who dropped her stack of cards and had to re-order hundreds of cards of a large program! The output from the computer back to the programmer was typically large piles of paper printouts, though was some starting work with computer music and computer graphics (on specialized, expensive monitors). In the 1960's and 1970's, computer scientists began envisioning a new role for the computer in its interaction with humans.
    [Show full text]
  • Lists in Lisp and Scheme
    Lists in Lisp and Scheme • Lists are Lisp’s fundamental data structures • However, it is not the only data structure Lists in Lisp – There are arrays, characters, strings, etc. – Common Lisp has moved on from being merely a LISt Processor and Scheme • However, to understand Lisp and Scheme you must understand lists – common funcAons on them – how to build other useful data structures with them In the beginning was the cons (or pair) Pairs nil • What cons really does is combines two objects into a a two-part object called a cons in Lisp and a pair in • Lists in Lisp and Scheme are defined as Scheme • Conceptually, a cons is a pair of pointers -- the first is pairs the car, and the second is the cdr • Any non empty list can be considered as a • Conses provide a convenient representaAon for pairs pair of the first element and the rest of of any type • The two halves of a cons can point to any kind of the list object, including conses • We use one half of the cons to point to • This is the mechanism for building lists the first element of the list, and the other • (pair? ‘(1 2) ) => #t to point to the rest of the list (which is a nil either another cons or nil) 1 Box nota:on Z What sort of list is this? null Where null = ‘( ) null a a d A one element list (a) null null b c a b c > (set! z (list ‘a (list ‘b ‘c) ‘d)) (car (cdr z)) A list of 3 elements (a b c) (A (B C) D) ?? Pair? Equality • Each Ame you call cons, Scheme allocates a new memory with room for two pointers • The funcAon pair? returns true if its • If we call cons twice with the
    [Show full text]