Programming Languages (CS 3270) Quiz 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

what are 2 languages that use column-major order

1. FORTRAN 2. MATLAB

What are the fundamental operations of a pointer?

1. assignment 2. dereferencing

examples of operators

1. conjunction 2. disjunction 3. negation 4. implication

What are some problems with pointers?

1. dangling pointers 2. memory leaks

Primitive Data Types

1. data types that are not defined in terms of other data types 2. almost always an exact reflection of hardware

What does a data type do?

1. defines a set of possible values (domain) together with a set of pre-defined operations 2. defines how to interpret bit strings of various lengths

Prolog Rules

1. describe known implications/relations 2. theorems that allow the interpreter to infer things 3. horn clause with head AND body (generally contain variables)

Ways to combat infinite recursion in prolog

1. making rules left or right recursive as needed 2. put base case rules first

properties of associative arrays

1. maps arbitrary indices to values 2. elements are essentially key-value pairs

Elements of Record Descriptor

1. name 2. type 3. offset (address relative to the beginning of the records)

What are the length types for strings?

1. static 2. limited dynamic 3. dynamic

predicate calculus

A particular form of symbolic logic used for logic programming.

dangling pointer

A pointer that points to a heap-dynamic variable that has been deallocated

knowledge base

"world" or "universe" in Prolog; consists of the facts

Tuple Types

A tuple is a data type that is similar to a record, except that the elements are not named

Fixed heap-dynamic array

An array in which the subscript ranges and the storage binding are both fixed after storage is allocated. Additionally, both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap.

Examples of composite types in different languages

C/C++ - struct Ada/Pascal - record python - named tuple kotlin- data class

What are 2 solutions to the dangling pointer problem?

1. tombstone 2. locks and keys

heap-dynamic array

The binding of indices and storage allocation is dynamic and can change any number of times

rectangular array

a multi-dimensioned array in which all of the rows have the same number of elements and all columns have the same number of elements

Composite (record) Types

aggregate of possibly heterogeneous data elements in which elements are identified by names

elliptical references (to records)

allow leaving out record names as ling as reference is unambiguous

Horn Clause

clause consisting of a head (LHS) and a body (RHS); the head is a single atomic proposition (term) and the body is a list of terms

another name for logic languages

declarative languages

unification

process by which compatible statements are merged

discriminated union

unions are type checked and require that each union include an indicator called a discriminant

operators

used to connect two or more atomic propositions

Quantifiers

used to include variables in propositions (universal or existential)

Pointer type

variable that has a range of values that consists of memory addresses and a special value, null

buffer overflow

when a program writing data to a buffer overruns the buffer's boundary and overwrites adjacent memory locations

What is the meaning of dog(X) :- barks(X) in Prolog?

If X barks, then X is a dog.

symbolic logic

Logic which can be used to 1. Express propositions 2. Express relationships between propositions 3. Describe how new propositions can be inferred from other propositions (basic needs of formal logic)

Fixed Stack-Dynamic Array

Subscript ranges are statically bound, but allocation is done at declaration elaboration time.

Prolog Term

a constant, variable, or structure

trivial unification

a goal can be unified with itself

consult

a predefined predicate to read a program from a file into the database

reference type

a special kind of pointer type that is used primarily for formal parameters (advantages of pass-by-pointer & pass-by-value)

Union Type

a type whose variables are allowed to store different type values at different times during execution

enumeration type

a user defined ordinal type; all possible values are provided in the definition

array

an aggregate of homogenous data elements in which an individual element is identified by its position in the aggregate

Heterogeneous Array

an array whose elements can be different types (normally heap-dynamic)

Prolog Constant

an atom or an integer

what does [ ] represent in Prolog?

an empty list

resolution

an inference rule that allows inferred propositions to be computed from given propositions (basically the transitive property)

variables start with

an uppercase letter or an underscore

what accounts for 10-16% of publicly reported security vulnerabilities in the US?

buffer overflow

What manages static descriptors?

compiler

structure

consists of a functor and a parenthesized list of arguments

one essential characteristic of logic programming languages

declarative semantics: there is a simple way to determine the meaning of each statement, and it does not depend on how the statement might be used to solve a problem

heap

dynamically allocated memory

terms that first appear on the RHS of a clause have what kind of qualifiers?

existential (there exists)

Tombstone

extra heap cell as a pointer to the heap-dynamic variable

A clause with no body

fact

basis of logical programming

formal logic

a variable that does not have a value yet but corresponds to a constant or value in another clause

gets instantiated with that value

what is pointer dereferencing?

getting the value stored at the location represented by the pointer's value

a clause with no head

goal/query

Static Array Binding

index ranges are statically bound and storage allocation is static (before runtime)

examples of primitive data types

int bool float complex decimal char

examples of primitive ordinal types

int char bool

logic languages

languages whose programs are expressed in a form of symbolic logic and use logical inferencing process to produce results (declarative rather than procedural)

proposition

logical statement that may or may not be true. It consists of objects and the relationships among objects

backtracking

looking through the database for something else with which to unify

memory leak

lost heap-dynamic variable (no longer accessible to user program)

constants and atoms start with

lowercase letter

indexing

mapping from indices to elements

array access function

maps subscript expressions to an address in the array

jagged array

multidimensional array where rows can have varying number of elements

fully qualified references to records

must include all record names

free union

no language support for type checking (unsafe)

what can prolog predicates return

only true or false (depending on if the predicate can be satisfied)

array operations

operations that operate on the array as a single unit ex: the + operator between 2 arrays results in an array of the sums of the element pairs

how does locks-and-keys work?

pointer values are represented as (key,address) pairs heap-dynamic variables are represented as variable plus cell for integer lock value when heap-dynamic variable allocated, lock value is created and placed in lock AND key cell of pointer each dereference must compare the key and the lock

fundamental difference between pointers and references

pointers refer to addresses in memory while references refer to objects or values in memory

What type of clause is happy(Person) :- woman(Person), wealthy(Person)

rule

a clause with a body AND a head

rule

What manages dynamic descriptors?

runtime system

what is pointer assignment?

setting a pointer variable's value to an address

slice

subsection of an array (a referencing mechanism useful in languages with array operations)

what constructs all prolog statements and data?

terms

How does the tombstone work?

the actual pointer variable points only at tombstones, when a heap-dynamic variable is de-allocated, the tombstone remains but it is set to null

what is the scope of a variable in prolog?

the clause in which it appears

descriptor

the collection of the attributes of a variable

when you pose a query to Prolog, it will return

the first answer it finds

arity

the number of arguments of a function.

Type Checking

the process where a compiler/runtime system detects misuse of data types

what does an underscore as an argument mean when entering a query in presidents

the value of that argument does not matter

why are pointers/references necessary for a language?

they are necessary for dynamic data structures

True or False: Changing the order of statements in the database can give you different results

true; it can lead to infinite loops or result in inefficiency

ordinal type

type in which the range of possible values can be easily associated with the set of positive integers

What types of clauses are the following? 1. woman(jean) 2. man(fred) 3. wealthy(jean)

unit clauses (facts)

terms that first appear on the LHS of a clause have what kind of qualifiers?

universal (for all)

associative arrays

unordered collection of data elements that are indexed by an equal number of values called keys


Conjuntos de estudio relacionados

Lippincott the child with health problems of the urinary system

View Set