CS345H: Programming Languages Lecture 14: Introduction To

Total Page:16

File Type:pdf, Size:1020Kb

CS345H: Programming Languages Lecture 14: Introduction To Functional Languages CS345H: Programming Languages I All languages we have studies so far were variants of lambda calculus Lecture 14: Introduction to Imperative Languages I Such languages are known as functional languages Thomas Dillig I We have also seen that these languages allow us to design powerful type systems I And even perform type inference Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 1/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 2/31 Salient Features of Functional Languages No Side Effects I The functional languages we studied have a set of defining features: I No side effects means no assignments and no variables! I Most noticeable feature: No side effects! I Recall: Let-bindings are only names for values I This means that evaluating an expression never changes the value of any other expression I The value they stand for can never change I Example: I Example: let x = 3+4 in let y = x+5 in x+y let x = 3 in let x = 4 in x I Here, evaluating the expression x+5 cannot change the value of any other expression Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 3/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 4/31 Impact of No Side Effects Impact of No Side Effects Cont. I Question: How can we exploit the fact that evaluating expressions never changes the value of any other expression? I Unfortunately, run-time errors negate all the benefits we listed! I Answers: I Question: What can we do about this? I We can evaluate expressions in parallel I Solution: Type systems I We can delay evaluation until a value is actually used I Any sound type system will guarantee no run-time errors I Question: What kind of side effect can evaluating expressions still have? I Conclusion: We can only fully take advantage of functional features if we use a sound type system I Answer: They may still trigger a run-time error Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 5/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 6/31 1 The Alternative to Functional Programming Imperative Programming Languages I However, there is also an alternative (and much more I You have all used imperative programming languages common) way of programming called imperative programming I Imperative Languages: I Features of imperative programming: I FORTRAN I Side effects I ALGOL I Assignments that change the values of variables I C, C++ I Programs are sequences of statements instead of one expression I Java I Imperative programming is the dominant model I Python I This style is much closer to the way hardware executes I ... Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 7/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 8/31 Features of Imperative Languages Example Compare and Contrast I Let’s look at some example imperative programs I At a minimum, a language must have the following features to be considered imperative: I I will use C style since most of you should be familiar with this I Variables and assignments I Adding all numbers from 1 to 10 in L: I Loops and Conditionals and/or goto fun add with n = if n == 0 then 0 else n + (add (n-1)) in (n 10) I Observe that features such as pointers, recursion and arrays are optional I Here is the same program in C: int res = 0, i; I For example, FORTRAN originally only had integers and for(i=0; i < 10; i++) res += i; floats, loops, conditionals and goto statements return res; I Question: Which style do you prefer? Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 9/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 10/31 Very basic imperative programming GOTOs in Programming I All early imperative languages include goto statements I Rational: 1) Hardware supports only compare and jump I Now, let’s get even more basic and only use conditionals and instructions 2) GOTOs allow for more expressive control flow goto statements to write the same program: int res = 0, i; I Example of GOTO use: again: int i = 0; res +=i; int sum; i++; again: if(i<10) goto again; i++; return res; int z = get_input(); if(z < 0) goto error: I Which style do you prefer? n+=z; if(i < 5) goto again: return n; error: return -1; Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 11/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 12/31 2 GOTOs in Programming Cont. GOTOs in Programming Cont. I Not so long ago, it was universally accepted that GOTO statements are necessary for expressive programs I In much early (and also more recent) code, GOTO not only implemented loops but was also used for code reuse I However, as software became larger, GOTO statements started becoming problematic I Real Comment from numerical analyst: “Why bother writing a function if I can just jump to the label?” I Central Problem of GOTO: “Spagetti Code” I In 1968, Dijkstra wrote a very influential essay called “GOTO I This means that thread of execution is very hard to follow in Statement Considered Harmful” in which he argued that program text GOTO statements facilitate unreadable code and should be removed from programming languages I Jumps to a label could come from almost anyplace (in extreme cases even from other functions!) Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 13/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 14/31 The End of GOTO Side Trip: GOTO and COBOL I COBOL stands for COmmon Business Oriented Language I At first, this article was very controversial I In addition to GOTO, COBOL also includes the ALTER I But over time, most programmers started to agree that keyword GOTO constructs should be avoided I After executing ALTER X TO PROCEED TO Y, any future GOTO I Imperative programming without GOTOs is known as X means GOTO Y instead structural programming I Can change control flow structures at runtime! I But not everyone was on board... I This was marketed as allowing polymorphism Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 15/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 16/31 Side Trip: GOTO and COBOL Structured Programming I Today there is a consensus that GOTOs are not a good idea I Instead, imperative languages include many kinds of loops and I Dijkstra’s comment: “The use of branching constructs COBOL cripples the mind; its teaching should, therefore, be I Examples in C++: while, do-while, for, if, switch regarded as a criminal offense.” I One legitimate use of GOTO: Error-handling code I This popularized exceptions in most modern languages Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 17/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 18/31 3 A Simple Imperative Language Semantics of IMP1 I Let’s start by looking at at a very basic imperative language we will call IMP1: I Let’s try to give operational semantics for this language P S1; S2 → | I First, we will again use an environment E to map variables to S if(C ) then S else S fi id = e → 1 2 | their values while(C ) do S od | e id e1 + e2 e1 e2 int → | | − | I Start with the semantics of expressions C e e e = e not C C and C → 1 ≤ 2 | 1 2 | | 1 2 I Question: What do expressions evaluate to? I This language has variables, declarations, conditionals and I Answer: Integers loops I Therefore, the result (value after colon) in operational I But no pointers, functions, ... semantics rules for expression is an integer I What are some example programs in IMP1? Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 19/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 20/31 Semantics of IMP1 Semantics of IMP1 Cont. I Here are operational semantics for expressions in IMP1 (first cut) I Variable: I On to the semantics of Predicates: E v : E(id) ` I Question: What do predicates evaluate to? I Plus E e1 : v1 E ` e : v I Answer: True and False ` 2 2 E e1 + e2 : v1 + v2 ` I Therefore, the result (value after colon) in operation I Minus semantics rules for predicates is a boolean E e1 : v1 E ` e : v ` 2 2 E e e : v v ` 1 − 2 1 − 2 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 21/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 22/31 Semantics of IMP1 Cont. Semantics of Statements I Here are operational semantics for predicates in IMP1 I Now, all we have left are the statements I Less than or equal to: E e : v I However, there is one big problem: Statements do not ` 1 1 E e2 : v2 evaluate to anything! v ` v 1 ≤ 2 E e e : True ` 1 ≤ 2 I Instead, statements update the values of variables E e1 : v1 ` I In other words, they change E! E e2 : v2 v ` v 1 6≤ 2 E e e : False I Therefore, the rules for statements will produce a new ` 1 ≤ 2 I Or (slightly imprecise) shorthand environment E e1 : v1 ` I Specifically, they are of the form E S : E 0 E e2 : v2 ` ` E e1 e2 : v1 v2 ` ≤ ≤ I Changing the environment is the technical way of having side I What about the other predicates? effects in the language Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 23/31 Thomas Dillig, CS345H: Programming Languages Lecture 14: Introduction to Imperative Languages 24/31 4 Semantics of Statements Cont.
Recommended publications
  • Preview Objective-C Tutorial (PDF Version)
    Objective-C Objective-C About the Tutorial Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. This is the main programming language used by Apple for the OS X and iOS operating systems and their respective APIs, Cocoa and Cocoa Touch. This reference will take you through simple and practical approach while learning Objective-C Programming language. Audience This reference has been prepared for the beginners to help them understand basic to advanced concepts related to Objective-C Programming languages. Prerequisites Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is a computer program, and what is a computer programming language? Copyright & Disclaimer © Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book can retain a copy for future reference but commercial use of this data is not allowed. Distribution or republishing any content or a part of the content of this e-book in any manner is also not allowed without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] ii Objective-C Table of Contents About the Tutorial ..................................................................................................................................
    [Show full text]
  • On Goto Statement in Basic
    On Goto Statement In Basic James spores his coeditor arrest lowse, but ribbony Clarence never perambulating so defenselessly. orFingered ferniest and after sold grapy Barry Jimmy sublime countermarches his microclimates so thwart? envelop snigs opinionatively. Is Skylar mismatched Download On Goto Statement In Basic pdf. Download On Goto Statement In Basic doc. Well before withthe statement recursion, basic, and look understandable like as labe not, usage i learned of. Normal to that precedence include support that the content goto basic;is a goto. back Provided them up by statementthe adjectives basic, novel the anddim knowsstatement exactly with be the in below. basic doesMany not and supported the active for on the goto vba. in theSkip evil the comes error asfrom on movesthe specified to go toworkbook go with thename _versionname_ to see the value home does page. not Activeprovided on byone this is withinsurvey? different Outline if ofa trailingbasic withinspace theor responding value if by thisto. Repaired page? Print in favor statement of code along so we with need recursion: to go with many the methods product. becomeThought of goto is startthousands running of intothe code?more readable Slightly moreand in instances vb. Definitely that runnot onprovided basic program, by a more goto explicit that construct,exponentiation, basic i moreinterpreter about? jump Stay to thatadd youthe workbookwhen goto name. basic commandPrediction gotoor go used, on statement we were basicnot, same moves page to the returns slightly isresults a boolean specific in toworkbook the trademarks name to of. the Day date is of.another Exactly if you what forgot you runa stack on in overflow basic does but misusingnot complete it will code isgenerally the window.
    [Show full text]
  • 7. Control Flow First?
    Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 Ordering Program Execution: What is Done 7. Control Flow First? Overview Categories for specifying ordering in programming languages: Expressions 1. Sequencing: the execution of statements and evaluation of Evaluation order expressions is usually in the order in which they appear in a Assignments program text Structured and unstructured flow constructs 2. Selection (or alternation): a run-time condition determines the Goto's choice among two or more statements or expressions Sequencing 3. Iteration: a statement is repeated a number of times or until a Selection run-time condition is met Iteration and iterators 4. Procedural abstraction: subroutines encapsulate collections of Recursion statements and subroutine calls can be treated as single Nondeterminacy statements 5. Recursion: subroutines which call themselves directly or indirectly to solve a problem, where the problem is typically defined in terms of simpler versions of itself 6. Concurrency: two or more program fragments executed in parallel, either on separate processors or interleaved on a single processor Note: Study Chapter 6 of the textbook except Section 7. Nondeterminacy: the execution order among alternative 6.6.2. constructs is deliberately left unspecified, indicating that any alternative will lead to a correct result Expression Syntax Expression Evaluation Ordering: Precedence An expression consists of and Associativity An atomic object, e.g. number or variable The use of infix, prefix, and postfix notation leads to ambiguity An operator applied to a collection of operands (or as to what is an operand of what arguments) which are expressions Fortran example: a+b*c**d**e/f Common syntactic forms for operators: The choice among alternative evaluation orders depends on Function call notation, e.g.
    [Show full text]
  • Gnu Smalltalk Library Reference Version 3.2.5 24 November 2017
    gnu Smalltalk Library Reference Version 3.2.5 24 November 2017 by Paolo Bonzini 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, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled \GNU Free Documentation License". 1 3 1 Base classes 1.1 Tree Classes documented in this manual are boldfaced. Autoload Object Behavior ClassDescription Class Metaclass BlockClosure Boolean False True CObject CAggregate CArray CPtr CString CCallable CCallbackDescriptor CFunctionDescriptor CCompound CStruct CUnion CScalar CChar CDouble CFloat CInt CLong CLongDouble CLongLong CShort CSmalltalk CUChar CByte CBoolean CUInt CULong CULongLong CUShort ContextPart 4 GNU Smalltalk Library Reference BlockContext MethodContext Continuation CType CPtrCType CArrayCType CScalarCType CStringCType Delay Directory DLD DumperProxy AlternativeObjectProxy NullProxy VersionableObjectProxy PluggableProxy SingletonProxy DynamicVariable Exception Error ArithmeticError ZeroDivide MessageNotUnderstood SystemExceptions.InvalidValue SystemExceptions.EmptyCollection SystemExceptions.InvalidArgument SystemExceptions.AlreadyDefined SystemExceptions.ArgumentOutOfRange SystemExceptions.IndexOutOfRange SystemExceptions.InvalidSize SystemExceptions.NotFound SystemExceptions.PackageNotAvailable SystemExceptions.InvalidProcessState SystemExceptions.InvalidState
    [Show full text]
  • The Latest IBM Z COBOL Compiler: Enterprise COBOL V6.2!
    The latest IBM Z COBOL compiler: Enterprise COBOL V6.2! Tom Ross Captain COBOL SHARE Providence August 7,2017 1 COBOL V6.2 ? YES! • The 4 th release of the new generation of IBM Z COBOL compilers • Announced: July 17, 2017 • The same day as IBM z14 hardware…coincidence? • GA: September 8, 2017 • Compiler support for the new IBM z14 hardware and IBM z/OS V2.3 • Ability to exploit the new Vector Packed Decimal Facility of z14 • ‘OLD’ news: • COBOL V5 EOM Sept 11, 2017 (announced Dec 6, 2016) • EOS for COBOL V4 ‘might’ be earlier than 2020, still discussing 2 COBOL V6.2 ? What else does it have? • New and changed COBOL statements, such as the new JSON PARSE statement • Support of COBOL 2002/2014 standards with the addition of the COBOL Conditional Compilation language feature • New and changed COBOL options for increased flexibility • Improved compiler listings with compiler messages at the end of the listing as in previous releases of the compiler • Improved interfaces to optional products and tools such as IBM Debug for z Systems (formerly Debug Tool for z/OS) and IBM Application Discovery and Delivery Intelligence (formerly EzSource) • Compile-time and runtime performance enhancements • Improved usability of the compiler in the z/OS UNIX System Services environment 3 Vector Packed Decimal Facility of z14 • Enterprise COBOL V6.2 adds support for exploiting the new Vector Packed Decimal Facility in z14 through the ARCH(12) compiler option. • The Vector Packed Decimal Facility allows the dominant COBOL data types, packed and zoned decimal, to be handled in wide 16-byte vector registers instead of in memory.
    [Show full text]
  • Programming Reference Guide
    Programming Reference Guide REFERENCE GUIDE RG-0006-01 1.9 en-US ENGLISH Important User Information Disclaimer The information in this document is for informational purposes only. Please inform HMS Networks of any inaccuracies or omissions found in this document. HMS Networks disclaims any responsibility or liability for any errors that may appear in this document. HMS Networks reserves the right to modify its products in line with its policy of continuous product development. The information in this document shall therefore not be construed as a commitment on the part of HMS Networks and is subject to change without notice. HMS Networks makes no commitment to update or keep current the information in this document. The data, examples and illustrations found in this document are included for illustrative purposes and are only intended to help improve understanding of the functionality and handling of the product. In view of the wide range of possible applications of the product, and because of the many variables and requirements associated with any particular implementation, HMS Networks cannot assume responsibility or liability for actual use based on the data, examples or illustrations included in this document nor for any damages incurred during installation of the product. Those responsible for the use of the product must acquire sufficient knowledge in order to ensure that the product is used correctly in their specific application and that the application meets all performance and safety requirements including any applicable laws, regulations, codes and standards. Further, HMS Networks will under no circumstances assume liability or responsibility for any problems that may arise as a result from the use of undocumented features or functional side effects found outside the documented scope of the product.
    [Show full text]
  • FORTRAN 77 Language Reference
    FORTRAN 77 Language Reference FORTRAN 77 Version 5.0 901 San Antonio Road Palo Alto, , CA 94303-4900 USA 650 960-1300 fax 650 969-9131 Part No: 805-4939 Revision A, February 1999 Copyright Copyright 1999 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California 94303-4900 U.S.A. All rights reserved. All rights reserved. This product or document is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation. No part of this product or document may be reproduced in any form by any means without prior written authorization of Sun and its licensors, if any. Portions of this product may be derived from the UNIX® system, licensed from Novell, Inc., and from the Berkeley 4.3 BSD system, licensed from the University of California. UNIX is a registered trademark in the United States and in other countries and is exclusively licensed by X/Open Company Ltd. Third-party software, including font technology in this product, is protected by copyright and licensed from Sun’s suppliers. RESTRICTED RIGHTS: Use, duplication, or disclosure by the U.S. Government is subject to restrictions of FAR 52.227-14(g)(2)(6/87) and FAR 52.227-19(6/87), or DFAR 252.227-7015(b)(6/95) and DFAR 227.7202-3(a). Sun, Sun Microsystems, the Sun logo, SunDocs, SunExpress, Solaris, Sun Performance Library, Sun Performance WorkShop, Sun Visual WorkShop, Sun WorkShop, and Sun WorkShop Professional are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and in other countries.
    [Show full text]
  • Zend Studio 5 Default Keymap
    Code Snippets Instant URL Code Folding Customise Keymap Code Analyzer Clone View Benefit from our Debugging Manage large amounts of Scheme Customization Get analysis information Create a clone of the communities extensive code by automatically with great ideas on how current editor for viewing knowledge and be updated Enter the URL you want Use a default scheme Create a unique key and editing two files at the to debug and press collapsing and or define your own. combination for each to improve your code. with the latest snippets expanding. Right click on a same time. Right click in from Zend’s site. Debug -> Debug URL. Tools->Preferences-> action. the editor and choose Tools -> Preferences Colors & Fonts Tools->Preferences- directory in the project Edit -> Show Snippets -> -> Editing tab and press Analyze ‘Clone View’ ‘Update Snippets’. >KeyMap Zend Studio 5 Default Keymap Code Debug Server Manage Debugging & Profiling Tools Documentation Ctrl + N - Add New Document F8- Debug URL Alt + Ctrl + A Analyze Code Connections Create documentation for Ctrl + O - Open Document F12 - Profile URL Ctrl + Shift + I Check Include Files Check connectivity with Ctrl + F4 - Close Document/Window Ctrl + F5 - Run the Debug Server. your PHP files in your Ctrl + Shift + F4 - Close All F5 - Go Code Templates favorite HTML style. Ctrl + Shift + O - Open Project F10 - Step Over To add a Template, press Tab to insert code. Tools -> Check Debug Tools -> PHPDocumentor Ctrl + Shift + N - New Project F11 - Step Into Server Connection Ctrl + S - Save File Shift + F11 - Step Out PHP Templates Ctrl + Shift + S - Save As Shift + F5 - Stop Debug itar - Iterates an Array SQL Connectivity Ctrl + Alt + S - Save All Shift + F10 - Go to Cursor itdir - Iterates a Directory F9 - Toggle Breakpoint prv - Prints a Value Goto File/ Resource Add SQL database Editor Shift + F8 - Add Watch inst - Instance of Statement connection in one click.
    [Show full text]
  • Jump Statements in C
    Jump Statements In C Welbie roll-out ruinously as perigonial Damon suppose her lame posit uxorially. Is Vinnie sphagnous or imprescriptible when fructified some decimalisations entitling prancingly? Lion denning paradigmatically. C goto statement javatpoint. What application development language with conditional and inside it makes a loop can be considered as possible structured programming languages and it will check. C Programming Language Tutorial-Lect 14 Jump statementsbreakcontinuegoto 6. We only use this variable c in the statement block can represent every value beneath each. In rate above program the notice of numbers entered by the user is calculated. Goto is already useful in exception handling within nested blocks. Jump Statements In C Programming. What are jumping statements? C Jump Statements Break Continue Goto Return and. What is loaded even go, then drop us form has a linear sequence numbering in this is used anywhere in a loop continues with java has loaded. Does not be for a handful of branching within a c break and can we can only one of coding rules. Since its algorithm, nothing wrong with example, when you bad habits that provide it terminates only if it. Jump Statements In C Language Lessons Blendspace. This way processors are crazy enough numbers in another part of stylistic advice for a timeout occurs that you can be used only one would be used. Differences Between break to continue with Comparison. These two compound statements that test some condition and execute correct or specimen block depending on customer outcome position the condition. We have however seen break used to jump part of switch statements.
    [Show full text]
  • Manual on Danube Navigation Imprint
    Manual on Danube Navigation Imprint Published by: via donau – Österreichische Wasserstraßen-Gesellschaft mbH Donau-City-Straße 1, 1220 Vienna [email protected] www.via-donau.org Responsibility for content: Hans-Peter Hasenbichler Project management: Martin Paschinger Editing: Thomas Hartl, Vera Hofbauer Technical contributions: Maja Dolinsek, Simon Hartl, Thomas Hartl, Brigitte Hintergräber, Vera Hofbauer, Martin Hrusovsky, Gudrun Maierbrugger, Bettina Matzner, Lisa-Maria Putz, Mario Sattler, Juha Schweighofer, Lukas Seemann, Markus Simoner, Dagmar Slavicek Sponsoring: Hedwig Döllinger, Hélène Gilkarov Layout: Bernd Weißmann Print: Grasl Druck & Neue Medien GmbH Vienna, January 2013 ISBN 3-00-009626-4 © via donau 2013 Klimaneutrale Produktion Erneuerbare Energie Nachhaltiges Papier Pflanzenölfarben The Manual on Danube Navigation is a project of the National Action Plan Danube Navigation. Preface Providing knowledge for better utilising the Danube’s potential In connection with the Rhine, the Danube is more and more developing into a main European traffic axis which ranges from the North Sea to the Black Sea at a distance of 3,500 kilometres, thereby directly connecting 15 countries via waterway. Some of the Danube riparian states show the highest economic growth rates amongst the states of Europe. Such an increase in trade entails an enormous growth of traffic in the Danube corridor and requires reliable and efficient transport routes. The European Commission has recognised that the Danube waterway may serve as the backbone of this dynamically growing region and it has included the Danube as a Priority Project in the Trans-European Transport Network Siim Kallas (TEN-T) to ensure better transport connections and economic growth. Vice-President of the European Prerequisite for the utilisation of the undisputed potentials of inland naviga- Commission, Commissioner for tion is the removal of existing infrastructure bottlenecks and weak spots in the Transport European waterway network.
    [Show full text]
  • To Use Or Not to Use the Goto Statement: Programming Styles Viewed from Hoare Logic
    CORE Metadata, citation and similar papers at core.ac.uk Provided by Elsevier - Publisher Connector Science of Computer Programming 60 (2006) 82–116 www.elsevier.com/locate/scico To use or not to use the goto statement: Programming styles viewed from Hoare Logic Hidetaka Kondoha,∗, Kokichi Futatsugib aSystems Development Lab., Hitachi, Ltd., 1099 Ohzenji, Asao, Kawasaki, Kanagawa 215-0013, Japan bJAIST, 1-1 Asahi-dai, Tatsunokuchi-machi, Noumi-gun, Ishikawa 923-1292, Japan Received 11 November 2003; received in revised form 28 April 2005; accepted 18 May 2005 Available online 31 August 2005 Abstract There has been a vast amount of debate on the goto issue: i.e., the issue whether to use or not to use the goto statement initiated by Dijkstra in his famous Letter to the Editor of CACM and his pro- posal of ‘Structured Programming’. However, except for the goto-less programming style by Mills based on theoretical results on the expressibility of control flow diagrams, there have hardly been any scientific accounts on this issue from Dijkstra’s own viewpoint of the correctness of programs. In this work, we reconsider this seemingly old-tired issue from the viewpoint of Hoare Logic, the most well-known framework for correctness proof of programs. We show that, in two cases, the with-goto programming styles are more suitable for proving correctness in Hoare Logic than the corresponding without-goto ones; that is, in each of two cases, the without-goto style requires more complicated as- sertions in the proof-outline than the with-goto one. The first case is on the use of the goto statement for escaping from nested loops and the second case is on the use of the goto statement for expressing state transitions in programming through the finite state machine model.
    [Show full text]
  • Control Flow Instructions
    Control Flow Instructions CSE 30: Computer Organization and Systems Programming Diba Mirza Dept. of Computer Science and Engineering University of California, San Diego 1 So Far... vAll instructions have allowed us to manipulate data vSo we’ve built a calculator vIn order to build a computer, we need ability to change the flow of control in a program… 2 Ways to change Control flow in C 1. goto <label> 2. if (condition) { //do something } 3. if-else 4. Loops I. do-while II. for III. while IV. switch 3 Labels v Any instruction can be associated with a label v Example: start ADD r0,r1,r2 ; a = b+c next SUB r1,r1,#1 ; b-- v In fact, every instruction has a label regardless if the programmer explicitly names it v The label is the address of the instruction v A label is a pointer to the instruction in memory v Therefore, the text label doesn’t exist in binary code 4 ARM goto Instruction v The simplest control instruction is equivalent to a C goto statement v goto label (in C) is the same as: v B label (in ARM) v B is shorthand for “branch”. This is called an unconditional branch meaning that the branch is done regardless of any conditions. v There are also conditional branches: 5 Conditional Branch v To perform a conditional branch, 1. First set the condition bits (N,Z,V,C) in the program status register 2. Then check on these condition bits to branch conditionally v What are the ways we have learnt to set condition bits so far? v Append S to arithmetic/logical instruction v There is another way using a ‘Comparison Instruction’ 6 Comparison
    [Show full text]