Lisp Introduction

Total Page:16

File Type:pdf, Size:1020Kb

Lisp Introduction Lisp Introduction Dr. Neil T. Dantam CSCI-534, Colorado School of Mines Spring 2020 Dantam (Mines CSCI-534) Lisp Spring 2020 1 / 80 What is Lisp? Definition (Lisp) A family of programming languages based on s-expressions. Data Structure “Math” NIL ( defun factorial NIL 1 if n = 0 n! = n ∗ (n − 1)! if n 6= 0 n 1 NIL if 0 NIL Code = n ( defun f a c t ( n ) NIL ( i f (= n 0) n * NIL 1 (∗ n ( f a c t (− n 1 ) ) ) ) ) factorial 1 NIL - n Dantam (Mines CSCI-534) Lisp Spring 2020 2 / 80 Homoiconic Code is Data Code Data Structure NIL ( defun f a c t ( n ) defun factorial NIL ( i f (= n 0) n 1 (∗ n ( f a c t (− n 1 ) ) ) ) ) 1 NIL if 0 NIL = n NIL n * NIL factorial 1 NIL - n “data processing” () “code processing” Dantam (Mines CSCI-534) Lisp Spring 2020 3 / 80 Introduction Why study lisp? Outcomes I Understand Lisp abstractions I Functional Programming: I Symbols I Planning algorithms often are I S-expressions functional/recursive I First-class functions Lisp has good support for functional I (closures) programming. Implement Lisp programs in I Symbolic Computing: I functional style I Planning algorithms must often process symbolic expressions I (Review differential calculus I Lisp has good support for symbolic processing and numerical methods) I Understanding the abstractions in Lisp will make you a better programmer. Dantam (Mines CSCI-534) Lisp Spring 2020 4 / 80 The Lisp Learning Process Yee-haw! start “Lisp is weird!” “I dislike Learn to think differences!” give symbolically? not yet up yes end “Lisp is awesome!” end Lisp might feel like it’s “from outer space” (at first). The symbolic view of programming is different, often useful. Dantam (Mines CSCI-534) Lisp Spring 2020 5 / 80 Lots of Irritating Silly Parenthesis? “LISP has jokingly been described as ‘the most intelligent way to misuse a com- puter’. I think that description a great compliment because it transmits the full flavour of liberation: it has assisted a number of our most gifted fellow humans in thinking previously impossible thoughts.” [emphasis added] https://xkcd.com/297/ Dantam (Mines CSCI-534) Lisp Spring 2020 6 / 80 Common Lisp by Example Outline Common Lisp by Example Basics Recursion First-class functions Higher-order Functions Implementation Details Programming Environment Dantam (Mines CSCI-534) Lisp Spring 2020 7 / 80 Common Lisp by Example Basics Booleans and Equality “Math” Lisp Notes False nil equivalent to the empty list () True t or any non-nil value :a (not a) a = b (= a b) numerical comparison a = b (eq a b) same object a = b (eql a b) same object, same number and type, or same character a = b (equal a b) eql objects, or lists/arrays with equal elements a = b (equalp a b) = numbers, or same character (case-insensitive), or recursively-equalp cons cells, arrays, structures, hash tables a 6= b (not (= a b)) similarly for other equality functions Dantam (Mines CSCI-534) Lisp Spring 2020 8 / 80 Common Lisp by Example Basics Example: Lisp Equality Operators I (= 1 1) t I (= "a" "a") error I (eq 1 1) t I (eq "a" "a") nil integer float I (eql "a" "a") nil z}|{ z}|{ (= 1 1:0 ) t I I (equal "a" "a") t integer float z}|{ z}|{ I (equal "a" "A") nil I (eq 1 1:0 ) nil I (equalp "a" "A") t integer float z}|{ z}|{ I (not t) nil I (eql 1 1:0 ) nil (not nil) t integer float I z}|{ z}|{ I (not "a") nil I (equal 1 1:0 ) nil integer float z}|{ z}|{ I (equalp 1 1:0 ) t Dantam (Mines CSCI-534) Lisp Spring 2020 9 / 80 nil nil nil t t nil nil t nil t t Common Lisp by Example Basics Exercise: Lisp Equality Operators (eq (list "a""b") (list "a""b")) I (not 0) I (equal (list "a""b") (list "a""b")) I (not 1) I I (eq t (not nil)) I (eq t 1) I (eq (list "a""b") (list "a""B")) (eq nil (not 1)) I I (equal (list "a""b") (list "a""B")) I (eq nil (not "a")) I (equalp (list "a""b") (list "a""B")) Dantam (Mines CSCI-534) Lisp Spring 2020 10 / 80 Common Lisp by Example Basics Inequality “Math” Lisp a < b (< a b) a ≤ b (<= a b) a > b (> a b) a ≥ b (>= a b) Dantam (Mines CSCI-534) Lisp Spring 2020 11 / 80 Common Lisp by Example Basics Function Definition DEFUN Defines a new function in the global environment. (defun FUNCTION-NAME ARGUMENTS BODY...) Pseudocode Common Lisp function name function arguments Procedure increment(n) z }| { z}|{ 1 return n + 1; (defun increment (n) (+ n 1)) | {z } result Dantam (Mines CSCI-534) Lisp Spring 2020 12 / 80 ( defun sinc (theta) (/( s i n t h e t a ) t h e t a ) ) Common Lisp by Example Basics Exercise: Function Definition Sine Cardinal sin θ sinc θ = θ Pseudocode Common Lisp Procedure sinc(θ) 1 return sin(θ)/θ; What’s wrong (mathematically) with this definition? Dantam (Mines CSCI-534) Lisp Spring 2020 13 / 80 Common Lisp by Example Basics Limit of sinc θ d sin θ l’Hôpital’s rule dθ sin θ cos θ lim lim lim 1 θ!0 θ θ!0 d θ!0 1 dθ θ 1 0:5 0 −15 −10 −5 0 5 10 15 Dantam (Mines CSCI-534) Lisp Spring 2020 14 / 80 Common Lisp by Example Basics Conditional IF IF Conditional execution based on a single test: (if TEST THEN-EXPRESSION [ELSE-EXPRESSION]) Pseudocode Common Lisp Procedure even?(n) (defun even? (n) test 1 if 0 = mod(n; 2) then z }| { (if (= 0 (mod n 2)) 2 return true; then clause 3 else z}|{t 4 return false; NIL )) |{z} else clause Dantam (Mines CSCI-534) Lisp Spring 2020 15 / 80 ( defun sinc (theta) (if (= 0 theta) 1 (/( s i n t h e t a ) t h e t a ) ) ) Common Lisp by Example Basics Exercise: Conditionals IF ( 1 if θ = 0 sinc(θ) = sin θ θ if θ 6= 0 Pseudocode Common Lisp Procedure sinc(θ) 1 if 0 = θ then 2 return 1; 3 else 4 return sin(θ)/θ; Dantam (Mines CSCI-534) Lisp Spring 2020 16 / 80 Common Lisp by Example Basics Taylor Series Represent function f (x) as infinite sum of derivatives around point a: f 0(a) f 00(a) f 000(a) f (x) = f (a) + (x − a) + (x − a) + (x − a) + ::: 1! 2! 3! 1 ! X f (n)(a) = (x − a)n n! n=0 Polynomial approximation of functions Dantam (Mines CSCI-534) Lisp Spring 2020 17 / 80 Common Lisp by Example Basics Sinc Taylor Series sin θ θ2 θ4 θ6 θ8 θ10 = 1 − + − + − + ::: θ 6 120 5040 362880 39916800 2 n = 1 n = 0 n = 2 1 n = 4 n = 6 n = 8 0 n = 10 −1 −15 −10 −5 0 5 10 15 Dantam (Mines CSCI-534) Lisp Spring 2020 18 / 80 Common Lisp by Example Basics Conditional COND COND Conditional execution of the first clause with a true test: (cond CLAUSES...) where each clause is of the form: (TEST EXPRESSIONS...) Pseudocode Common Lisp Procedure sign(n) (defun sign (n) test result 1 if n > 0 then return 1 ; z }| { z}|{ (cond ((> n 0) 1 ) 2 else if n < 0 then return −1 ; test result 3 else return 0 ; z }| { z}|{ ((< n 0) −1 ) test result z}|{ (z}|{t 0 ))) Dantam (Mines CSCI-534) Lisp Spring 2020 19 / 80 ( defun sinc (theta) ( cond ((= 0 theta) 1) ((< (∗ theta theta) .00001) (+ 1 (/( expt t h e t a 2) −6) (/( expt theta 4) 120))) ( t (/ ( s i n t h e t a ) t h e t a ) ) ) ) Common Lisp by Example Basics Exercise: Conditionals COND sin θ θ2 θ4 = 1 − + + ::: θ 6 120 Pseudocode Common Lisp Procedure sinc(θ) 1 if 0 = θ then 2 return 1; 3 else if θ2 < :00001 then 4 return 1 − θ2=6 + θ4=120; 5 else 6 return sin(θ)/θ; Dantam (Mines CSCI-534) Lisp Spring 2020 20 / 80 Common Lisp by Example Recursion Recursion Example: Factorial ( 1 if n = 0 n! = Recursion: A function (or other object) defined n ∗ (n − 1)! if n 6= 0 in terms of itself Base Case: Terminating condition Procedure factorial(n) Recursive Case: Reduction towards the base case 1 if 0 = n then // base case 2 return 1; 3 else // recursive case 4 return n ∗ factorial(n − 1); Dantam (Mines CSCI-534) Lisp Spring 2020 21 / 80 Common Lisp by Example Recursion Example: Factorial ( 1 if n = 0 n! = n ∗ (n − 1)! if n 6= 0 Pseudocode Common Lisp Procedure factorial(n) ( defun factorial (n) 1 if 0 = n then // base case ( i f (= n 0) 2 return 1; 1 3 else // recursive case (∗ n (factorial (− n 1 ) ) ) ) ) 4 return n ∗ factorial(n − 1); Dantam (Mines CSCI-534) Lisp Spring 2020 22 / 80 Common Lisp by Example Recursion Factorial Execution Trace factorial(3) Procedure factorial(n) 3*factorial(2) 1 if 0 = n then // base case 2 return 1; 3*(2*factorial(1)) 3 else // recursive case 4 return n ∗ factorial(n − 1); 3*(2*(1*factorial(0))) 3*(2*(1*1)) Dantam (Mines CSCI-534) Lisp Spring 2020 23 / 80 Common Lisp by Example Recursion Factorial Call Stack fact(0) fact(1) fact(1) fact(2) fact(2) fact(2) fact(3) fact(3) fact(3) fact(3) fact(3) 3*fact(2) 3*(2*fact(1)) 3*(2*(1*fact(0))) fact(0) 1 fact(1) fact(1) 1 fact(2) fact(2) fact(2) 2 fact(3) fact(3) fact(3) fact(3) 6 3*(2*(1*1)) 3*(2*1) 3*2 6 Dantam (Mines CSCI-534) Lisp Spring 2020 24 / 80 Common Lisp by Example Recursion Exercise: Recursion, Fibonacci Sequence (1; 1; 2; 3; 5; 8; 13; 21; 34; 55;:::) 8 1 if n = 0 <> fib(n) = 1 if n = 1 :>fib(n − 1) + fib(n − 2) if n ≥ 2 Dantam (Mines CSCI-534) Lisp Spring 2020 25 / 80 Procedure fib(x) 1 if 0 = n then return 1 ; ( defun f i b ( n ) 2 else if 1 = n then return 1 ; ( cond ((= n 0) 1) 3 else ((= n 1) 1) 4 return fib(n − 1) + fib(n − 2); ( t (+ ( f i b (− n 1) ) ( f i b (− n 2 ) ) ) ) ) ) Common Lisp by Example Recursion Exercise: Recursion, Fibonacci Sequence continued Pseudocode Common Lisp Dantam (Mines CSCI-534) Lisp Spring 2020 26 / 80 Function accumulate(S) 1 if S then // Recursive Case 2 return car(S) + accumulate (cdr (S)); 3 else // Base Case 4 return 0; Common Lisp by Example Recursion Exercise: Recursion, Accumulate Iterative Recursive Function accumu- late(S) 1 a 0; 2 i 0; 3 while i < jSj do 4 a a + Si ; 5 return a; Dantam (Mines CSCI-534) Lisp Spring 2020 27 / 80 Recursive Implementation of Accumulate Function accumulate(S) 1 if S then // Recursive Case ( defun accumulate ( l i s t ) 2 return ( i f l i s t car(S) + accumulate
Recommended publications
  • Lisp Tutorial
    Gene Kim 9/9/2016 CSC 2/444 Lisp Tutorial About this Document This document was written to accompany an in-person Lisp tutorial. Therefore, the information on this document alone is not likely to be sufficient to get a good understanding of Lisp. However, the functions and operators that are listed here are a good starting point, so you may look up specifications and examples of usage for those functions in the Common Lisp HyperSpec (CLHS) to get an understanding of their usage. Getting Started Note on Common Lisp Implementations I will use Allegro Common Lisp since it is what is used by Len (and my research). However, for the purposes of this class we won’t be using many (if any) features that are specific to common lisp implementations so you may use any of the common lisp implementations available in the URCS servers. If you are using any libraries that are implementation-specific for assignments in this class, I would strongly urge you to rethink your approach if possible. If we (the TAs) deem any of these features to be solving to much of the assigned problem, you will not receive full credit for the assignment. To see if a function is in the Common Lisp specifications see the Common Lisp HyperSpec (CLHS). Simply google the function followed by “clhs” to see if an entry shows up. Available Common Lisp implementations (as far as I know): - Allegro Common Lisp (acl or alisp will start an Allegro REPL) - CMU Common Lisp (cmucl or lisp will start a CMUCL REPL) - Steel Bank Common Lisp (sbcl will start an SBCL REPL) IDE/Editor It is not important for this class to have an extensive IDE since we will be working on small coding projects.
    [Show full text]
  • Common Lisp - Viel Mehr Als Nur D¨Amliche Klammern
    Einf¨uhrung Geschichtliches Die Programmiersprache Abschluß Common Lisp - viel mehr als nur d¨amliche Klammern Alexander Schreiber <[email protected]> http://www.thangorodrim.de Chemnitzer Linux-Tage 2005 Greenspun’s Tenth Rule of Programming: “Any sufficiently-complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp.” Alexander Schreiber <[email protected]> Common Lisp - viel mehr als nur d¨amliche Klammern 1 / 30 Einf¨uhrung Geschichtliches Die Programmiersprache Abschluß Ubersicht¨ 1 Einf¨uhrung 2 Geschichtliches 3 Die Programmiersprache 4 Abschluß Alexander Schreiber <[email protected]> Common Lisp - viel mehr als nur d¨amliche Klammern 2 / 30 Einf¨uhrung Geschichtliches Die Programmiersprache Abschluß Lisp? Wof¨ur? NASA: Remote Agent (Deep Space 1), Planner (Mars Pathfinder), Viaweb, gekauft von Yahoo f¨ur50 Millionen $, ITA Software: Orbitz engine (Flugticket Planung), Square USA: Production tracking f¨ur“Final Fantasy”, Naughty Dog Software: Crash Bandicoot auf Sony Playstation, AMD & AMI: Chip-Design & Verifizierung, typischerweise komplexe Probleme: Wissensverarbeitung, Expertensysteme, Planungssysteme Alexander Schreiber <[email protected]> Common Lisp - viel mehr als nur d¨amliche Klammern 3 / 30 Einf¨uhrung Geschichtliches Die Programmiersprache Abschluß Lisp? Wof¨ur? NASA: Remote Agent (Deep Space 1), Planner (Mars Pathfinder), Viaweb, gekauft von Yahoo f¨ur50 Millionen $, ITA Software: Orbitz engine (Flugticket Planung), Square USA: Production tracking
    [Show full text]
  • Advanced Use of Lisp's FORMAT Function
    Advanced Use of Lisp’s FORMAT Function Gene Michael Stover created 22 January 2004 updated Saturday, 30 October 2004 Copyright c 2004 Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted. Contents 1 Introduction 1 2 Wanted & To Do 2 3 How to Print a Row 2 4 How to Print a Table 3 5 How to Use Format for Word Wrap 4 6 How to Print a Comma-Separated List 6 7 HowtoUseCommasinEnglishStyle 7 8 Conclusion 7 A Change Log 8 B Other File Formats 8 1 Introduction Lisp’s format function is analogous to C’s printf function, but format can do a whole lot more. format can iterate, use conditionals, process nested format strings, & recurse into format strings embedded into its arguments. The more-or-less official documentation for format is at the Common Lisp Hyperspec[X3J]. There is a complete if terse description of it in Paul Graham’s ANSI Common Lisp[Gra96], but my favorite description of format is in Franz’s Common Lisp The Reference[Inc88]. 1 Knowing the details of how something works isn’t the same as knowing how to use it well. Good applications of format aren’t obvious from its documentation. Thus this article. 2 Wanted & To Do Read the original article about format[Wat89]. Possibly incorporate ideas from it, or refer to them. Definitely refer to it in this article so people know it exists. (I didn’t know it existed at all even though I searched the web for such articles before I wrote this one.
    [Show full text]
  • Memory Pool System Documentation Release 1.111.0
    Memory Pool System Documentation Release 1.111.0 Ravenbrook Limited May 23, 2013 CONTENTS i ii CHAPTER ONE GUIDE 1.1 Overview of the Memory Pool System The Memory Pool System is a very general, adaptable, flexible, reliable, and efficient memory management system. It permits the flexible combination of memory management techniques, supporting manual and automatic memory management, inline allocation, finalization, weakness, and multiple concurrent co-operating incremental generational garbage collections. It also includes a library of memory pool classes implementing specialized memory management policies. The MPS has been in development since 1994 and deployed in successful commercial products since 1997. Bugs are almost unknown in production. It is under continuous development and support by Ravenbrook. The MPS is distributed under an open source license. The license is designed to make it possible for you to use the MPS in your own projects, provided that you either don’t distribute your product, or your product is open source too. If the licensing terms aren’t suitable for you (for example, you’re developing a closed-source commercial product or a compiler run-time system) you can easily license the MPS under different terms from Ravenbrook by arrangement. Please contact us at [email protected] for details. 1.1.1 Supported target platforms The MPS is currently supported for deployment on: • Windows XP or later on IA-32 and x86-64, using Microsoft Visual C/C++; • Linux (Ubuntu 11 and RHEL 6.3 known good, otherwise YMMV) on IA-32 and x86-64, using GCC; • FreeBSD 7 or later, on IA-32 and x86-64, using GCC; • OS X 10.4 or later, on IA-32 and x86-64 (single threaded only), using Clang/LLVM.
    [Show full text]
  • Objektové Programování Poznámky K Přednášce
    Objektové programování Poznámky k přednášce Michal Krupka 18. prosince 2016 1 Obsah 1 Od Scheme k Lispu 7 1.1 Základní rozdíly mezi Schemem a Common Lispem . 8 1.2 Common Lisp: základní výbava . 14 2 Objekty a třídy 37 2.1 Základní pojmy ........................... 37 2.2 Třídy a instance v Common Lispu . 40 2.3 Inicializace slotů nových instancí . 49 ÚLOHY ................................... 52 3 Zapouzdření a polymorfismus 55 3.1 Princip zapouzdření ........................ 55 3.2 Úprava tříd point a circle ................... 61 3.3 Třída picture ........................... 64 3.4 Vlastnosti ............................... 67 3.5 Kreslení pomocí knihovny micro-graphics . 68 3.6 Kreslení grafických objektů .................... 72 3.7 Princip polymorfismu ....................... 81 3.8 Polygony ............................... 83 3.9 Geometrické transformace ..................... 87 ÚLOHY ................................... 89 4 Dědičnost 91 4.1 Princip dědičnosti a pravidlo is-a . 91 4.2 Určení předka v definici třídy ................... 98 4.3 Poznámka o běžných jazycích . 102 4.4 Přepisování metod . 102 4.5 Volání zděděné metody . 104 4.6 Inicializace instancí . 110 3 4 OBSAH 4.7 Návrh stromu dědičnosti . 111 ÚLOHY ................................... 112 5 Zpětná volání 115 5.1 Zpětná volání v knihovně micro-graphics . 115 5.2 Překreslování oken po vnější změně . 117 5.3 Překreslení při změně okna . 118 5.4 Překreslování při změnách objektů . 120 ÚLOHY ................................... 124 6 Klikání a jiné události 127 6.1 Jednoduché obsloužení vstupu z myši . 127 6.2 Zpravení grafického objektu o kliknutí . 129 6.3 Princip vlastnění, delegování, události . 133 6.4 Události ev-changing a ev-change . 136 6.5 Reakce na kliknutí: událost ev-mouse-down . 140 ÚLOHY ..................................
    [Show full text]
  • Clarification Proposal for CLHS Section 22.3 Version 1.1
    Clarification Proposal for CLHS Section 22.3 Version 1.1 Didier Verna <[email protected]> Copyright c 2011 Didier Verna Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided also that the section entitled \Copy- ing" is included exactly as in the original. Permission is granted to copy and distribute translations of this manual into an- other language, under the above conditions for modified versions, except that this permission notice may be translated as well. Copying 1 Copying This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3 of this license or (at your option) any later version. The latest version of this license is in http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later. This work has the LPPL maintenance status `maintained'. The Current Maintainer of this work is Didier Verna. Chapter 1: Motivation 2 1 Motivation Section 22.3 \Formatted Output" of the Common Lisp Hyperspec describes the syntax and semantics of format directives. We believe that the standard is underspecified in two related areas. 1.1 Trailing Commas The standard describes the syntax of directive parameters as follows. A directive consists of a tilde, optional prefix parameters separated by commas, [...]. ¨ It also gives the following example.
    [Show full text]
  • Automating Iterative Tasks with Programming by Demonstration
    http://waikato.researchgateway.ac.nz/ Research Commons at the University of Waikato Copyright Statement: The digital copy of this thesis is protected by the Copyright Act 1994 (New Zealand). The thesis may be consulted by you, provided you comply with the provisions of the Act and the following conditions of use: Any use you make of these documents or images must be for research or private study purposes only, and you may not make them available to any other person. Authors control the copyright of their thesis. You will recognise the author’s right to be identified as the author of the thesis, and due acknowledgement will be made to the author where appropriate. You will obtain the author’s permission before publishing any material from the thesis. Department of Computer Science Hamilton, New Zealand Automating iterative tasks with programming by demonstration Gordon W. Paynter This thesis is submitted in partial fulfilment of the requirements for the degree of Doctor of Philosophy at The University of Waikato. February 26, 2000 © 2000 Gordon W. Paynter Abstract iii Abstract Programming by demonstration is an end-user programming technique that allows people to create programs by showing the computer examples of what they want to do. Users do not need specialised programming skills. Instead, they instruct the computer by demonstrating examples, much as they might show another person how to do the task. Programming by demonstration empowers users to create programs that perform tedious and time-consuming computer chores. However, it is not in widespread use, and is instead confined to research applications that end users never see.
    [Show full text]
  • Common Lisp Reference Manual the Common Lisp Reference Manual Copyright C 2006 Robert Strandh
    Common Lisp Reference Manual The Common Lisp Reference Manual Copyright c 2006 Robert Strandh. i Table of Contents 1 Introduction............................... 1 2 Terminology and conventions ............... 2 2.1 Introduction ................................................ 2 2.2 General..................................................... 2 3 Numbers .................................. 3 3.1 Introduction ................................................ 3 4 Cons cells ................................. 4 5 Sequences ................................. 5 5.1 Introduction ................................................ 5 5.2 Lists ....................................................... 5 5.2.1 Standard functions, macros, and special operators on lists.. 5 5.3 Vectors ..................................................... 5 6 Structures ................................. 6 7 Generalized references ..................... 7 8 Standard functions, macros, and special operators................................. 8 car ........................................................ 8 cdr ........................................................ 8 9 Standard types and classes ................. 9 Index ....................................... 10 Chapter 1: Introduction 1 1 Introduction You are reading the Common Lisp Reference Manual. The purpose of this document is to be a complete discription of all of ANSI Common Lisp. It differs from the Common Lisp standard or the Common Lisp HyperSpec, in that it is completely free (though I haven’t figured out the details
    [Show full text]
  • Common Lisp: a Brief Tutorial August 2004
    Common Lisp: A Brief Tutorial August 2004 David R. Pierce Stuart C. Shapiro Copyright c 2004 David R. Pierce and Stuart C. Shapiro Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be obtained from the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. i Table of Contents 1 Basics ..................................... 1 1.1 Introduction ............................................ 1 1.2 Syntax ................................................. 1 1.3 Read-Eval-Print ......................................... 1 1.4 Evaluation .............................................. 2 1.5 Comments .............................................. 3 1.6 Running Programs ...................................... 3 2 Data Types................................ 4 2.1 Booleans ............................................... 4 2.2 Numbers ............................................... 4 2.3 Functions ............................................... 5 2.4 Characters .............................................. 6 2.5 Strings ................................................. 6 2.6 Symbols ................................................ 7 2.7 Packages................................................ 8 2.8 Lists ................................................... 9 2.9 Objects...............................................
    [Show full text]
  • A Web-Based, Pac-Man-Complete Hybrid Text and Visual Programming Language
    Politechnika Łódzka Wydział Fizyki Technicznej, Informatyki i Matematyki Stosowanej Instytut Informatyki Dariusz Jędrzejczak, 201208 Dual: a web-based, Pac-Man-complete hybrid text and visual programming language Praca magisterska napisana pod kierunkiem dr inż. Jana Stolarka Łódź 2016 ii Contents Contents iii 0 Introduction 1 0.1 Scope . .1 0.2 Choice of subject . .1 0.3 Related work . .2 0.4 Goals . .3 0.5 Structure . .3 1 Background 5 1.1 Web technologies . .5 1.1.1 Document Object Model . .5 1.1.2 JavaScript . .6 1.2 Design and implementation of Lisp . .8 1.2.1 Abstract syntax tree and program representation . 10 1.2.2 Text-based code editors . 10 1.2.3 Visual programming languages . 11 1.2.4 A note on history of VPLs . 13 1.2.5 Common criticisms of VPLs . 14 1.2.6 The problem with structure . 14 1.3 Screenshots . 16 2 Dual programming language 21 2.1 Introduction . 21 2.2 Syntax and grammar . 21 2.2.1 Basic syntax . 22 2.3 Comments . 23 2.4 Numbers . 24 2.5 Escape character . 25 2.6 Strings . 25 2.7 Basic primitives and built-ins . 25 2.7.1 Functions . 26 2.7.2 Language primitives . 27 2.7.3 Values . 30 2.8 Enhanced Syntax Tree . 31 iii CONTENTS CONTENTS 2.8.1 Structural representation of strings . 32 2.9 Syntax sugar for function invocations . 33 2.10 Pattern matching . 34 2.10.1 Destructuring . 36 2.10.2 match primitive . 36 2.11 Rest parameters and spread operator .
    [Show full text]
  • Projet De Programmation 3
    Projet de Programmation 3 Cours : Ir`ene Durand TD : Ir`ene Durand, Richard Moussa, Kaninda Musumbu (2 groupes) Semaines Cours mercredi 9h30-10h50, 2-7 9-10 Amphi A29 TD 12 s´eances de 1h20 5-7 9 10 12 1 Devoir surveill´emercredi 9h30-11h 11 Amphi A29 1 Projet surveill´e 9 `a13 Le devoir surveill´eET le projet surveill´esont obligatoires. Support de cours : transparents et exemples disponibles sur page Web http://dept-info.labri.u-bordeaux.fr/~idurand/enseignement/PP3/ 1 Bibliographie Peter Seibel Practical Common Lisp Apress Paul Graham : ANSI Common Lisp Prentice Hall Paul Graham : On Lisp Advanced Techniques for Common Lisp Prentice Hall Robert Strandh et Ir`ene Durand Trait´ede programmation en Common Lisp M´etaModulaire Sonya Keene : Object-Oriented Programming in Common Lisp A programmer’s guide to CLOS Addison Wesley Peter Norvig : Paradigms of Artificial Intelligence Programming Case Studies in Common Lisp Morgan Kaufmann 2 Autres documents The HyperSpec (la norme ANSI compl`ete de Common Lisp, en HTML) http://www.lispworks.com/documentation/HyperSpec/Front/index.htm SBCL User Manual CLX reference manual (Common Lisp X Interface) Common Lisp Interface Manager (CLIM) http://bauhh.dyndns.org:8000/clim-spec/index.html Guy Steele : Common Lisp, the Language, second edition Digital Press, (disponible sur WWW en HTML) David Lamkins : Successful Lisp (Tutorial en-ligne) 3 Objectifs et contenu Passage `al’´echelle – Appr´ehender les probl`emes relatifs `ala r´ealisation d’un vrai projet – Installation et utilisation de biblioth`eques existantes – Biblioth`eque graphique (mcclim) – Cr´eation de biblioth`eques r´eutilisables – Modularit´e, API (Application Programming Interface) ou Interface de Programmation – Utilisation de la Programmation Objet – Entr´ees/Sorties (flots, acc`es au syst`eme de fichiers) – Gestion des exceptions 4 Paquetages (Packages) Supposons qu’on veuille utiliser un syst`eme (une biblioth`eque) (la biblioth`eque graphique McCLIM par exemple).
    [Show full text]
  • Evolution of Emacs Lisp
    Evolution of Emacs Lisp STEFAN MONNIER, Universit´ede Montr´eal,Canada MICHAEL SPERBER, Active Group GmbH, Germany While Emacs proponents largely agree that it is the world's greatest text editor, it is almost as much a Lisp machine disguised as an editor. Indeed, one of its chief appeals is that it is programmable via its own programming language, Elisp (or Emacs Lisp), a Lisp in the classic tradition. In this article, we present the history of this language over its more than 30 years of evolution. Its core has remained remarkably stable since its inception in 1985, in large part to preserve compatibility with the many third-party packages providing a multitude of extensions. Still, Elisp has evolved and continues to do so. Despite the fact that it is closely tied to a concrete editor, Elisp has spawned multiple implementations| in Emacs itself but also in variants of Emacs, such as XEmacs, Edwin, and even the window manager Sawfish. Through competing implementations as well as changes in maintainership, it has pickedup outside influences over the years, most notably from Common Lisp. Important aspects of Elisp have been shaped by concrete requirements of the editor it supports, such as the buffer-local variables that tie bindings to editing contexts, as well as implementation constraints. These requirements led to the choice of a Lisp dialect as Emacs's language in the first place, specifically its simplicity and dynamic nature: Loading additional Emacs packages or changing the ones in place occurs frequently, and having to restart the editor in order to re-compile or re-link the code would be unacceptable.
    [Show full text]