Procedural and Object-oriented Programming 1

# Unit 5 – Programming Part II

Lists · Tuples · for loops · and a real Rexx parser

# Lists

Sequences

# Lists

- Array (sequence) of elements — ordered and mutable
- `[]` creates a list; access with an index (0-based)
- Insert with `append()` and `insert()`

    colors = ['blue', 'red', 'green']
    colors[1]          # => 'red'
    colors.append('orange')
    colors.insert(1, 'yellow')

Sequences

# Lists vs. Tuples

List — mutable

- Defined with `[]`
- Elements can change
- append, insert, remove

    colors = ['blue', 'red']
    colors.append('green')

Tuple — immutable

- Defined with `()`
- Elements are fixed
- Less overhead than a list

    base = ('red', 'blue')
    base[0]  # => 'red'

# for loops

Iteration · time-driven build

# Example of a for loop

- This slide builds itself on a timer — keys override it at any moment

    lectures = ['Maths', 'English', 'Computer Science']

    for lecture in lectures:
        print(f'I love {lecture}')

Output:

    I love Maths
    I love English
    I love Computer Science

# The Rexx angle

The Rexx Highlighter

# What a real parser can see

    /**
     * This is a doc-comment. The first statement, up to the first period,
     * is the summary, and the rest is the description.
     *
     * @param name Description
     */
    ::Method open Package Protected         -- Bold, underline, italic
      Expose x pos stem.

      Use Strict Arg name

      a   = 12.34e-56 + " -98.76e+123 "     -- Highlighting of numbers
      len = Length( Stem.12.2a.x.y )        -- A built-in function call
      pos = Pos( "S", "String" )      -- An internal function call
      Call External pos, len, .True         -- An external function call
      .environment~test.2.x = test.2.x      -- Method call, compound variable

      Exit "नमस्ते"G,  "P ≝ 𝔐",  "🦞🍐"     -- Unicode strings

Get in touch

# Contact

Prof. Rony G. Flatscher

Institute for Society and Information Systems

Email rony.flatscher@wu.ac.at

Web wu.ac.at/en/isis

Office Welthandelsplatz 1, D2-C, A-1020 Vienna

Josep Maria Blasco

Rexx Parser · EPBCN

Email josep.maria.blasco@epbcn.com

Web rexx.epbcn.com/rexx-parser

Office Barcelona

section
· code style
· ⓘ