Structure Programming in Lisp. Shared Structure. Tailp. Shared Structure. Top-Level List Structure
|
|
- Georgia Fields
- 5 years ago
- Views:
Transcription
1 Structure Programming in Lisp Lecture 6 - Structure; ase Study: locks World Lisp's use of pointers Let you put any value anywhere Details are taken care of by the Lisp interpreter What goes on "under the hood"? It's useful to know this sometimes Some functions let you get down to low level details of pointers Alok Mehta - Programming in Lisp - Lecture 6 1 Alok Mehta - Programming in Lisp - Lecture 6 2 Shared Structure Lists can share conses in common > (setf part (list 'b 'c)) > (setf whole (cons 'a part)) (A ) > (tailp part whole) T WHOLE PART A Tailp Definition of tailp (tailp object list) returns T if object is a tail of list Example implementation > (defun our-tailp (x y) (or (eql x y) (and (consp y) (our-tailp x (cdr y))))) An object is a tail of itself (base case) NIL is a tail of every proper list Recursively take cdr's of the list, until you test for (eql NIL NIL) Alok Mehta - Programming in Lisp - Lecture 6 3 Alok Mehta - Programming in Lisp - Lecture 6 4 Shared Structure Lists can share structure without either being a tail of the other > (setf part (list 'b 'c) whole1 (cons 1 part) whole2 (cons 2 part)) WHOLE1 PART Top-Level List Structure Sometimes want to treat data structure as a list Include only the conses that make up the list Don't recurse into conses that make up elements This is the top-level list structure Other times, want to treat data structure as a tree All conses are important and treated uniformly 1 WHOLE2 A D 2 Alok Mehta - Programming in Lisp - Lecture 6 5 Alok Mehta - Programming in Lisp - Lecture 6 6 1
2 opy-list vs. opy-tree opy-list vs. opy-tree (code) Original opy-list opy-tree A A D D Example implementation of copy-list > (defun our-copy-list (lst) (if (null lst) nil (cons (car lst) (our-copy-list (cdr lst))))) Example implementation of copy-tree > (defun our-copy-tree (lst) (if (atom tr) tr (cons (our-copy-tree (car tr)) (our-copy-tree (cdr tr))))) Lisp handles pointers automatically Then why do we care? ecause some Lisp functions can modify structures Alok Mehta - Programming in Lisp - Lecture 6 7 Alok Mehta - Programming in Lisp - Lecture 6 8 Setf revisited Operators > (setf whole (list 'a 'b 'c) tail (cdr whole)) > (setf (second tail) 'e) E > tail ( E) > whole (A E) WHOLE TAIL A Alok Mehta - Programming in Lisp - Lecture 6 9 Avoid modifying lists Operators like setf, pop, rplaca, If you need to (or want to) modify a list Make sure it's not shared Or, make sure the shared update works as expected Or, make changes to a copy of the list > (setf whole (list 'a 'b 'c) tail (cdr whole)) > (setf tail (cons (first tail) (cons 'e (rest (rest tail))))) > tail > whole (A E) Alok Mehta - Programming in Lisp - Lecture 6 10 Parameter passing Parameters are passed by value The value is copied into the function If the value is a list The entire list is not copied The reference to the list is copied A function can permanently alter a list passed in as a parameter! Similar to parameter passing in Java an cause unintentional errors ut, can also be useful Queues Queue data structure First in, First out ompare to stacks (last in, first out) Stacks are easy in Lisp Insert (push) / Retrieve (pop) happen at the same end of the list Queues are harder Insert (enqueue) / Retrieve (dequeue) happen at opposite ends Q1 A Alok Mehta - Programming in Lisp - Lecture 6 11 Alok Mehta - Programming in Lisp - Lecture
3 Sample implementation Implementation of Queue (Inefficient) > (defmacro dequeue (q) `(pop,q)) > (defmacro enqueue (o q) `(setf,q (append,q (cons,o nil)))) Implementation of Queue using LOS (Inefficient) > (defclass queue () ((front :accessor front :initform nil))) > (defmethod dequeue ((q queue)) (pop (front q))) > (defmethod enqueue (o (q queue) &aux (node (cons o nil))) (setf (front q) (append (front q) node))) Example usage > (setf a (make-instance 'queue)) > (enqueue 'a a) > (enqueue 'b a) > (dequeue a) Efficient Queue Implementation Efficient Implementation of Queue using LOS > (defclass queue () ((front :accessor front :initform nil) (back :accessor back :initform nil))) > (defmethod enqueue (o (q queue) &aux (node (cons o nil))) (if (eql (front q) nil) ; first one? (setf (front q) node (back q) node) (progn ; not first time (setf (cdr (back q)) node) (setf (back q) (cdr (back q)))) )) > (defmethod dequeue ((q queue)) (if (eql (cdr (front q)) nil) (setf back nil)) ;last one (pop (front q))) Alok Mehta - Programming in Lisp - Lecture 6 13 Alok Mehta - Programming in Lisp - Lecture 6 14 Destructive Functions Several functions update the lists passed to them Examples Delete (destructive version of remove) > (setf a '(a b a d a)) (A A D A) > (remove 'a a) ; Doesn't change A ( D) > (delete 'a A) ; hanges A ( D) Nconc (destructive version of append) > (defun our-nconc (x y) (if (consp x) (progn (setf (cdr (last x)) y) x) y)) ase Study: The locks World Rules There are three kinds of movable objects: bricks, wedges, balls. Robot has one hand. It can grasp any movable block that has nothing on top of it. Every block is either held by the hand or supported by exactly one brick or the table. No block can overhang from its support. Although a movable block can be moved to the top of a wedge or a ball, neither wedges nor balls can support anything. Supporting bricks can support more than one block, as long as there is room. The table is wide enough for all of the blocks to fit on it at once. Alok Mehta - Programming in Lisp - Lecture 6 15 Alok Mehta - Programming in Lisp - Lecture 6 16 ase Study: The locks World lass Hierarchy Several moves are required to put block 1 on block 2 Sample path Move W7; Move 4; Move 1 onto 2 Load-bearing-block asic-block Movable-block Hand Π <=== Robotic Hand 4 1 W7 2 3 W5 6 L8 Table rick Wedge all Table Alok Mehta - Programming in Lisp - Lecture 6 17 Alok Mehta - Programming in Lisp - Lecture
4 lass Definitions lass Definitions (cont.) asic-lock > (defclass basic-block() ((name :accessor block-name :initarg :name) (width :accessor block-width :initarg :width) (height :accessor block-height :initarg :height) (position :accessor block-position :initarg :position) (supported-by :accessor block-supported-by :initform nil))) Supported-by => What the block is supported by (what's underneath it) Movable-block > (defclass movable-block (basic-block) ()) Load-bearing-block Has new field > (defclass load-bearing-block (basic-block) ((support-for :accessor block-support-for :initform nil))) Support-for => What the block is a support for (what's on top of it) Alok Mehta - Programming in Lisp - Lecture 6 19 rick, wedge, ball, table > (defclass brick (movable-block load-bearing-block) ()) > (defclass wedge (movable-block) ()) > (defclass ball (movable-block) ()) Table > (defclass table (load-bearing-block) ()) Robotic Hand > (defclass hand () ((name :accessor hand-name :initarg :name) (position :accessor hand-position :initarg :position) (grasping :accessor hand-grasping :initform nil))) Alok Mehta - Programming in Lisp - Lecture 6 20 reating locks in locks World (defvar *blocks* (list (make-instance 'table :name 'table :width 20 :height 0 :position '(0 0)) (make-instance 'brick :name 'b1 :width 2 :height 2 :position '(0 0)) (make-instance 'brick :name 'b2 :width 2 :height 2 :position '(2 0)) (make-instance 'brick :name 'b3 :width 4 :height 4 :position '(4 0)) (make-instance 'brick :name 'b4 :width 2 :height 2 :position '(8 0)) (make-instance 'wedge :name 'w5 :width 2 :height 4 :position '(10 0)) (make-instance 'brick :name 'b6 :width 4 :height 2 :position '(12 0)) (make-instance 'wedge :name 'w7 :width 2 :height 2 :position '(16 0)) (make-instance 'ball :name 'L8 :width 2 :height 2 :position '(18 0)) )) (defvar *hand* (make-instance 'hand :name '*hand* :position '(0 6))) Π Table W5 6 Alok Mehta - Programming in Lisp - Lecture 6 21 W7 L8 Initializing locks World reate other global variables for convenience > (dolist (l *blocks*) (set (block-name l) l)) This sets the global variables TALE, 1, 2, W7, L8 to their respective block All blocks rest on the table initially > (dolist (l (rest *blocks*)) ; For each, except table (setf (block-supported-by l) table) (push l (block-support-for table))) Load-bearing-block has a method block-support-for This was automatically generated reate a dummy stub for this method in basic-block > (defmethod block-support-for ((object basic-block)) nil) y default, basic-blocks do not have anything on top of them. Only Load-bearingblocks may have something on top of them. Alok Mehta - Programming in Lisp - Lecture 6 22 lock-support-for Put-On Returns Nil Returns value of Slot Support-For Load-bearing-block lock-support-for asic-block lock-support-for Movable-block Table rick Wedge all Hand Want a method, PUT-ON, that places one object on another Get space for the object (may have to move things around) Grasp object (may have to remove things on top of the object) Move object Ungrasp object asic Prototype > (defmethod put-on ((object movable-block) ) Alok Mehta - Programming in Lisp - Lecture 6 23 Alok Mehta - Programming in Lisp - Lecture
5 Put-On Implementation > (defmethod put-on ((object movable-block) (if (get-space object support) (and (grasp object) (move object support) (ungrasp object)) (format t "~&ouldn't get space to put ~a on ~a." (block-name object) (block-name support)))) get-space, grasp, move, ungrasp have yet to be defined Get-space either finds space or makes space > (defmethod get-space ((object movable-block) (or (find-space object support) (make-space object support))) find-space, make-space have yet to be defined (do this later) Alok Mehta - Programming in Lisp - Lecture 6 25 Grasp Grasp Puts desired object in robot's hand > (defmethod grasp ((object movable-block)) (unless (eq (hand-grasping *hand*) object) ; already holding? ; Make sure nothing else is on top of object (when (block-support-for object) (clear-top object)) ; Make sure robot isn't holding anything else (when (hand-grasping *hand*) (get-rid-of (hand-grasping *hand*))) (format t "~&Move hand to pick up ~a at location ~a." (block-name object) (top-location object)) (setf (hand-position *hand*) (top-location object)) (format t "~&Grasp ~a." (block-name object)) (setf (hand-grasping *hand*) object)) t) Need to define: lear-top, top-location Function returns T if successful Alok Mehta - Programming in Lisp - Lecture 6 26 Ungrasp Ungrasp Releases object, if object is being supported by something else > (defmethod ungrasp ((object movable-block)) (when (block-supported-by object) (format t "~&Ungrasping ~a" (block-name object)) (setf (hand-grasping *hand*) nil) T)) Get-rid-of puts object on the table (out of the way) > (defmethod get-rid-of ((object movable-block)) (put-on object table)) Make-space lear-top Gets rid of everything on top of an object > (defmethod clear-top ((support load-bearing-block)) (dolist (obstacle (block-support-for support) t) (get-rid-of obstacle))) Make-space lears away just enough room to put block Algorithm keeps getting rid of things on top of block Until the find-space function returns that there is enough space available > (defmethod make-space ((object movable-block) (dolist (obstruction (block-support-for support)) (get-rid-of obstruction) (let ((space (find-space object support))) (when space (return space))))) Alok Mehta - Programming in Lisp - Lecture 6 27 Alok Mehta - Programming in Lisp - Lecture 6 28 Move Moves an object on top of a support > (defmethod move ((object movable-block) (remove-support object) (let ((newplace (get-space object support))) (format t "~&Move ~a to top of ~a at location ~a." (block-name object) (block-name support) newplace) (setf (block-position object) newplace) (setf (hand-position *hand*) (top-location object))) (add-support object support) t) alls remove-support, add-support These are methods for bookkeeping They maintain the bi-directional links (support-for, supported-by) Remove-support removes the bi-directional links of an object Add-support adds bi-directional links for an object that is to be placed on top of a support Remove-support Remove-support This is a bookkeeping method that removes bi-directional links > (defmethod remove-support ((object movable-block)) (let ((support (block-supported-by object))) (when support (setf (block-support-for support) (remove object (block-support-for support))) (setf (block-supported-by object) nil) t))) Alok Mehta - Programming in Lisp - Lecture 6 29 Alok Mehta - Programming in Lisp - Lecture
6 Add-support Adding support, for general case This is just a stub (does no operation) an't really put an object on top of any basic-block > (defmethod add-support ((object movable-block) t) Adding support, for specific cases For load-bearing blocks, we can put an object on top ookkeeping needed for this is to update bi-directional pointers > (defmethod add-support ((object movable-block) (support load-bearing-block)) (push object (block-support-for support)) (setf (block-supported-by object support))) Top-location Returns the location of the top (center) of a block Example Usage > (block-position b3) (4 0) <-- Lower left position of block > (block-width b3) 4 > (block-height b3) 4 > (top-location b3) (6 4) <-- X = Pos.X + (width/2.0); Y = Pos.Y Implementation > (defmethod top-location ((object basic-block)) (list (+ (first (block-position object)) (/ (block-width object) 2)) (+ (second (block-position object)) (block-height object)))) Alok Mehta - Programming in Lisp - Lecture 6 31 Alok Mehta - Programming in Lisp - Lecture 6 32 Find-space Find-space asic algorithm 4 6 For each possible location on top of support that the object can be placed, Is the position occupied? If not, we've found the space; else continue > (defmethod find-space ((object basic-block) (dotimes (offset (+ 1 (- (block-width support) (block-width object)))) (unless (intersections-p object offset (first (block-position support)) (block-support-for support)) (return (list (+ offset (first (block-position support))) (+ (second (block-position support)) (block-height support))))))) Intersections-p is to be defined next 4 6 Intersections-p Intersections-p hecks for intersections (only checks the X dimension) > (defun intersections-p (object offset base obstacles) (dolist (obstacle obstacles) (let* ((ls_proposed (+ offset base)) (rs_proposed (+ ls_proposed (block-width object))) (ls_obstacle (first (block-position obstacle))) (rs_obstacle (+ ls_obstacle (block-width obstacle)))) (unless (or (>= ls_proposed rs_obstacle) (<= rs_proposed ls_obstacle)) (return t))))) Obstacle Proposed Object Location Alok Mehta - Programming in Lisp - Lecture 6 33 Alok Mehta - Programming in Lisp - Lecture 6 34 locks World Usage Sample usage of blocks world > (put-on b4 b1) > (put-on w7 b2) > (put-on b1 b2) Final Exam Next time Open book, open notes No calculators, computers, etc. No lisp interpreter! Mostly programming type questions Write a program to Exam may contain material from hapters 1-12, plus case studies: Expert Systems, locks World Anything from lecture notes Alok Mehta - Programming in Lisp - Lecture 6 35 Alok Mehta - Programming in Lisp - Lecture
Look at the outermost list first, evaluate each of its arguments, and use the results as arguments to the outermost operator.
LISP NOTES #1 LISP Acronymed from List Processing, or from Lots of Irritating Silly Parentheses ;) It was developed by John MacCarthy and his group in late 1950s. Starting LISP screen shortcut or by command
More information(defvar *state* nil "The current state: a list of conditions.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; GPS engine for blocks world ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defvar *dbg-ids* nil "Identifiers used by dbg") (defvar *state* nil "The current state: a list of conditions.")
More informationObject oriented programming
Object oriented programming The main ideas behind object-oriented programming: the same type of action may be carried out differently on different types of objects cutting a cake is different from cutting
More informationA little bit of Lisp
B.Y. Choueiry 1 Instructor s notes #3 A little bit of Lisp Introduction to Artificial Intelligence CSCE 476-876, Fall 2017 www.cse.unl.edu/~choueiry/f17-476-876 Read LWH: Chapters 1, 2, 3, and 4. Every
More informationA Genetic Algorithm Implementation
A Genetic Algorithm Implementation Roy M. Turner (rturner@maine.edu) Spring 2017 Contents 1 Introduction 3 2 Header information 3 3 Class definitions 3 3.1 Individual..........................................
More informationA Brief Introduction to Common Lisp
A Brief Introduction to Common Lisp David Gu Schloer Consulting Group david_guru@gty.org.in A Brief History Originally specified in 1958, Lisp is the second-oldest highlevel programming language in widespread
More informationAllegroCache: an Introduction
AllegroCache: an Introduction David Margolies (dm@franz.com) Questions and comments to support@franz.com Topics What is AllegroCache? Getting started Persistent classes and objects Transactions, committing
More informationObject Oriented Programming (OOP)
Object Oriented Programming (OOP) o New programming paradigm o Actions Objects o Objects Actions o Object-oriented = Objects + Classes + Inheritance Imperative programming o OOP (Object-Oriented Programming)
More informationModern Programming Languages. Lecture LISP Programming Language An Introduction
Modern Programming Languages Lecture 18-21 LISP Programming Language An Introduction 72 Functional Programming Paradigm and LISP Functional programming is a style of programming that emphasizes the evaluation
More informationSymbolic Programming. Dr. Zoran Duric () Symbolic Programming 1/ 89 August 28, / 89
Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic expressions. Symbolic manipulation: you do it all the
More informationCSCE476/876 Fall Homework 3: Programming Assignment Using Emacs and Common Lisp. 1 Exercises (15 Points) 2. 2 Find (6 points) 4
CSCE476/876 Fall 2018 Homework 3: Programming Assignment Using Emacs and Common Lisp Assigned on: Monday, September 10 th, 2018. Due: Monday, September 24 th, 2018. Contents 1 Eercises (15 Points) 2 2
More informationDebugging in LISP. trace causes a trace to be printed for a function when it is called
trace causes a trace to be printed for a function when it is called ;;; a function that works like reverse (defun rev (list) (cons (first (last list)) (rev (butlast list)))) USER: (trace rev) ; note trace
More informationHomework #2. Source code with description. Tzewen Wang ECE578 Winter 2005
Tzewen Wang ECE578 Winter 2005 Source code with description Homework #2 Homework 2 Tzewen Wang ECE578 Winter 2005 In addition to the symbols for obstacle and corridor in a labyrinth, five more symbols
More informationCommon Lisp. Blake McBride
Contents Common Lisp Blake McBride (blake@mcbride.name) 1 Data Types 2 2 Numeric Hierarchy 3 3 Comments 3 4 List Operations 4 5 Evaluation and Quotes 5 6 String Operations 5 7 Predicates 6 8 Math Predicates
More informationLisp. Versions of LISP
Lisp Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks is based on Common Lisp Scheme is one of the major
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 4. LISP: PROMĚNNÉ, DALŠÍ VLASTNOSTI FUNKCÍ, BLOKY, MAPOVACÍ FUNKCIONÁLY, ITERAČNÍ CYKLY, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší
More informationAnnouncement. Overview. LISP: A Quick Overview. Outline of Writing and Running Lisp.
Overview Announcement Announcement Lisp Basics CMUCL to be available on sun.cs. You may use GNU Common List (GCL http://www.gnu.org/software/gcl/ which is available on most Linux platforms. There is also
More informationDepartment of Computer and information Science Norwegian University of Science and Technology
Department of Computer and information Science Norwegian University of Science and Technology http://www.idi.ntnu.no/ A Crash Course in LISP MNFIT272 2002 Anders Kofod-Petersen anderpe@idi.ntnu.no Introduction
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE,
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 3. LISP: ZÁKLADNÍ FUNKCE, POUŽÍVÁNÍ REKURZE, 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti Comments in Lisp ; comments
More informationGPS: The general problem solver. developed in 1957 by Alan Newel and Herbert Simon. (H. Simon, 1957)
GPS: The general problem solver developed in 1957 by Alan Newel and Herbert Simon (H. Simon, 1957) GPS: The general problem solver developed in 1957 by Alan Newel and Herbert Simon - Was the first program
More information(defun fill-nodes (nodes texts name) (mapcar #'fill-node (replicate-nodes nodes (length texts) name) texts))
PROBLEM NOTES Critical to the problem is noticing the following: You can t always replicate just the second node passed to fill-nodes. The node to be replicated must have a common parent with the node
More informationLISP. Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits.
LISP Everything in a computer is a string of binary digits, ones and zeros, which everyone calls bits. From one perspective, sequences of bits can be interpreted as a code for ordinary decimal digits,
More informationLP/LispLite: Trivial Lisp Org Mode Conversion
LP/LispLite: Trivial Lisp Org Mode Conversion Roy M. Turner Spring 2016 Contents 1 Introduction 3 2 Using the tool 3 3 Header/miscellaneous 3 4 Variables/parameters 4 4.1 Variable: =*short-comment-start-regexp*........................
More informationCommon Lisp Object System Specification. 1. Programmer Interface Concepts
Common Lisp Object System Specification 1. Programmer Interface Concepts Authors: Daniel G. Bobrow, Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Draft Dated:
More informationCS 480. Lisp J. Kosecka George Mason University. Lisp Slides
CS 480 Lisp J. Kosecka George Mason University Lisp Slides Symbolic Programming Symbols: +, -, 1, 2 etc. Symbolic expressions: (+ 1 2), (+ (* 3 4) 2) Symbolic programs are programs that manipulate symbolic
More informationRecursion & Iteration
Recursion & Iteration York University Department of Computer Science and Engineering 1 Overview Recursion Examples Iteration Examples Iteration vs. Recursion Example [ref.: Chap 5,6 Wilensky] 2 Recursion
More informationCommon LISP Tutorial 1 (Basic)
Common LISP Tutorial 1 (Basic) CLISP Download https://sourceforge.net/projects/clisp/ IPPL Course Materials (UST sir only) Download https://silp.iiita.ac.in/wordpress/?page_id=494 Introduction Lisp (1958)
More informationImperative, OO and Functional Languages A C program is
Imperative, OO and Functional Languages A C program is a web of assignment statements, interconnected by control constructs which describe the time sequence in which they are to be executed. In Java programming,
More information1 CLWEB INTRODUCTION 1
1 CLWEB INTRODUCTION 1 1. Introduction. This is CLWEB, a literate programming system for Common Lisp by Alex Plotnick plotnick@cs.brandeis.edu. It is modeled after the CWEB system by Silvio Levy and Donald
More informationLecture #2 Kenneth W. Flynn RPI CS
Outline Programming in Lisp Lecture #2 Kenneth W. Flynn RPI CS Items from last time Recursion, briefly How to run Lisp I/O, Variables and other miscellany Lists Arrays Other data structures Jin Li lij3@rpi.edu
More informationCIS4/681 { Articial Intelligence 2 > (insert-sort '( )) ( ) 2 More Complicated Recursion So far everything we have dened requires
1 A couple of Functions 1 Let's take another example of a simple lisp function { one that does insertion sort. Let us assume that this sort function takes as input a list of numbers and sorts them in ascending
More informationFUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 5. LISP: MAKRA, DATOVÁ STRUKTURA ZÁZNAM
FUNKCIONÁLNÍ A LOGICKÉ PROGRAMOVÁNÍ 5. LISP: MAKRA, DATOVÁ STRUKTURA ZÁZNAM 2011 Jan Janoušek MI-FLP Evropský sociální fond Praha & EU: Investujeme do vaší budoucnosti MACROS Introduction to macro system
More informationAllegro CL Certification Program
Allegro CL Certification Program Lisp Programming Series Level I Review David Margolies 1 Summary 1 A lisp session contains a large number of objects which is typically increased by user-created lisp objects
More informationINF4820: Algorithms for Artificial Intelligence and Natural Language Processing. More Common Lisp
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing More Common Lisp Stephan Oepen & Murhaf Fares Language Technology Group (LTG) September 6, 2017 Agenda 2 Previously Common
More informationLecture Notes on Lisp A Brief Introduction
Why Lisp? Lecture Notes on Lisp A Brief Introduction Because it s the most widely used AI programming language Because Prof Peng likes using it Because it s good for writing production software (Graham
More informationJatha. Common Lisp in Java. Ola Bini JRuby Core Developer ThoughtWorks Studios.
Jatha Common Lisp in Java Ola Bini JRuby Core Developer ThoughtWorks Studios ola.bini@gmail.com http://olabini.com/blog Common Lisp? Common Lisp? ANSI standard Common Lisp? ANSI standard Powerful Common
More informationCOSI: Adding Constraints to the object-oriented paradigm
COSI: Adding Constraints to the object-oriented paradigm Gary Curtis, Mark Giuliano Space Telescope Science Institute, 3700 San Martin Drive, Baltimore, MD 21218 I. Overview Trans [1] is a Lisp system
More informationCommon LISP-Introduction
Common LISP-Introduction 1. The primary data structure in LISP is called the s-expression (symbolic expression). There are two basic types of s-expressions: atoms and lists. 2. The LISP language is normally
More information1 of 5 5/11/2006 12:10 AM CS 61A Spring 2006 Midterm 2 solutions 1. Box and pointer. Note: Please draw actual boxes, as in the book and the lectures, not XX and X/ as in these ASCII-art solutions. Also,
More informationINF4820: Algorithms for Artificial Intelligence and Natural Language Processing. Common Lisp Fundamentals
INF4820: Algorithms for Artificial Intelligence and Natural Language Processing Common Lisp Fundamentals Stephan Oepen & Murhaf Fares Language Technology Group (LTG) August 30, 2017 Last Week: What is
More informationSample Final Exam Questions
91.301, Organization of Programming Languages Fall 2015, Prof. Yanco Sample Final Exam Questions Note that the final is a 3 hour exam and will have more questions than this handout. The final exam will
More informationHeap storage. Dynamic allocation and stacks are generally incompatible.
Heap storage Dynamic allocation and stacks are generally incompatible. 1 Stack and heap location Pointer X points to stack storage in procedure Q's activation record that no longer is live (exists) when
More information2. Reasons for implementing clos-unit
A CLOS Implementation of the JUnit Testing Framework Architecture: A Case Study Sandro Pedrazzini Canoo Engineering AG sandro.pedrazzini@canoo.com Abstract There are different reasons why you would like
More informationLists in Lisp and Scheme
Lists in Lisp and Scheme a Lists in Lisp and Scheme Lists are Lisp s fundamental data structures, but there are others Arrays, characters, strings, etc. Common Lisp has moved on from being merely a LISt
More informationFunctional programming with Common Lisp
Functional programming with Common Lisp Dr. C. Constantinides Department of Computer Science and Software Engineering Concordia University Montreal, Canada August 11, 2016 1 / 81 Expressions and functions
More informationCMSC Introduction to Algorithms Spring 2012 Lecture 7
CMSC 351 - Introduction to Algorithms Spring 2012 Lecture 7 Instructor: MohammadTaghi Hajiaghayi Scribe: Rajesh Chitnis 1 Introduction In this lecture we give an introduction to Data Structures like arrays,
More informationArtificial Intelligence Programming
Artificial Intelligence Programming Rob St. Amant Department of Computer Science North Carolina State University Lisp basics NC State University 2 / 99 Why Lisp? Some recent Lisp success stories include
More informationUsing a waiting protocol to separate concerns in the mutual exclusion problem
Using a waiting protocol to separate concerns in the mutual exclusion problem Frode V. Fjeld frodef@cs.uit.no Department of Computer Science, University of Tromsø Technical Report 2003-46 November 21,
More informationFormal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5
Formal Methods of Software Design, Eric Hehner, segment 24 page 1 out of 5 [talking head] This lecture we study theory design and implementation. Programmers have two roles to play here. In one role, they
More informationStreams and Lazy Evaluation in Lisp
Streams and Lazy Evaluation in Lisp Overview Different models of expression evaluation Lazy vs. eager evaluation Normal vs. applicative order evaluation Computing with streams in Lisp Motivation Unix Pipes
More informationAssociative Database Managment
Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»
More informationDiscussion 2C Notes (Week 3, January 21) TA: Brian Choi Section Webpage:
Discussion 2C Notes (Week 3, January 21) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs32 Abstraction In Homework 1, you were asked to build a class called Bag. Let
More informationAssociative Database Managment WIlensky Chapter 22
Associative Database Managment WIlensky Chapter 22 DB-1 Associative Database An associative database is a collection of facts retrievable by their contents» Is a poodle a dog? Which people does Alice manage?»
More informationIntro. Scheme Basics. scm> 5 5. scm>
Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if
More informationLinked Structures. See Section 3.2 of the text.
Linked Structures See Section 3.2 of the text. First, notice that Java allows classes to be recursive, in the sense that a class can have an element which is itself an object of that class: class Person
More informationFifth Generation CS 4100 LISP. What do we need? Example LISP Program 11/13/13. Chapter 9: List Processing: LISP. Central Idea: Function Application
Fifth Generation CS 4100 LISP From Principles of Programming Languages: Design, Evaluation, and Implementation (Third Edition, by Bruce J. MacLennan, Chapters 9, 10, 11, and based on slides by Istvan Jonyer
More informationSummer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define
CS 6A Scheme Summer 207 Discussion 0: July 25, 207 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationDeferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.
Deferred operations Continuations 6.037 - Structure and Interpretation of Computer Programs Mike Phillips (define the-cons (cons 1 #f)) (set-cdr! the-cons the-cons) (define (run-in-circles l) (+
More informationFall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives
CS 6A Scheme Fall 208 Discussion 8: October 24, 208 Solutions Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write
More informationAnnouncements. Today s Menu
Announcements 1 Today s Menu Finish Introduction to ANNs (original material by Dr. Mike Nechyba) > Slides 58-60 > Adjusting the Learning Rate Loose Ends in > Lambda Expressions Review > I/O Functions >
More informationJohn McCarthy IBM 704
How this course works SI 334: Principles of Programming Languages Lecture 2: Lisp Instructor: an arowy Lots of new languages Not enough class time to cover all features (e.g., Java over the course of 34-36:
More informationMORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.
MORE SCHEME COMPUTER SCIENCE MENTORS 61A October 30 to November 3, 2017 1 What Would Scheme Print? Solutions begin on the following page. 1. What will Scheme output? Draw box-and-pointer diagrams to help
More information(defmacro while (condition &body body) `(iterate loop () (if,condition (loop)))))
; PARCIL - A Parser for C syntax In Lisp version 0.1a copyright (c) 1992 by Erann Gat, all rights reserved This program is free software; you can redistribute it and/or modify it under the terms of the
More informationScheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7
Scheme Textbook, Sections 13.1 13.3, 13.7 1 Functional Programming Based on mathematical functions Take argument, return value Only function call, no assignment Functions are first-class values E.g., functions
More informationBelow are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.
6.001, Fall Semester, 2002 Quiz II Sample solutions 1 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Computer Science 6.001 Structure and Interpretation of Computer Programs
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationCSCI337 Organisation of Programming Languages LISP
Organisation of Programming Languages LISP Getting Started Starting Common Lisp $ clisp i i i i i i i ooooo o ooooooo ooooo ooooo I I I I I I I 8 8 8 8 8 o 8 8 I \ `+' / I 8 8 8 8 8 8 \ `-+-' / 8 8 8 ooooo
More information19 Machine Learning in Lisp
19 Machine Learning in Lisp Chapter Objectives Chapter Contents ID3 algorithm and inducing decision trees from lists of examples. A basic Lisp implementation of ID3 Demonstration on a simple credit assessment
More information1. Problem Representation
Answer Key CSci 5511 Artificial Intelligence 1 October 7, 2008 Exam 1 1. Problem Representation 20 points [graded by baylor] Consider the following problem: you are given a path of N white and black squares.
More informationStructure and Interpretation of Computer Programs
CS 61A Fall 2016 Structure and Interpretation of Computer Programs Final INSTRUCTIONS You have 3 hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator, except
More informationLinked Lists and Abstract Data Structures A brief comparison
Linked Lists and Abstract Data A brief comparison 24 March 2011 Outline 1 2 3 4 Data Data structures are a key idea in programming It s just as important how you store the data as it is what you do to
More informationMIDTERM EXAMINATION - CS130 - Spring 2005
MIDTERM EAMINATION - CS130 - Spring 2005 Your full name: Your UCSD ID number: This exam is closed book and closed notes Total number of points in this exam: 231 + 25 extra credit This exam counts for 25%
More informationCustom Specializers in Object-Oriented Lisp
Custom Cadence Design Systems Goldsmiths, University of London 23rd May 2008 Common : Skill: Unification of various dialects; Not dead yet. Common Skill Internal dialect from Cadence Design Systems; Extension
More informationNST: A Unit Test Framework for Common Lisp
Smart Information Flow Technologies (SIFT, LLC) TC-lispers, June 9, 2009 Outline 1 Unit testing 2 3 The basic idea Early implementations, and other lessons How it maybe should work 4 What is unit testing?
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 17: Functional Programming Zheng (Eddy Zhang Rutgers University April 4, 2018 Class Information Homework 6 will be posted later today. All test cases
More information6.001 Notes: Section 31.1
6.001 Notes: Section 31.1 Slide 31.1.1 In previous lectures we have seen a number of important themes, which relate to designing code for complex systems. One was the idea of proof by induction, meaning
More informationMeet the Macro. a quick introduction to Lisp macros. Patrick Stein / TC Lisp Users Group /
Meet the Macro a quick introduction to Lisp macros Patrick Stein / TC Lisp Users Group / 2009-07-14 Attack Plan Some other things called macros First look at Lisp macros More advanced macros Uh-oh, my
More informationINF4820. Common Lisp: Closures and Macros
INF4820 Common Lisp: Closures and Macros Erik Velldal University of Oslo Oct. 19, 2010 Erik Velldal INF4820 1 / 22 Topics for Today More Common Lisp A quick reminder: Scope, binding and shadowing Closures
More informationThis should prevent residual sexism, racism, favoritism lurking in the unconscious of your professor & TA from biasing grading!!
NAME login: Signature: Computer Science and Engineering 150 Programming Languages for Artificial Intelligence Tuesday, November 5, 2002: DON T FORGET TO VOTE!!! FIRST MIDTERM EXAM DO NOT TURN THIS PAGE
More informationLisp Basic Example Test Questions
2009 November 30 Lisp Basic Example Test Questions 1. Assume the following forms have been typed into the interpreter and evaluated in the given sequence. ( defun a ( y ) ( reverse y ) ) ( setq a (1 2
More information/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17
01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are
More informationDocumentation for LISP in BASIC
Documentation for LISP in BASIC The software and the documentation are both Copyright 2008 Arthur Nunes-Harwitt LISP in BASIC is a LISP interpreter for a Scheme-like dialect of LISP, which happens to have
More informationImplementing Symmetric Multiprocessing in LispWorks
Implementing Symmetric Multiprocessing in LispWorks Making a multithreaded application more multithreaded Martin Simmons, LispWorks Ltd Copyright 2009 LispWorks Ltd Outline Introduction Changes in LispWorks
More informationIntroduction to Lisp
Last update: February 16, 2010 Introduction to Lisp Dana Nau Dana Nau 1 Outline I assume you know enough about computer languages that you can learn new ones quickly, so I ll go pretty fast If I go too
More informationMidterm Examination (Sample Solutions), Cmput 325
Midterm Examination (Sample Solutions, Cmput 325 [15 marks] Consider the Lisp definitions below (defun test (L S (if (null L S (let ((New (add (cdar L S (test (cdr L New (defun add (A S (if (null S (cons
More information.:: UNIT 4 ::. STACK AND QUEUE
.:: UNIT 4 ::. STACK AND QUEUE 4.1 A stack is a data structure that supports: Push(x) Insert x to the top element in stack Pop Remove the top item from stack A stack is collection of data item arrange
More informationCSCI 2210: Programming in Lisp. Progn. Block. CSCI Programming in Lisp; Instructor: Alok Mehta 1. ANSI Common Lisp, Chapters 5-10
CSCI 2210: Programming in Lisp ANSI Common Lisp, Chapters 5-10 CSCI 2210 - Programming in Lisp; Instructor: Alok Mehta; 4.ppt 1 Progn Progn Creates a block of code Expressions in body are evaluated Value
More informationA Small Interpreted Language
A Small Interpreted Language What would you need to build a small computing language based on mathematical principles? The language should be simple, Turing equivalent (i.e.: it can compute anything that
More informationCMPUT325 Extensions to Pure Lisp. Extensions to Pure Lisp. Bob Price and Russ Greiner. 5th October 2004
CMPUT325 Extensions to Pure Lisp Bob Price and Russ Greiner 5th October 2004 Bob Price and Russ Greiner CMPUT325 Extensions to Pure Lisp 1 Extensions to Pure Lisp Extensions to Pure Lisp Side Eects (setq,
More informationCS 314 Principles of Programming Languages. Lecture 16
CS 314 Principles of Programming Languages Lecture 16 Zheng Zhang Department of Computer Science Rutgers University Friday 28 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:
More informationSCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017
SCHEME 8 COMPUTER SCIENCE 61A March 2, 2017 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationTail Recursion and Accumulators
Tail Recursion and Accumulators Recursion Should now be comfortable with recursion: No harder than using a loop (Maybe?) OAen much easier than a loop When processing a tree (e.g., evaluate an arithmefc
More information6.001 Notes: Section 8.1
6.001 Notes: Section 8.1 Slide 8.1.1 In this lecture we are going to introduce a new data type, specifically to deal with symbols. This may sound a bit odd, but if you step back, you may realize that everything
More informationSummer Final Exam Review Session August 5, 2009
15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding
More informationLinked Lists, Stacks, and Queues
Department of Computer Science and Engineering Chinese University of Hong Kong In a nutshell, a data structure describes how data are stored in memory, in order to facilitate certain operations. In all
More informationSCHEME AND CALCULATOR 5b
SCHEME AND CALCULATOR 5b COMPUTER SCIENCE 6A July 25, 203 In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationAllegroCache. Reference Manual. Franz Inc. version 3.1.2
AllegroCache Reference Manual Franz Inc. version 3.1.2 AllegroCache 3.1.0 2 Table of Contents Introduction...3 Package...3 Creating persistent objects...3 Indexes...5 Maps...5 Sets...6 Transactions...7
More informationStructure and Interpretation of Computer Programs
CS 6A Fall 206 Structure and Interpretation of Computer Programs Final Solutions INSTRUCTIONS You have hours to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,
More informationData Structure. Recitation VII
Data Structure Recitation VII Recursion: Stack trace Queue Topic animation Trace Recursive factorial Executes factorial(4) Step 9: return 24 Step 8: return 6 factorial(4) Step 0: executes factorial(4)
More informationAllegro CL Certification Program
Allegro CL Certification Program Lisp Programming Series Level I Session 1.3.1 David Margolies Manipulating Lists 9/16/2010 1 What is a List? An ordered (possibly empty) collection of things in a particular
More information