Aspects of Lisp

Pen and Paper in Pairs

x = 3


def foo(z):
    y = x + 1
    return y * z


print(foo(5), x)
x = 3


def foo(z):
    x = 4
    y = x + 1
    return y * z


print(foo(5), x)
x = 3


def foo(z):
    global x
    x = 4
    y = x + 1
    return y * z


print(foo(5), x)
x = 3


def foo(z):
    y = x + 1
    x = 4
    return y * z


print(foo(5), x)

Binding variables locally

from math import sqrt


def roots(a, b, c):
    """Find the roots of a quadratic equation with coefficients a, b, c"""
    discriminant = b**2 - 4 * a * c
    return (
        ((-b + sqrt(discriminant)) / (2 * a)),
        ((-b - sqrt(discriminant)) / (2 * a)),
    )


roots(1, -3, 2)
(2.0, 1.0)

Aspects of Lisp

etc

Author: Breanndán Ó Nualláin <o@uva.nl>

Date: 2026-04-16 Thu 09:59