CSE 130 Programming Language Principles & Paradigms Lecture #
8
Chapter 6 Data Types CSE 130 Programming Language Principles & - - PowerPoint PPT Presentation
CSE 130 Programming Language Principles & Paradigms Lecture # 8 Chapter 6 Data Types CSE 130 Programming Language Principles & Paradigms Lecture # 8 Introduction - Evolution of Data Types: FORTRAN I (1957) - INTEGER, REAL, arrays
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
sometimes more
accuracy specs in code e.g. (Ada)
type SPEED is digits 7 range 0.0..1000.0; type VOLTAGE is delta 0.1 range -12.0..24.0;
Some languages don’t allow you to compare an integer and a float or even two floats, why might they want to restrict this?
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
arrays)
substring reference
matching
that provide operations
CSE 130 Programming Language Principles & Paradigms Lecture #
8
/[A-Za-z][A-Za-z\d]+/
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
e.g.
type pos = 0 .. MAXINT;
CSE 130 Programming Language Principles & Paradigms Lecture #
8
subtype POS_TYPE is INTEGER range 0 ..INTEGER'LAST;
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
binding and binding to storage)
e.g. FORTRAN 77, some arrays in Ada Advantage: execution efficiency (no allocation or deallocation)
statically bound, but storage is bound at elaboration time e.g. Most Java locals, and C locals that are not static Advantage: space efficiency
CSE 130 Programming Language Principles & Paradigms Lecture #
8
declare STUFF : array (1..N) of FLOAT; begin ... end;
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
the values in / ... / on the declaration
the compiler count them e.g.
int stuff [] = {2, 4, 6, 8};
e.g.
SCORE : array (1..14, 1..2) := (1 => (24, 10), 2 => (10, 7), 3 =>(12, 30), others => (0, 0));
CSE 130 Programming Language Principles & Paradigms Lecture #
8
Slices, reverse, sorting, pop, push, shift, unshift, join See [Chapter 7 and JSRef Appendix A ] Arrays can be used as the basis of many other data types like stacks and queues see how JavaScript facilitates this JavaScript arrays are also associative – discussed in a moment JavaScript arrays are not homogenous?
CSE 130 Programming Language Principles & Paradigms Lecture #
8
mechanism
INTEGER MAT (1 : 4, 1 : 4) MAT(1 : 4, 1) - the first column MAT(2, 1 : 4) - the second row
you can imagine the array unfolded and placed in contiguous memory cells
location
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
e.g.,
%hi_temps = ("Monday" => 77, "Tuesday" => 79,…);
e.g.,
$hi_temps{"Wednesday"} = 83;
e.g.,
delete $hi_temps{"Tuesday"};
JavaScript is even more direct and crosses over greatly with regular objects window.document.lastModified vs. window.document[“lastModified”]
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
record to fields with the same names in the destination record
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
nondiscriminated unions
record tagg : Boolean of true : (blint : integer); false : (blreal : real); end;
ineffective
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
Most common examples: C and C++
e.g. float stuff[100];
float *p; p = stuff; *(p+5) is equivalent to stuff[5] and p[5] *(p+i) is equivalent to stuff[i] and p[i]
(Implicit scaling)
checked (cannot be dereferenced)
CSE 130 Programming Language Principles & Paradigms Lecture #
8
CSE 130 Programming Language Principles & Paradigms Lecture #
8
management
accessed by a variable
can't design a language without them, or something that basically does what a pointer does even if named differently
CSE 130 Programming Language Principles & Paradigms Lecture #
8