SBCL User Manual SBCL Version 1.4.5 2018-02 This Manual Is Part of the SBCL Software System

Total Page:16

File Type:pdf, Size:1020Kb

SBCL User Manual SBCL Version 1.4.5 2018-02 This Manual Is Part of the SBCL Software System SBCL User Manual SBCL version 1.4.5 2018-02 This manual is part of the SBCL software system. See the README file for more infor- mation. This manual is largely derived from the manual for the CMUCL system, which was produced at Carnegie Mellon University and later released into the public domain. This manual is in the public domain and is provided with absolutely no warranty. See the COPYING and CREDITS files for more information. i Table of Contents 1 Getting Support and Reporting Bugs :::::::::::::::::::::::::: 1 1.1 Volunteer Support :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.2 Commercial Support :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.3 Reporting Bugs ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.3.1 How to Report Bugs Effectively :::::::::::::::::::::::::::::::::::::::::::::::::: 1 1.3.2 Signal Related Bugs:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 2 2 Introduction :::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 2.1 ANSI Conformance ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 2.2 Extensions:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 2.3 Idiosyncrasies ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 2.3.1 Declarations ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 2.3.2 FASL Format :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 2.3.3 Compiler-only Implementation ::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.3.4 Defining Constants::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.3.5 Style Warnings::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 2.4 Development Tools:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.4.1 Editor Integration:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.4.2 Language Reference :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.4.3 Generating Executables :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.5 More SBCL Information :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.5.1 SBCL Homepage::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.5.2 Online Documentation ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 2.5.3 Additional Documentation Files :::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.5.4 Internals Documentation ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.6 More Common Lisp Information :::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.6.1 Internet Community ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.6.2 Third-party Libraries :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.6.3 Common Lisp Books ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 2.7 History and Implementation of SBCL ::::::::::::::::::::::::::::::::::::::::::::::::: 8 3 Starting and Stopping :::::::::::::::::::::::::::::::::::::::::: 10 3.1 Starting SBCL::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.1.1 From Shell to Lisp :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.1.2 Running from Emacs ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.1.3 Shebang Scripts::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.2 Stopping SBCL :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.2.1 Exit :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 10 3.2.2 End of File ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 3.2.3 Saving a Core Image :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 3.2.4 Exit on Errors :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 3.3 Command Line Options:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 13 3.3.1 Runtime Options ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 14 3.3.2 Toplevel Options:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 14 3.4 Initialization Files ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 3.5 Initialization and Exit Hooks :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 16 ii 4 Compiler ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 17 4.1 Diagnostic Messages ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 17 4.1.1 Controlling Verbosity ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 17 4.1.2 Diagnostic Severity ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 18 4.1.3 Understanding Compile Diagnostics ::::::::::::::::::::::::::::::::::::::::::::: 18 4.1.3.1 The Parts of a Compiler Diagnostic :::::::::::::::::::::::::::::::::::::::: 18 4.1.3.2 The Original and Actual Source :::::::::::::::::::::::::::::::::::::::::::: 20 4.1.3.3 The Processing Path ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 20 4.2 Handling of Types ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 4.2.1 Declarations as Assertions :::::::::::::::::::::::::::::::::::::::::::::::::::::: 21 4.2.2 Precise Type Checking :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 22 4.2.3 Getting Existing Programs to Run :::::::::::::::::::::::::::::::::::::::::::::: 22 4.2.4 Implementation Limitations ::::::::::::::::::::::::::::::::::::::::::::::::::::: 24 4.3 Compiler Policy ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 24 4.4 Compiler Errors ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 26 4.4.1 Type Errors at Compile Time ::::::::::::::::::::::::::::::::::::::::::::::::::: 26 4.4.2 Errors During Macroexpansion :::::::::::::::::::::::::::::::::::::::::::::::::: 27 4.4.3 Read Errors :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 27 4.5 Open Coding and Inline Expansion :::::::::::::::::::::::::::::::::::::::::::::::::: 27 4.6 Interpreter::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 28 5 Debugger :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 5.1 Debugger Entry ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 5.1.1 Debugger Banner ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 5.1.2 Debugger Invocation :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 29 5.2 Debugger Command Loop ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 5.3 Stack Frames :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 5.3.1 Stack Motion ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 5.3.2 How Arguments are Printed::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 5.3.3 Function Names :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 5.3.3.1 Entry Point Details :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 32 5.3.4 Debug Tail Recursion ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 32 5.3.5 Unknown Locations and Interrupts :::::::::::::::::::::::::::::::::::::::::::::: 32 5.4 Variable Access :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 33 5.4.1 Variable Value Availability :::::::::::::::::::::::::::::::::::::::::::::::::::::: 33 5.4.2 Note On Lexical Variable Access :::::::::::::::::::::::::::::::::::::::::::::::: 34 5.5 Source Location Printing :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 34 5.5.1 How the Source is Found:::::::::::::::::::::::::::::::::::::::::::::::::::::::: 35 5.5.2 Source Location Availability :::::::::::::::::::::::::::::::::::::::::::::::::::: 36 5.6 Debugger Policy Control ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 36 5.7 Exiting Commands :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 37 5.8 Information Commands :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 38 5.9 Function Tracing :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 38 5.10 Single Stepping ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 40 5.11 Enabling and Disabling the Debugger ::::::::::::::::::::::::::::::::::::::::::::::: 40 6 Efficiency :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 6.1 Slot access::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 6.1.1 Structure object slot access ::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 6.1.2 Standard object slot access:::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 6.2 Dynamic-extent allocation ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 6.3 Modular arithmetic :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 43 iii 6.4 Global and Always-Bound variables :::::::::::::::::::::::::::::::::::::::::::::::::: 44 6.5 Miscellaneous Efficiency Issues ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 44 7 Beyond the ANSI Standard :::::::::::::::::::::::::::::::::::: 46 7.1 Reader Extensions ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 46 7.2 Package-Local Nicknames :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 46 7.3 Package Variance :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 47 7.4 Garbage Collection :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48 7.4.1 Finalization::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48 7.4.2 Weak
Recommended publications
  • Technical Standard
    Technical Standard X/Open Curses, Issue 7 The Open Group ©November 2009, The Open Group All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the copyright owners. Technical Standard X/Open Curses, Issue 7 ISBN: 1-931624-83-6 Document Number: C094 Published in the U.K. by The Open Group, November 2009. This standardhas been prepared by The Open Group Base Working Group. Feedback relating to the material contained within this standardmay be submitted by using the web site at http://austingroupbugs.net with the Project field set to "Xcurses Issue 7". ii Technical Standard 2009 Contents Chapter 1 Introduction........................................................................................... 1 1.1 This Document ........................................................................................ 1 1.1.1 Relationship to Previous Issues ......................................................... 1 1.1.2 Features Introduced in Issue 7 ........................................................... 2 1.1.3 Features Withdrawn in Issue 7........................................................... 2 1.1.4 Features Introduced in Issue 4 ........................................................... 2 1.2 Conformance............................................................................................ 3 1.2.1 Base Curses Conformance .................................................................
    [Show full text]
  • Modern Programming Languages CS508 Virtual University of Pakistan
    Modern Programming Languages (CS508) VU Modern Programming Languages CS508 Virtual University of Pakistan Leaders in Education Technology 1 © Copyright Virtual University of Pakistan Modern Programming Languages (CS508) VU TABLE of CONTENTS Course Objectives...........................................................................................................................4 Introduction and Historical Background (Lecture 1-8)..............................................................5 Language Evaluation Criterion.....................................................................................................6 Language Evaluation Criterion...................................................................................................15 An Introduction to SNOBOL (Lecture 9-12).............................................................................32 Ada Programming Language: An Introduction (Lecture 13-17).............................................45 LISP Programming Language: An Introduction (Lecture 18-21)...........................................63 PROLOG - Programming in Logic (Lecture 22-26) .................................................................77 Java Programming Language (Lecture 27-30)..........................................................................92 C# Programming Language (Lecture 31-34) ...........................................................................111 PHP – Personal Home Page PHP: Hypertext Preprocessor (Lecture 35-37)........................129 Modern Programming Languages-JavaScript
    [Show full text]
  • An Implementation of Python for Racket
    An Implementation of Python for Racket Pedro Palma Ramos António Menezes Leitão INESC-ID, Instituto Superior Técnico, INESC-ID, Instituto Superior Técnico, Universidade de Lisboa Universidade de Lisboa Rua Alves Redol 9 Rua Alves Redol 9 Lisboa, Portugal Lisboa, Portugal [email protected] [email protected] ABSTRACT Keywords Racket is a descendent of Scheme that is widely used as a Python; Racket; Language implementations; Compilers first language for teaching computer science. To this end, Racket provides DrRacket, a simple but pedagogic IDE. On the other hand, Python is becoming increasingly popular 1. INTRODUCTION in a variety of areas, most notably among novice program- The Racket programming language is a descendent of Scheme, mers. This paper presents an implementation of Python a language that is well-known for its use in introductory for Racket which allows programmers to use DrRacket with programming courses. Racket comes with DrRacket, a ped- Python code, as well as adding Python support for other Dr- agogic IDE [2], used in many schools around the world, as Racket based tools. Our implementation also allows Racket it provides a simple and straightforward interface aimed at programs to take advantage of Python libraries, thus signif- inexperienced programmers. Racket provides different lan- icantly enlarging the number of usable libraries in Racket. guage levels, each one supporting more advanced features, that are used in different phases of the courses, allowing Our proposed solution involves compiling Python code into students to benefit from a smoother learning curve. Fur- semantically equivalent Racket source code. For the run- thermore, Racket and DrRacket support the development of time implementation, we present two different strategies: additional programming languages [13].
    [Show full text]
  • About ILE C/C++ Compiler Reference
    IBM i 7.3 Programming IBM Rational Development Studio for i ILE C/C++ Compiler Reference IBM SC09-4816-07 Note Before using this information and the product it supports, read the information in “Notices” on page 121. This edition applies to IBM® Rational® Development Studio for i (product number 5770-WDS) and to all subsequent releases and modifications until otherwise indicated in new editions. This version does not run on all reduced instruction set computer (RISC) models nor does it run on CISC models. This document may contain references to Licensed Internal Code. Licensed Internal Code is Machine Code and is licensed to you under the terms of the IBM License Agreement for Machine Code. © Copyright International Business Machines Corporation 1993, 2015. US Government Users Restricted Rights – Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents ILE C/C++ Compiler Reference............................................................................... 1 What is new for IBM i 7.3.............................................................................................................................3 PDF file for ILE C/C++ Compiler Reference.................................................................................................5 About ILE C/C++ Compiler Reference......................................................................................................... 7 Prerequisite and Related Information..................................................................................................
    [Show full text]
  • The Machine That Builds Itself: How the Strengths of Lisp Family
    Khomtchouk et al. OPINION NOTE The Machine that Builds Itself: How the Strengths of Lisp Family Languages Facilitate Building Complex and Flexible Bioinformatic Models Bohdan B. Khomtchouk1*, Edmund Weitz2 and Claes Wahlestedt1 *Correspondence: [email protected] Abstract 1Center for Therapeutic Innovation and Department of We address the need for expanding the presence of the Lisp family of Psychiatry and Behavioral programming languages in bioinformatics and computational biology research. Sciences, University of Miami Languages of this family, like Common Lisp, Scheme, or Clojure, facilitate the Miller School of Medicine, 1120 NW 14th ST, Miami, FL, USA creation of powerful and flexible software models that are required for complex 33136 and rapidly evolving domains like biology. We will point out several important key Full list of author information is features that distinguish languages of the Lisp family from other programming available at the end of the article languages and we will explain how these features can aid researchers in becoming more productive and creating better code. We will also show how these features make these languages ideal tools for artificial intelligence and machine learning applications. We will specifically stress the advantages of domain-specific languages (DSL): languages which are specialized to a particular area and thus not only facilitate easier research problem formulation, but also aid in the establishment of standards and best programming practices as applied to the specific research field at hand. DSLs are particularly easy to build in Common Lisp, the most comprehensive Lisp dialect, which is commonly referred to as the “programmable programming language.” We are convinced that Lisp grants programmers unprecedented power to build increasingly sophisticated artificial intelligence systems that may ultimately transform machine learning and AI research in bioinformatics and computational biology.
    [Show full text]
  • Bringing GNU Emacs to Native Code
    Bringing GNU Emacs to Native Code Andrea Corallo Luca Nassi Nicola Manca [email protected] [email protected] [email protected] CNR-SPIN Genoa, Italy ABSTRACT such a long-standing project. Although this makes it didactic, some Emacs Lisp (Elisp) is the Lisp dialect used by the Emacs text editor limitations prevent the current implementation of Emacs Lisp to family. GNU Emacs can currently execute Elisp code either inter- be appealing for broader use. In this context, performance issues preted or byte-interpreted after it has been compiled to byte-code. represent the main bottleneck, which can be broken down in three In this work we discuss the implementation of an optimizing com- main sub-problems: piler approach for Elisp targeting native code. The native compiler • lack of true multi-threading support, employs the byte-compiler’s internal representation as input and • garbage collection speed, exploits libgccjit to achieve code generation using the GNU Com- • code execution speed. piler Collection (GCC) infrastructure. Generated executables are From now on we will focus on the last of these issues, which con- stored as binary files and can be loaded and unloaded dynamically. stitutes the topic of this work. Most of the functionality of the compiler is written in Elisp itself, The current implementation traditionally approaches the prob- including several optimization passes, paired with a C back-end lem of code execution speed in two ways: to interface with the GNU Emacs core and libgccjit. Though still a work in progress, our implementation is able to bootstrap a func- • Implementing a large number of performance-sensitive prim- tional Emacs and compile all lexically scoped Elisp files, including itive functions (also known as subr) in C.
    [Show full text]
  • Technical Study Desktop Internationalization
    Technical Study Desktop Internationalization NIC CH A E L T S T U D Y [This page intentionally left blank] X/Open Technical Study Desktop Internationalisation X/Open Company Ltd. December 1995, X/Open Company Limited All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the copyright owners. X/Open Technical Study Desktop Internationalisation X/Open Document Number: E501 Published by X/Open Company Ltd., U.K. Any comments relating to the material contained in this document may be submitted to X/Open at: X/Open Company Limited Apex Plaza Forbury Road Reading Berkshire, RG1 1AX United Kingdom or by Electronic Mail to: [email protected] ii X/Open Technical Study (1995) Contents Chapter 1 Internationalisation.............................................................................. 1 1.1 Introduction ................................................................................................. 1 1.2 Character Sets and Encodings.................................................................. 2 1.3 The C Programming Language................................................................ 5 1.4 Internationalisation Support in POSIX .................................................. 6 1.5 Internationalisation Support in the X/Open CAE............................... 7 1.5.1 XPG4 Facilities.........................................................................................
    [Show full text]
  • Common Lispworks User Guide
    LispWorks® for the Windows® Operating System Common LispWorks User Guide Version 5.1 Copyright and Trademarks Common LispWorks User Guide (Windows version) Version 5.1 February 2008 Copyright © 2008 by LispWorks Ltd. All Rights Reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of LispWorks Ltd. The information in this publication is provided for information only, is subject to change without notice, and should not be construed as a commitment by LispWorks Ltd. LispWorks Ltd assumes no responsibility or liability for any errors or inaccuracies that may appear in this publication. The software described in this book is furnished under license and may only be used or copied in accordance with the terms of that license. LispWorks and KnowledgeWorks are registered trademarks of LispWorks Ltd. Adobe and PostScript are registered trademarks of Adobe Systems Incorporated. Other brand or product names are the registered trade- marks or trademarks of their respective holders. The code for walker.lisp and compute-combination-points is excerpted with permission from PCL, Copyright © 1985, 1986, 1987, 1988 Xerox Corporation. The XP Pretty Printer bears the following copyright notice, which applies to the parts of LispWorks derived therefrom: Copyright © 1989 by the Massachusetts Institute of Technology, Cambridge, Massachusetts. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, pro- vided that this copyright and permission notice appear in all copies and supporting documentation, and that the name of M.I.T.
    [Show full text]
  • How Lisp Systems Look Different in Proceedings of European Conference on Software Maintenance and Reengineering (CSMR 2008)
    How Lisp Systems Look Different In Proceedings of European Conference on Software Maintenance and Reengineering (CSMR 2008) Adrian Dozsa Tudor Gˆırba Radu Marinescu Politehnica University of Timis¸oara University of Berne Politehnica University of Timis¸oara Romania Switzerland Romania [email protected] [email protected] [email protected] Abstract rently used in a variety of domains, like bio-informatics (BioBike), data mining (PEPITe), knowledge-based en- Many reverse engineering approaches have been devel- gineering (Cycorp or Genworks), video games (Naughty oped to analyze software systems written in different lan- Dog), flight scheduling (ITA Software), natural language guages like C/C++ or Java. These approaches typically processing (SRI International), CAD (ICAD or OneSpace), rely on a meta-model, that is either specific for the language financial applications (American Express), web program- at hand or language independent (e.g. UML). However, one ming (Yahoo! Store or reddit.com), telecom (AT&T, British language that was hardly addressed is Lisp. While at first Telecom Labs or France Telecom R&D), electronic design sight it can be accommodated by current language inde- automation (AMD or American Microsystems) or planning pendent meta-models, Lisp has some unique features (e.g. systems (NASA’s Mars Pathfinder spacecraft mission) [16]. macros, CLOS entities) that are crucial for reverse engi- neering Lisp systems. In this paper we propose a suite of Why Lisp is Different. In spite of its almost fifty-year new visualizations that reveal the special traits of the Lisp history, and of the fact that other programming languages language and thus help in understanding complex Lisp sys- borrowed concepts from it, Lisp still presents some unique tems.
    [Show full text]
  • Synchronizing Threads with POSIX Semaphores
    3/17/2016 POSIX Semaphores Synchronizing Threads with POSIX Semaphores 1. Why semaphores? 2. Posix semaphores are easy to use sem_init sem_wait sem_post sem_getvalue sem_destroy 3. Activities 1 2 Now it is time to take a look at some code that does something a little unexpected. The program badcnt.c creates two new threads, both of which increment a global variable called cnt exactly NITER, with NITER = 1,000,000. But the program produces unexpected results. Activity 1. Create a directory called posixsem in your class Unix directory. Download in this directory the code badcnt.c and compile it using gcc badcnt.c -o badcnt -lpthread Run the executable badcnt and observe the ouput. Try it on both tanner and felix. Quite unexpected! Since cnt starts at 0, and both threads increment it NITER times, we should see cnt equal to 2*NITER at the end of the program. What happens? Threads can greatly simplify writing elegant and efficient programs. However, there are problems when multiple threads share a common address space, like the variable cnt in our earlier example. To understand what might happen, let us analyze this simple piece of code: THREAD 1 THREAD 2 a = data; b = data; a++; b--; data = a; data = b; Now if this code is executed serially (for instance, THREAD 1 first and then THREAD 2), there are no problems. However threads execute in an arbitrary order, so consider the following situation: Thread 1 Thread 2 data a = data; --- 0 a = a+1; --- 0 --- b = data; // 0 0 --- b = b + 1; 0 data = a; // 1 --- 1 --- data = b; // 1 1 So data could end up +1, 0, -1, and there is NO WAY to know which value! It is completely non- deterministic! http://www.csc.villanova.edu/~mdamian/threads/posixsem.html 1/4 3/17/2016 POSIX Semaphores The solution to this is to provide functions that will block a thread if another thread is accessing data that it is using.
    [Show full text]
  • Praise for Practical Common Lisp
    Praise for Practical Common Lisp “Finally, a Lisp book for the rest of us. If you want to learn how to write a factorial function, this is not your book. Seibel writes for the practical programmer, emphasizing the engineer/artist over the scientist and subtly and gracefully implying the power of the language while solving understandable real-world problems. “In most chapters, the reading of the chapter feels just like the experience of writing a program, starting with a little understanding and then having that understanding grow, like building the shoulders upon which you can then stand. When Seibel introduced macros as an aside while building a test frame- work, I was shocked at how such a simple example made me really ‘get’ them. Narrative context is extremely powerful, and the technical books that use it are a cut above. Congrats!” —Keith Irwin, Lisp programmer “While learning Lisp, one is often referred to the CL HyperSpec if they do not know what a particular function does; however, I found that I often did not ‘get it’ just by reading the HyperSpec. When I had a problem of this manner, I turned to Practical Common Lisp every single time—it is by far the most readable source on the subject that shows you how to program, not just tells you.” —Philip Haddad, Lisp programmer “With the IT world evolving at an ever-increasing pace, professionals need the most powerful tools available. This is why Common Lisp—the most powerful, flexible, and stable programming language ever—is seeing such a rise in popu- larity.
    [Show full text]
  • Hy Documentation Release 0.12.1+64.G5eb9283
    hy Documentation Release 0.12.1+64.g5eb9283 Paul Tagliamonte Apr 14, 2017 Contents 1 Documentation Index 3 1.1 Quickstart................................................4 1.2 Tutorial..................................................5 1.2.1 Basic intro to Lisp for Pythonistas...............................5 1.2.2 Hy is a Lisp-flavored Python..................................7 1.2.3 Macros............................................. 12 1.2.4 Hy <-> Python interop..................................... 13 1.2.5 Protips!............................................. 14 1.3 Hy Style Guide.............................................. 14 1.3.1 Prelude............................................. 15 1.3.2 Layout & Indentation...................................... 15 1.3.3 Coding Style.......................................... 16 1.3.4 Conclusion........................................... 17 1.3.5 Thanks............................................. 17 1.4 Documentation Index.......................................... 18 1.4.1 Command Line Interface.................................... 18 1.4.2 Hy <-> Python interop..................................... 19 1.4.3 Hy (the language)........................................ 21 1.4.4 Hy Core............................................. 47 1.4.5 Reader Macros......................................... 65 1.4.6 Internal Hy Documentation................................... 66 1.5 Extra Modules Index........................................... 72 1.5.1 Anaphoric Macros....................................... 72 1.5.2
    [Show full text]