Subprograms A subprogram allows process (as opposed to data) abstraction. Characteristics –single entry point –caller suspended until control returns from.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #16 Lecture #16 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Programming Languages and Paradigms
Subprogram ธนวัฒน์ แซ่ เอียบ. Subprograms as computational abstractions.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Subprograms A subprogram allows process abstraction (as opposed to data abstraction). Characteristics –single entry point –caller suspended until control.
Overview Fundamentals of Subprograms (Sec )
Chapter 9 Subprograms Specification: name, signature, actions Signature: number and types of input arguments, number and types of output results –Book.
ISBN Chapter 9 Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms.
Chapter 9 Subprograms.
1 CHAPTER 9 SUBPROGRAM. 2 SUBPROGRAM Topics: b Definitions of subprogram b general subprogram characteristics b parameters b Functions and procedures.
Procedures and Control Flow CS351 – Programming Paradigms.
Chapter 9 Subprograms.
Chapter 9 Subprograms.
Chapter 9 Subprograms Sections 1-5 and 9. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Two fundamental abstraction facilities.
ISBN Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Introduction Two fundamental abstraction facilities.
ISBN Chapter 9 Subprograms. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Chapter 9 Topics Introduction Fundamentals.
ISBN Chapter 7 Expressions and Assignment Statements CE2004 Principles of Programming Languages EIGHTH EDITION.
ISBN Chapter 9 Subprograms CE2004 Principles of Programming Languages.
CSE 452: Programming Languages Lecture 8 9/18/2003.
Overview Parameter passing modes.
ISBN Chapter 9 Subprograms and Functions –Design Issues –Local Referencing Environments –Parameter-Passing Methods –Parameters that are Subprogram.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 9 Functions It is better to have 100 functions.
© 2003 G. Drew Kessler and William M. Pottenger1 Subroutines (Part 1) CSE 262, Spring 2003.
Chapter 8 :: Subroutines and Control Abstraction
1 Subprograms Fundamentals of subprograms Design issues for subprograms –Parameter-passing methods –Type checking of parameters –Static or dynamic storage.
Chapter 9 Subprograms.
Chapter 9 Subprograms. Copyright © 2012 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues.
ISBN Chapter 9 Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms.
Chapter Nine: Subprograms Lesson 09. What are they  Modularized code  Might return a value  Functions  Or not  Procedures  Subroutines  In object.
Programming Languages and Design Lecture 7 Subroutines and Control Abstraction Instructor: Li Ma Department of Computer Science Texas Southern University,
Subprograms Support process abstraction and modularity –characteristics of subprograms are that they have a single entry point the calling entity is suspended.
Chapter 9 Subprograms Fundamentals of Subprograms
April 23, ICE 1341 – Programming Languages (Lecture #16) In-Young Ko Programming Languages (ICE 1341) Lecture #16 Programming Languages (ICE 1341)
1 Chapter 9 © 2002 by Addison Wesley Longman, Inc. 9.2 Fundamentals of Subprograms - General characteristics of subprograms: 1. A subprogram has a single.
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 8 Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The.
ISBN Chapter 9 Subprograms. 1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Week 7 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for.
Subprograms subroutines, procedures, functions, methods.
ISBN Chapter 9 Subprograms. Copyright © 2015 Pearson. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Angela Guercio.
1 Subprograms In Text: Chapter 8. 2 Chapter 8: Subprograms Outline Definitions Referencing environments Parameter passing modes and mechanisms Independent.
Chapter 9 Subprograms. 2 Fundamentals of Subprograms Each subprogram has a single entry point The calling program is suspended during execution of the.
C HAPTER 9 Subprograms. CCSB314 Programming Language C HAPTER 9 T OPICS Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing.
1 Subroutines Structure of Programming Language. 2 Procedures and Functions There are two categories of subprograms Function: subroutine that returns.
ISBN Chapter 9 Subprograms Sections
CSI 3125, Subprograms, page 1 Subprograms General concepts Parameter passing Functions Subprograms as parameters.
(1) ICS 313: Programming Language Theory Module 12: Subprograms.
Chapter 9 Subprograms. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues.
Chapter 9: Subprograms Introduction Fundamentals of Subprograms
ISBN Chapter 9 Subprograms. Corrected and improved by Assoc. Prof. Zeki Bayram, EMU, North Cyprus. Original Copyright © 2007 Addison-Wesley.
9-1 Chapter 9 Subprograms Topics Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters.
1 CSC 533: Programming Languages Spring 2014 Subprogram implementation  subprograms (procedures/functions/subroutines)  subprogram linkage  parameter.
Chapter 9 Chapter 9 Subprograms. The Structure of Run-Time Memory.
ISBN Chapter 9 Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved.1-2 Chapter 9 Topics Introduction Fundamentals of Subprograms.
Chapter 9 Subprograms. Chapter 9 Topics Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing.
Chapter 9 Subprograms.
Functions.
Chapter 9 Subprograms.
Parameter passing Module 12.3 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
CSCI 3370: Principles of Programming Languages Chapter 9 Subprograms
CSC 533: Programming Languages Spring 2015
Subprograms In Text: Chapter 9.
Subject : T0152 – Programming Language Concept
Chapter 9 Subprograms Fundamentals of Subprograms
CSE 452: Programming Languages
CSC 533: Programming Languages Spring 2018
CSC 533: Programming Languages Spring 2019
Presentation transcript:

Subprograms A subprogram allows process (as opposed to data) abstraction. Characteristics –single entry point –caller suspended until control returns from subprogram –control returns to caller when subprogram terminates only if subprogram terminates normally exceptions allow for alternate control flow Types –Functions: return a value –Procedures: do not return a value –Predicates: are provable (or not)

Parameters Formal parameters/parameters –in subprogram definition Actual parameters/arguments –in subprogram call Binding of arguments to parameters –positional (1 st is bound to 1 st, 2 nd to 2 nd, etc) –keyword (each parameter has a keyword

Keyword parameter example (defun makePoint (&key x y)...) (makePoint :x 3 :y 5) (makePoint :y 5 :x 3) This example is Lisp. Other languages that permit keyword arguments include Ada and Fortran95.

Default arguments C++, Fortran95, Ada and PHP allow default argument values void example(int x=100, int y) {...} example(30)  example(100,30) example(50,30)  example(50,30)

Variable-length parameter lists Some languages allow subprograms to accept a variable number of arguments. –Lisp, Scheme, C#, Java (define f (lambda (x y)...)) f takes a list of two args (define g (lambda lst...)) g takes a list of unspec len

Java varargs example void foo(int x, String... names) { System.out.println(“x is ”+x); for (String name:names) { System.out.println(name); } Vararg must be last parameter.

Parameter passing modes in –information passes in through parameter out –information passes out through parameter in-out –information passes both in and out through parameter

passing modes in-mode –pass-by-value out-mode –pass-by-result in-out mode –pass-by-value-result –pass-by-reference –(pass-by-name: textual substitution)