* Lecture 12 Mapping, Map Reduction Summing integers,

Slides:



Advertisements
Similar presentations
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
Advertisements

Visual Basic Programming
PHP Arūnas Liuiza. PHP 101 What is PHP? Widely popular dynamic interpreted opensource programming language, aimed for web development Syntax is simmilar.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
Recursion.
CS314 – Section 5 Recitation 9
Web Database Programming Using PHP
Trace Tables In today’s lesson we will look at:
Session 2 Basics of PHP.
CS314 – Section 5 Recitation 10
CprE 185: Intro to Problem Solving (using C)
Java Applet Programming Barry Sosinsky Valda Hilley
CHAPTER 5 SERVER SIDE SCRIPTING
เอกสารประกอบการบรรยายรายวิชา Web Technology
CSC 221: Computer Programming I Spring 2010
Loops BIS1523 – Lecture 10.
Web Database Programming Using PHP
Python: Control Structures
Arrays in PHP are quite versatile
CSC 221: Computer Programming I Fall 2005
GC211Data Structure Lecture2 Sara Alhajjam.
C Programming Tutorial – Part I
CS 326 Programming Languages, Concepts and Implementation
* Lecture # 7 Instructor: Rida Noor Department of Computer Science
Object-Oriented Programming & Design Lecture 14 Martin van Bommel
JavaScript Syntax and Semantics
Engineering Innovation Center
* Lecture 26 Manifest Asynchrony
Server Side Programming Overview And file system basics
Introduction to Databases with MAMP/LAMP/WAMP thrown in!
CT Web Development, Colorado State University
HTML5 Drawing Canvas and Video
C# Programming: From Problem Analysis to Program Design
Handling Files In particular, uploading files.
Tables from Arrays of Objects Exploding Strings
Content Management and WordPress
HTML Basics & Context & IDEs & Server Basics & Online Notes
Functions BIS1523 – Lecture 17.
Topics Introduction to File Input and Output
* Lecture 22 Images * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
Introduction to AJAX and the migration toward applications
MySQL Tables and Relations 101
Final Review CSE321 B.Ramamurthy 11/23/2018 B.Ramamurthy.
Introduction to Python
* Lecture 5 PHP Basics * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
Querying Client Information Forms and Passing Data,
* jQuery * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.
PHP Intro/Overview Bird Book pages 1-11,
Authentication Stepped Up Persistent User Data Protected Content.
Arrays 6-Dec-18.
PHP.
Final Review CSE321 B.Ramamurthy 12/9/2018 B.Ramamurthy.
Closure Closure binds a first-class function and a lexical environment together This is a complex topic, so we will build up our understanding of it we.
We’re moving on to more recap from other programming languages
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Basics (Cont...).
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Server Side Programming Overview And file system basics
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Suggested self-checks: Section 7.11 #1-11
Chapter 18 Recursion.
Javascript Chapter 19 and 20 5/3/2019.
Loops and Conditionals Generating , Reading files.
Arrays 2-May-19.
JavaScript.
Topics Introduction to File Input and Output
Alternatives to our approach
Introduction to scripting
Presentation transcript:

* Lecture 12 Mapping, Map Reduction Summing integers, Map Reduce & Strings PHP Objects * Course logo spider web photograph from Morguefile openstock photograph by Gabor Karpati, Hungary.

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 02 Reduction trumps iteration! Two arguments, First builds result, Second is current array element. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 02 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Basics - Functions Here is how functions are defined. Feature you have come to expect: A name: “runsum” Arguments – no typing Code body Explicit return value – no typing again. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

The Naming of Functions Consider Carefully this Code What is the second argument? Is it a string literal? Is it a function? When you are comfortable saying yes to be both and understand why that answer makes sense you will be on your way to understanding array_reduce in particular and the idea of a run-time symbol table more generally. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Mapping In General In C, C++, Java and the like there is a STRONG bias in favor of loops. There has always been an alternative view in CS … PHP supports Mapping !! Excerpt from: John McCarthy, Paul W. Abrahams, Daniel J. Edwards, Timothy P. Hart and Michael I. Levin. LISP 1.5 Programmer's Manual. The M.I.T. Press, 1962, second edition. Posted here by permission of The MIT Press. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Map runsum as a Figure ‘’ 2 ‘’ + 2 6 2 + 4 12 6 + 6 12 + 8 20 [0]=>2 [1]=>4 [2]=>6 [3]=>8 Accumulation variable $s Array element $next 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

In Honor of Douglas Adams 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Starting with 42 42 44 42 + 2 48 44 + 4 54 48 + 6 54 + 8 62 [0]=>2 [1]=>4 [2]=>6 [3]=>8 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

The PHP.net Documentation array_reduce is a function. It does return a result. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 03 The combination function may be created in place, not named. The short if-then-else format is handy for the return. Second example is better. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 03 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Why The Leading ‘and’ In the first case, foo, the initialization value is null the first time the function is called. What is returned is null – the empty string for strings – concatenated with ‘and’ The second example uses the short syntax if-the-else to avoid the problem. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz A Function with No Name Notice the in-place definition of the function passed to map_reduce. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Reading the Fine Print A more modern, preferred, way. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Updating Example 3 Here is a portion of Example 3 using the new more general way of creating anonymous functions This new format better implements what is commonly called a closure. Put simply, closures have everything to do with variable scoping, and the PHP documentation has some nice examples. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 04 PHP is an object oriented language. Here is a class for ‘States’. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Example 04 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz Object, print thy self In Example 4, pay attention to the use of the __toString() method. Most modern Object Oriented Languages expect a programmer to take responsibility for how an object responds to a print – echo – statement. Since so much of PHP is about generating text - HTML – output this is a useful capability. 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz

About Arrays of Objects Recognize This Format? 11/14/2018 CSU CT 310 - Web Development ©Ross Beveridge & Jaime Ruiz