Introduction to RPAL Module 10.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez
Topics The RPAL Language “Turing complete” 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”
RPAL is a subset of PAL 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 !!
Simple one-line RPAL programs 3 //comment: value is 3, print nothing (3+1)*4**2 // arithmetic: value is 64, prints nothing ’Hello World’ // value is ’Hello World’ Print(’Hello World’) // Prints ’Hello World’, value is dummy Print(Conc ’Hello ’ ’World’) // same 4*6 < 27 // value is true (not ’true’) 2 < 0 -> 3 | 6 // conditional (like the ?: operator) true or false // value is true true & false // value is false, & is the ‘and’ operator
data types and operators 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
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
New data type: function (fn x. B) 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, typeless function that take typeless parameter y, and returns x+y.”
Function application 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
Type Identification Functions Intrinsic functions. Applied to a value, return true or false: Isinteger x Istruthvalue x Isstring x Istuple x Isfunction x Isdummy x
Rpal constructs Operators Function definitions Constant definitions (parameterless function) Conditional expressions Function application Recursion
RPAL Has Six Data Types: 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)
summary RPAL Language of expressions To run it, evaluate it. Arithmetic, boolean, string operations. New data type: function. New operation: function application.