Document Sample
Graphics Powered By Docstoc
					159.331 Programming Languages
         & Algorithms
          Lecture 25 - Miscellaneous Other
            Programming Languages &

159.331               Prog Lang & Alg        1
            Classifying Paradigms
• We have looked at the main programming
  paradigms - can we abstract anything over
  paradigms? - See Figure
• What other major/minor paradigms can we
• Many modern system are beginning to blur our
  paradigm distinctions, as they borrow ideas from
  other paradigms and languages
• A review of some ideas will lead us on to
  modern scripting languages…
  159.331            Prog Lang & Alg           2
159.331   Prog Lang & Alg   3
            Constraint Programming
• User defines the solution to a problem as a data type,
  the domain of the solution and supplies constraints on
  it that constrain them to the desired solution
• For example, the n-queens problem in chess
   – There are exactly 8 queens on the board and no other pieces
   – No queen attacks any other queen
• Activating the system gives us the possible solutions
• This is a declarative paradigm and is usefull for
  symbolic manipulation
  159.331                  Prog Lang & Alg                    4
• A classic example concerns a program that
  manipulates temperature.
• We can specify that the Celsius temperature is
  constrained by the Fahrenheit temperature. If
  one is changed then the other is constrained
  to respond.
• Systems like Mathematica or Matlab support
  these ideas
• Tends to require little effort from the
  programmer, and can be a good prototyping
  159.331            Prog Lang & Alg           5
159.331   Prog Lang & Alg   6
       Access-Oriented Programming
• The key idea is that variables can be annotated with
  procedures that are automatically invoked when the
  variable is accessed
• The Xerox Loops language is based on this idea
• Not nearly as popular as OO
• Can be used in visualisation - update the rendering
  automatically when the simulated object has its position
• The trigger idea in database system is based on this
• Annotations can be dynamically installed or indeed be
  recursive in Loops
    159.331               Prog Lang & Alg               7
     Single Data-Structure Languages
• The paradigm can be summarised as “all the world is a …”
• APL formulates everything as an array
• Our assignment example formulated everything as a string
• Lisp takes the “all the world is a list” approach
• SETL treats everything as a set
• Generally these languages have sophisticated and powerful
  libraries to support operations on their favourite data
• They are often used for rapid prototyping

    159.331              Prog Lang & Alg              8
             Dataflow Programming
• Key idea is to have a separate processor (perhaps a
  virtual one) for every operation in the program
• Each operation waist until the values of its operands
  become available and then “fires” to carry out its
  activity and make its output available as quickly as
• The Lucid language supports this model
• Attempts have been made to implement hardware to
  support this model - sadly the model does not scale well
  to real problems which would require too many
  porocessors, and the communications technology is still
  too slow for all the fine grained communications needed
   159.331              Prog Lang & Alg               9
159.331   Prog Lang & Alg   10
159.331   Prog Lang & Alg   11
• Data flow model includes named values only - no variables
  as such
• There cannot be side effects - each processor only sees its
  own input values and can affect only its output values
• There is no global memory - the only memory there is
  exists in the interfaces pipelines between processors
• Values can be given names but there can be only one such
  definition of a given name. If redefinition were possible a
  processor would not known whether to wait for the original
  value or for its redefinition. A dataflow language must be
  single-definition - also known as single-assignment
• Processors cannot just give up on errors in their input values
  since there is no central program counter to manipulate in
  error handling. We need an explicit error value for each
  data type.
    159.331                Prog Lang & Alg                12
              Little Languages
• Intended for a special purpose
• Often thought of as a useful tool ratherthan a full
  blown language
• They often keep growing however…

  159.331             Prog Lang & Alg            13
                        Unix Shell
   for i in chap?.n
      wc $i > $i.wc &
• A simple interpreted language for manipulating file
• Has become useful for systems administration tasks and
  has given rise to a whole raft of other shells and
  interpreted languages…
    159.331               Prog Lang & Alg            14
• PIC - little language for drawing figures
• nroff/troff - old Unix little language s for
  document layout
• TeX/LaTeX - powerful “little” languages for
  document typesetting/formatting
• lex/yacc/flex/bison- language tools for writing
• awk - pattern matching language that a lot of
  modern scripting language s are based upon
• sed - streaming editor - general data filter

   159.331            Prog Lang & Alg           15
               Database Languages
• Beyond our scope to consider details but SQL - Structured
  Query Language is a language for dealing with a
  generalised relational database
• Generally the database is an abstract data type and SQL
  provides the interface to it
• Make SQL calls from your favourite programming language
  through appropriate library calls or language bindings
   select name from student_database where assignment_mark = 0
• An SQL database product often implemented as a command
  line interpreter - eg the free mysql package
• Most RDB products are just proprietary interface “bells and
  whistles” wrapped around an SQL interpreter
    159.331                Prog Lang & Alg                16
            Realtime Languages
• Needed for embedded systems
• To control devices - mobile phones and cardiac
• Sometimes meeting deadline in hard real time is the
  most important feature
• Built in clocks and time scheduling features is
• Ada tasks can read the real time clock
• We also need access to low level addresses etc for
  device/memory mapping
  159.331              Prog Lang & Alg             17
• A classification of paradigms can be based on how it suggests
  that state and its manipulation should be specified in a program
• In constraint programming the user defines the solution to a
  problem as a data type and a set of constraints. The system then
  find values of eth data type that satisfy the constraints
• In access-oriented programming, variables are annotated with
  procedures. When a variable is accessed, a procedure is invoked
  automatically. This allows the monitoring of variables and the
  propagation of effects.
• Single data structure languages simplify programming by casting
  everything into a single data structure, for which powerful
  operations are then provided

   159.331                  Prog Lang & Alg                   18
• In dataflow programming, a separate processor is
  (in principle) available for each operation in the
  program. Operations here include arithmetical and
  logical operations, function calls and if-else
  decisions. Each operation executes as soon as the
  values of its operands become available. This
  provides optimal fine-grained parallelism without
  requiring explicit programmer help.
• Little languages are intended for special purposes.
  A little language should be thought of as a “useful
  tool” rather than as a full blown general -purpose
  programming language

  159.331               Prog Lang & Alg                 19
• Relational database languages provide access to a
  compound data type, a relational database. Since all
  access to the database is through commands, it is an
  abstract data type. Typical commands are
  conditional data retrieval (selection) and conditional
  data update.
• The correctness of a real-time program depends on
  when the results are produced. Real-time programs
  are frequently used as part of embedded systems.
  Important issues are meeting deadlines, reliability
  and low-level programming.

  159.331                Prog Lang & Alg               20
           Reading Further
• Bal & Grune Chapter 7

• Next - Scripting languages…

159.331           Prog Lang & Alg   21

Shared By: