CS 541 Lecture -*-Outline-*- * Ch. 3 Storage ** Variables and Updating (3.1) Variable is an object that contains a value, and can be inspected and updated Is it the same as a Pascal variable? Is it reasonable to include databases and files? What kind of collection is a store? (a set?) How would you define a variable using store? Does that definition have the same generality? ** Composite Variables (3.2) This is the direct model of a variable. Does it match C? Scheme? Some object-oriented languages, LISP, and ML have an indirect model. *** Total and Selective Updating (3.2.1) In ML, can you define procedures that do selective updating? Which is more general, selective or total? Which is more efficient? *** Array Variables (3.2.2) Dynamic arrays are also called semi-dynamic -- variation, when is it created (compile/run-time)? Flexible arrays are also called dynamic. Algol 68 and CLU have flexible arrays. Can you program flexible arrays in C/C++? Should they be added? Is there an efficiency difference between Pascal and Ada array variables? Is it significant? What about between Ada and CLU arrays? If a language has lists, why would it need flexible arrays? (Note: arrays are not part of the ML standard) ** Storables (3.3) Is the "cannot be selectively updated" necessary? What are the differences between storables and variables? What are the storables in C/C++? Does it make sense to say that arrays in ML are not storables? ** Lifetime (Extent) (3.4) *** Local and Global Variables (3.4.1) (See figure 3.7 -- text) Are there any variables that are NOT local? (Yes, heap variables) Do we need better terminology? v is local to block B if v is declared within B. v is global to B... Are variables reincarnated? (p. 45) Better to think of them as distinct. Static variables are also called own variables. *** Heap Variables (3.4.2) They're variables that are created/deleted independent of blocks. What does he mean: a heap variable is accessed through a pointer? (is it a defn. of pointer?) Consider LISP/Scheme? The deallocator DISPOSE was not in the original Pascal. Sharing is also called aliasing. Do you really think pointers are a "low-level concept" and "notoriously error-prone"? In object-oriented languages, does assignment typically mean reference or copying? In functional languages? *** Persistent Variables (3.4.3) What would a "file language" look like? Do you know of any? What would be some advantages of allowing all types of variables to be persistent? (p. 49) What syntax would you use? *** Dangling References (3.4.4) How can they be avoided? Which of these ways would be suitable for C/C++? What's a solution to the dangling references posed by 3.11? (closures, only allow downward) The Algol-68 idea is a very early form of subtyping. ** Commands (3.5) How can we be sure that new kinds of commands aren't needed? Or don't add to expressive power? (p. 52) *** Skips (3.5.1) Is the skip really needed? Can't it be programmed? *** Assignments (3.5.2) Are variable references first-class values in C/C++? Is simultaneous assignment an extravagance? Or is it really useful? What are some examples? (gcd) Content (rvalue) vs. reference (lvalue) Dereferencing is also explicit in Bliss, Logo. Would there be any advantage to making variable dereferencing explicit? *** Procedure Calls (3.5.3) Does the form of the actual argument always determine the parameter-passing mechanism? *** Sequential Composition (;) (3.5.4) *** Collateral (composition) (3.5.5) This is an Algol-68 term. Parallel is a synonym. Is this comma the same as in C/C++? Why would we want to add nondeterminism to a languages? Do you know of any language that has this? (several; e.g. Scheme as no defined order of evaluation for arguments to procedures) So we could define this in Scheme... (define comma (lambda (e1 e2) (skip))) Would it be wise to require collateral commands to be effectively deterministic? How do we enforce this? *** Conditional Commands (3.5.6) What are the advantages/uses of a nondeterministic IF? In a nondeterministic IF, what happens when one of the tests goes into a loop? How would the ML case work? What efficiency advantages are there in the use of CASE vs. IF? Why would a language designer not want a maximally general CASE? *** Iterative Commands (loops) (3.5.7) Indefinite: What does the first equivalence (WHILE) on p. 58 mean? "exactly equivalent? What does the repeat c1 while B do c2 look like in Ada? Can you think of an example where a loop with several conditions in the body is necessary? I thought "structured programming" (Boehm and Jacobi) meant that one could do with just a while loop...? Definite: Iteration over lists: is that definite? Does it always terminate? In CLU there are for loops that can "iterate" over any type. Why would you want to prevent assignment to the control variable of a for loop? Can for loops be run in parallel? ** Expressions with Side Effects (3.6) *** Command Expressions (3.6.1) What is a side effect? What is a command expression? Do side effects really introduce nondeterminism into expression evaluation? Would blocks (example 3.16) be a useful addition to C/C+? *** Expression-oriented Languages (3.6.2) Do you agree with the last paragraph on p. 62?