130 likes | 166 Views
Introduction to RPAL. Module 10.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez. The RPAL Language No assignment No sequencing No iteration No “memory” Only expressions: every RPAL program is an expression. To run an RPAL program is to evaluate it. “Turing complete”.
E N D
Introduction to RPAL Module 10.1COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez
The RPAL Language No assignment No sequencing No iteration No “memory” Only expressions: every RPAL program is an expression. To run an RPAL program is to evaluate it. “Turing complete” Topics
PAL: Pedagogic Algorithmic Language. Developed by J. Wozencraft and A. Evans at MIT, early 70's. R(ight-reference)PAL ⊂ L(eft-reference)PAL ⊂ J(ump) PAL Intellectual ancestor of Scheme, (Guy Steele, mid-70's) Steele (Sun Microsystems): principal contributor to Java. Google: 'Guy Steele Scheme‘. Why Study RPAL ? Generic, “plain vanilla” functional language. Unknown language (to you) Paradigm shift !! RPAL is a subset of PAL
Integer operations: +, -, *, /, **, eq, ne, ls, <, gr, >, le, <=, ge, >= Truthvalue (boolean) operations: or, &, not, eq, ne String operations: eq, ne, Stem S, Stern S, Conc S T Conditional operator: -> | Elementary values: <int>, <id>, true, false data types and operators
operator Precedence Operator Precedence Associativity -> Low Right or Left & Left not None gr ge le ls eq ne None + - (unary and binary) Left * / Left ** Right () High Embedded • Elements: <id>, <int>, <str>, true, false, dummy
Has a ’bound variable’ (parameter), and a body. Example: fn X. Print(X**2) It’s value: “Nameless, typeless function with typeless parameter X, that prints X squared.” fn N. N ls 0 -> -N | N Value: “Nameless, typeless function with typeless parameter N, that returns |N|.” fn x. fn y.x+y or, equivalently fn x y.x+y Value: “Nameless, typeless function that takes typeless parameter x, and returns nameless, New data type: function (fn x. B) typeless function that take typeless parameter y, and returns x+y.”
Function application is by juxtaposition. Example: (fn X. Print(X**2)) 3 Function is applied to 3. 3 replaces X in expression Print(X**2),yielding Print(3**2), yielding Print(9), yielding dummy (and prints 9). Function application
Example: (fn N. N ls 0 -> -N | N) (-3) (-3) replaces N in (N ls 0 -> -N | N), yielding ((-3) ls 0 -> -(-3)|(-3)) ), yielding –(-3) = 3 Function application is left associative: Example: (fn x. fn y.x+y) 3 2 yielding (fn y.3+y) 2 yielding 3+2 yielding 5 Function application
Intrinsic functions. Applied to a value, return true or false: Isinteger x Istruthvalue x Isstring x Istuple x Isfunction x Isdummy x Type Identification Functions
Operators Function definitions Constant definitions (parameterless function) Conditional expressions Function application Recursion Rpal constructs
Integer Truthvalue (boolean) String Tuple (coming soon) Function Dummy (value: dummy) RPAL is dynamically typed: the type of an expression is determined at run-time. Example: let Funny = (B -> 1 | ’January’) in Print(Funny) RPAL Has Six Data Types:
summary • RPAL • Language of expressions • To run it, evaluate it. • Arithmetic, boolean, string operations. • New data type: function. • New operation: function application.