333_20240624123259 Flashcards
Why should Concepts of programming languages be studied?
Programming is new.
General language concept knowledge helps.
Increased ability to express ideas.
“ “ to learn new languages.
Helps choose appropriate languages.
Understand tradeoffs.
Overall advancement of computing
What are the Language Evaluation Criteria?
Readability, Writability, Reliability, Cost
What is Readability defined as?
The ease with which programs can be read and understood
What is Writability defined as?
The ease with which a language can be used to create programs
What is Reliability defined as?
Whether a language performs to its specifications under all conditions
What is Cost defined as?
cost of using the language
What is the Evaluation Criteria for Readability?
Overall simplicity: Manageable set of features and constructs(minimal feature multiplicity, minimal operator overloading)
Orthogonality: small set of primitive constructs can be combined in small number of ways
Data types; if types are missing, they must be simulated
Syntax considerations: Lack of naming restrictions increase readability (Identifier forms). More special words = more readable (Special words). meaningful keywords, avoid language constructs with same name and different meaning(Form and meaning)
Why is a lack of orthogonality bad?
It can lead to exceptions
Why is too much orthogonality bad?
bad for readability
What is the problem with too much simplicity?
Can be bad for readability
What is the Evaluation Criteria for Writability?
Simplicity and orthogonality: few constructs, small number of primitives, small set of rules for combining them
Support for abstraction: define and use complex structures/operations.(Process abstraction and Data abstraction)
Expressivity: convenient ways of specifying operations. Strength + number of operators and predefined functions
What is process abstraction?
Provision for subprograms
What is data abstraction?
classes, pointer & dynamic memory
What is the Evaluation Criteria for Reliability?
Type checking: Test for type errors. Compile time checking > run time checking
Exception handling: intercept run time errors and correct it
Aliasing: Presence of 2+ distinct referencing names for same memory location. (dangerous feature)
Readability and writability: non-natural ways of expressing algorithms = unnatural approaches = reduced reliability
What is the Evaluation Criteria for Cost?
Training new programmers.
Writing programs
compiling programs
Executing programs
Language implementation system (availability of free compilers)
Reliability(poor = high cost)
Maintaining programs
What are some extra Evaluation Criteria?
Portability : ease of moving from on implementation to another
Generality: applicability to a wide range of applications
Well-definedness: Completeness + precision of of language’s official definition
What are the Language Design trade-offs
Reliability vs cost of execution
Readability vs writability
Writability(flexibility) vs reliability
What are the programming domains?
Scientific Applications
Business Applications
AI
System Programming
Web Software
What influences the Design of a Language?
Computer Architecture
Programming Methodologies (eg OOP led to new programming paradigms)
What influenced Programming Methodologies?
1950/60: simple applications (machine efficiency)
1960s: Efficiency + readability + better control structures (structured programming + top-down design + step-wise refinement)
1970: Process- oriented -> data-oriented (data abstraction
1980: OOP (Abstraction + inheritance + polymorphism)
What are the Language Categories?
Imperative: Variables, assignment statements, iteration. has OOP languages. Includes visual languages. (c++ Java C ..)
Functional : Main means of computation, applying functions to parameters (LIST, Scheme)
Logic: Rule based (Prolog)
Markup/hybrid (XSLT, JSTL)
What are the Implementation Methods
Compilation: programs translated to ML
Pure Interpretation: Programs are interpreted by another program known as an interpreter
Hybrid: compromise between compilers and pure interpreters
What are the phases of Compilation
Lexical analysis: converts source characters to lexical units
Syntax Analysis: Transforms lexical units to parse trees
Semantics analysis: Generate intermediate code
Code generation: Machine code is generated
Is Compiled or Pure Interpreted programs faster
Compiled.
Interpreted programs are 10-100 times slower
Does Interpreted or compiled programs use more space
Interpreted.
What is an example of a Hybrid Implementation System
Perl, typical Java programs
What is Just-In-Time Implementation Systems
Translate programs to intermediate language
Compile the intermediate language into machine code when they are called
What uses JIT systems?
.NET languages
What are the different Programming environments?
UNIX, Microsoft Visual Studio.NET,NetBeans
When was Zuse’s Plankakul designed?
- Never implemented. Not published until 1972
What was the environment for the development of Zuse’s. and what was it used for
Environment = limited hardware,limited impact
Use = wasnt implemented
Pseudocode environment and use
No specific environment
use = break bigger problems down into smaller ones
What was speedcoding created for?
IBM 701
Was Fortran 0 implemented?
no
What was the environment for Fortran 1 and use?
IBM 704 had little memory. Machine efficiency was very important.
use = business software/scientific computing
How was fortran II different from Fortran I?
More reliable and bug fixes
What was important about Fortran 77
It became the new standard in 1978
Why was Fortran important?
It changed how computers are used
Why was LISP created?
AI research needed a language to support
Why was LISP important?
It pioneered functional programming
Why was Scheme created and where is it used?
Created to promote functional programming.
used in computer science courses
What is COMMON LISP
Feature rich dialect of LISP (it combines features of several LISP dialects) (almost opposite of scheme)
Environment of development for ALGOL 60
No universal language for communicating algorithms.
No portable languages
Needed to design a universal language
What was the goal for ALGOL
it must be close to mathematical notation.
good for describing algorithms
must be translatable
When was ALGOL 58 implemented?
It was never implemented but variations of it was
Environment of development for COBOL
Only few proprietary business languages at the time
On what programming language is COBOL based on?
FLOW-MATIC
what is COBOL used for?
Transaction processing, Data security (business application language)
What was the environment of development for BASIC
Time sharing systems was on the rise
What was BASIC used for?
A general programming language.
first widely used language with time sharing
What was the environment of development for PL/I
Scientific users needed better I/O
Business users needed floating point + arrays
What was PL/I used for?
Business, Scientific and Engineering applications
What was bad about PL/I?
poorly designed. Too large and too complex
What was the 2 early dynamic languages?
APL and SNOBOL
What was APL designed as?
A hardware description language
What is orthogonality?
the ability to “mix” different data types and perform operations with them
What was SNOBOL originally used for?
Writing text editors
What was SIMULA 67 designed for?
system simulation
How did SIMULA 67 advance programming?
It introduced coroutines and the beginnings of data abstraction
What was the design of the ALGOL 68 based on?
Orthogonality
What did ALGOL 68 contribute?
user-defined data structures. reference types. dynamic arrays
For what was C developed?
systems programming at Bell Labs
What is Prolog based on?
Formal logic
What was history’s largest design effort?
Ada
What was Ada developed for?
US DoD
How many languages were in use by the DoD before Ada?
450+
What was Ada intended for?
Embedded system development
What did Ada contribute?
Packages, Exception handling, Generic Program units, Concurrency
What language had the first full implementation of true OO
Smalltalk
What did Smalltalk bring to the table?
Promoted GUI design and OOP paradigm
From where did C++ evolve from?
C + SIMULA 67
What was Java based on?
C++ without struct union and enum(enum is implemented as classes) or pointers
What is perl uses?
UNIX system text file processing, CGI programming. UNIX general system administration
What is PHP often used for?
Form processing + database access via the web
What is JavaScript used for?
Dynamic HTML documents
What was the 1st Japanese language to be widely used in US and what did it replace?
Ruby
Perl and Python
What is imperative language design based on?
von Neumann architecture with efficiency as primary concern
What is functional language design based on?
Mathematical functions
What are functional side effects?
When a function changes a parameter or a global variable
What is the problem with functional side effects?
Unpredictable, Concurrency issues
How to solve functional side effects?
1) No 2 way parameters, No non-local references in functions. but it is very inflexible
2) Demand fixed operand evaluation order. limits some complier optimizations
When does a program have referential transparency?
Any 2 expressions that are equivalent can be substituted for one another and it doesn’t affect the action.
There are no functional side effects
What is the advantage of referential transparency?
semantics are easier to understand
Are Pure Functional Languages referentially transparent? and why?
Yes. No global variables. parameter values are constants. functions cannot have state, value of function depends only on parameters
What is the objective of functional language designs?
mimic math functions as closely as possible
What are the LISP Data Objects and Structures?
Only consists of atoms and lists
2 types of atoms (symbols and numeric literals)
List = sequence of atoms or sublists
What does Scheme and Lisp have in common?
They use the same atoms and lists
What is Scheme interpreter interactive mode?
Mode that allows you to type code in line by line rahter than programming in an editor
Scheme interpreter is just a Scheme function?
Yes
How are functions evaluated?
Parameters (in no order)
values of parameters substituted into the function body
Value of last expression evaluated in the body is the value that the function defines
What are the Primitive Numeric Functions
+,-,*,/,abs,sqrt,remainder,min,max
Which primitive numeric functions cannot accept multiple parameters?
abs,sqrt,remainder
What are lambda functions used for?
Nameless functions
how many parameters can lambda functions have?
any number of parameters
how do you bind names to lambda expressions?
(define (square x) (* x x))
how do you bind a name to the value of an expression
(define pi 3.142) or (define two_pi (* 2 pi))
Hoe is the evaluation process for defined different?
Since the 1st parameter is a name and not a parameter it is not evaluated (otherwise it would be evaluated as undefined)
How do you output a expression in Scheme?
(display expression)
what is used for true and false in scheme?
t and #f (or () for false)
What are the predicate values for numbers with multiple parameters?
=, <>, > ,<, >= and <=
Predefined predicate functions for numbers, single value test.
even?,odd?,zero?,negative?,positive?
what does <> mean?
not equals
how does a if function look like?
(if predicate then_exp else_exp)
example
(define (divide number denom)
(if (<> denom 0)
(/ number denom) // returns this if true
0 // returns this if false
)
)
what is the cond function?
conditional control flow function
how does the cond function work?
“Accepts” the 1st expression that evaluates to true.
if no expression is true it goes to the else expression if there is one
how is repetition handled?
through recursion
how is a list created?
‘(A B) or (quote (A B))
how does “list” work in scheme?
(list ‘A ‘B ‘C) yields (A B C)
(list ‘A ‘B ‘(C D)) yields (A B (C D ))
How do you get the 1st element of a list?
(car list)
how do you get the remainder of a list after its 1st element has been removed?
(cdr list)
what does cons do?
outs the 1st oarameter into the 2nd parameter (a list) to make a new parameter
examples of cons
(cons ‘A ‘(B C)) = (A B C)
(cons ‘(A B) ‘(C D)) = ((A B) C D)
(cons ‘() ‘(A B)) = (() A B)
(cons ‘A ‘B) = (A . B)
(cons ‘(A B) ‘C) = (( A B) .C)
How many parameters does list? take?
1
What does the null? predicate function do?
Checks if the list is empty ( (()) is not an empty list)
what does eqv? do?
checks if 2 values are the same.
Doesnt work for lists but does work for (eqv? ‘A ‘A)
what does eq? check?
if the 2 parameters are the same object in memory (for 2 list parameters or numeric atoms the result is not reliable)
What is the general form of let?
(let ((name1 exp1)(name2 exp2))body that uses the names in the bindings)
what does the let construct yield?
the value of the last application
What does the member function do?
Checks if an atom is in a simple list
With which function do you check if 2 lists are equal?
equalsimp
how is equal different from equalsimp?
equalsimp = atoms, equal = atoms + lists
What does (append lis1 lis2) yield?
all elements of list 1 followed by all elements of list 2
When is a recursive function tail recursive?
When the recursive call is the last operation in the function
What does mapcar do?
“Does” the function to everything in the list
(define (add-two number)
(+ number 2))
(mapcar add-two ‘(1 3 5 7))
results in (2 5 7 9)
What is a function that builds code
A function that can build code that can be executed
What is LISP used for?
AI
What is scheme used for?
To teach intro to programming
Other name for Logic programming languages
Declarative Programming languages
How are logic programs expressed?
Form of symbolic logic
Is it declarative or procedural?
Declarative: Only specify the form of results
What is a proposition?
Logical statement that can be true or false
What does a proposition consist of?
1+ objects and Relationships among objects
What are the 3 basic needs of formal logic?
Express propositions
Express relationships between propositions
Describe how new propositions can be inferred from other propositions
What is 1st order predicate calculus.
Form of symbolic logic that is used for logic programming
Object representation in predicate calculus
Represent objects in propositions.
What is a constant in predicate calculus?
A symbol that represents a particular object
What is a variable in predicate calculus?
A symbol that can represent different objects at different times
Is variables in imperative languages the same as in predicate calculus?
No
What are the 2 types of propositions?
Atomic propositions
Compound propositions
How does atomic propositions differ from compound propositions?
Compound propositions represent mathematical relations (written like mathematical functions)
Atomic propositions are represented by compound terms
What are the 2 parts of a compound term?
Functor (function symbol that names the relation)
Ordered list of parameters (tuples)
Example of a compound term:
student(jon)
like(seth, osx)
What are the 2 forms of propositions?
Fact: (assumed to be true)
Query: Truth of a proposition is to be determined
Example of fact and query
Fact = Jon is a student
Query = Can you prove that Jon is a student?
What are compound propositions?
2+ atomic propositions where atomic propositions are connected by operators
What are the 5 logical Operators?
negation
conjunction
disjunction
equivalence
implication
How many logical operators are there?
5
What are the quantifiers and and what do they mean?
Universal (upside down A) AX.P -> For all X, P is True
Existential (Backwards E) EX.P -> There exists a value of X such that P is true
How do we infer facts from known propositions?
Using resolution since resolution is an inference principle
What does the unification process do?
Finds values for variables in propositions that allow the matching process to succeed
What is instantiation?
Assigning temporary values to variables to allow unification to succeed
What happens if matching fails when instantiating a variable?
You backtrack and instantiate the variable with a different value
Steps of Proof by Contradiction
Hypotheses (set of assumed propositions)
Theorem (new proposition we want to infer)
Goal (Negation of theorem stated as a proposition)
Proof by contradiction (Theorem proved by finding an inconsistency with the goal)
What are Horn Clauses?
An “if-then” statement
What are the different types of Horn Clauses?
Headed (single atomic propositions on the left)
Headless (Empty left side)
Headed Horn Clause example
Rich(X) ∨ WorksHard(X) ∧ OwnsBusiness(X)
Rich(X) (Someone is rich) is true if WorksHard(X) (they work hard) and OwnsBusiness(X) (they own a business) are both true.
Headless Horn Clause
father(bob, jake)
bob is the father of jake
What type of clauses are
1) Facts
2) Queries
3) Rules
1+2) Headless
3) Headed
Which is simpler, Logic programming semantics or imperative language semantics?
Logic programming
Overview of logic programming
Programs only state the form of the result (not how its computed)
Uses predicate calculus (descriptive
Difference between imperative and logic using a “Sort the list” example
imperative = Describe Alg. to sort the list. Computer executes the steps of the Alg
Logic = describe the characteristics of a sorted list
Why was prolog designed?
For natural language processing
When was prolog designed?
1970s
A constant, variable or structure describes what in prolog?
A term
What is a constant in prolog?
An atom on int
What do atoms consist of in Prolog?
string of letters, digits and underscores starting with a lowercase letter
What do variables consist of in Prolog?
String of letters, digits and underscores starting with a uppercase letter
What are the kind of statements in prolog?
Fact, Rule and Goal statements
Example of a fact statement:
male(bill)