Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

Class notes 21CSC203P (APP)

Beoordeling
-
Verkocht
-
Pagina's
24
Geüpload op
23-11-2025
Geschreven in
2025/2026

This document contains the complete APP syllabus in clear, easy-to-understand notes. All units are explained in a structured format so you can study faster and score better. Included in this file: Full APP course coverage Unit-wise notes Important definitions & formulas Exam-focused explanations Short revision notes for quick study Clean and well-organized format Useful for assignments, tests, and semester exams These notes are perfect for students who want a complete, ready-to-study material without searching multiple sources. Simple language, neat presentation, and fully exam-oriented content. If you want to prepare the entire APP subject quickly and effectively, these notes are exactly what you need.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

Unit 4


Functional programming: Functional programming is a programming paradigm in which code is
structured primarily in the form of functions. The origins of this programming style arise from a branch of
mathematics known as lambda calculus, which is the study of functions and their mathematical properties.
In contrast to the popular object-oriented and procedural approaches, functional programming offers a
different way of thinking when solving a problem.

Concepts of Functional Programming: Any Functional programming language is expected to follow
these concepts.

• Pure Functions: These functions have two main properties. First, they always produce the same
output for the same arguments irrespective of anything else. Secondly, they have no side-effects
i.e. they do modify any argument or global variables or output something.
• Recursion: There are no “for” or “while” loop in functional languages. Iteration in functional
languages is implemented through recursion.
• Functions are First-Class and can be Higher-Order: First-class functions are treated as first-class
variable. The first-class variables can be passed to functions as a parameter, can be returned from
functions or stored in data structures.
• Variables are Immutable: In functional programming, we can’t modify a variable after it’s been
initialized. We can create new variables – but we can’t modify existing variables.

Pure Functions: Pure functions have two properties.
• It always produces the same output for the same arguments. For example, 3+7 will always be 10
no matter what.
• It does not change or modifies the input variable.
The second property is also known as immutability. The only result of the Pure Function is the value it
returns. They are deterministic. Programs done using functional programming are easy to debug because
pure functions have no side effects or hidden I/O. Pure functions also make it easier to write
parallel/concurrent applications. When the code is written in this style, a smart compiler can do many things
– it can parallelize the instructions, wait to evaluate results when needing them, and memorize the results
since the results never change as long as the input doesn’t change.
# writing a function that multiplies numbers by 10
def pure_func(numbers: [int]) -> [int]:
# creating a new list to store the results
new_nums = []
# looping over the original input list
for num in numbers:
# appending newly calculated numbers into the new list
new_nums.append(num * 10)
return new_nums

original_nums = [1, 2, 3, 4]

,changed_nums = pure_func(original_nums)
print(orginal_nums)
print(changed_nums)


Functions are First-Class and can be Higher-Order:
First-class objects are handled uniformly throughout. They may be stored in data structures, passed as
arguments, or used in control structures. A programming language is said to support first-class functions if
it treats functions as first-class objects.
Properties of first class functions:
• A function is an instance of the Object type.
• You can store the function in a variable.
• You can pass the function as a parameter to another function.
• You can return the function from a function.
• You can store them in data structures such as hash tables, lists, …

# Python program to demonstrate
# higher order functions
def shout(text):
return text.upper()
def whisper(text):
return text.lower()
def greet(func):
# storing the function in a variable
greeting = func("Hi, I am created by a function passed as an argument.")
print(greeting)

greet(shout)
greet(whisper)



Higher Order Functions
Before moving on to read about higher-order functions, let's understand how functions can be used as first-
class objects.
In languages that do not support functional programming, the functions can either be defined or called.
However, in languages that support functional programming, there are functions that are treated as first-
class objects or first-class citizens.
Here, we can use functions as any other data, i.e. we can store them in variables, we can also pass them to
other functions and return them from other functions just like we do with other variables. Let's look at some
code that demonstrates these.
# a simple function that prints text
def function():
print("I'm just a function!")

, # function call
function()
# assigning the function to a variable
another_name_for_function = function()
# using the newly assigned variable to call the function
another_name_for_function()
Output:
I'm just a function!
I'm just a function!
In line number 6, we're just creating a new reference to the pure function function() that is
named another_name_for_function. Now you can call the function() using the variable as well, as we did
in line 7. Take a look at a few more examples.
def another_func():
print("Just another function!")
# printing a few objects, along with a function as an object
# printing the function will return a function object
print("dog", another_func, 31)
Output:
dog <function another_func at 0x7f81b4d29bf8> 31
You can display a function using the print() method as above.
# creating a list containing a function
some_objects = ['dog', another_func, 31]
print(some_objects[1])
# calling the function from the list showing object behavior of functions
print(some_objects[1]())
Output:
<function another_func at 0x7f735844b280>
Just another function!
It is also possible to store a function in a list much like any other object and call it.
Now, coming to higher-order functions. We know that functions can be passed to other functions are
parameters and that is exactly what we do in higher-order functions. Higher-order functions essentially
either accept other functions as parameters or return other functions. Let's look at some code to demonstrate
higher-order functions.
# a non-generic function that only writes the input text
def write_multiple(text: str, n: int):
for i in range(n):
print(text)
# this function call will print the input text 6 times
write_multiple("word", 6)
Output:
word
word
word
word

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
23 november 2025
Aantal pagina's
24
Geschreven in
2025/2026
Type
College aantekeningen
Docent(en)
Harshit mehta sir
Bevat
Alle colleges

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
nitin8

Maak kennis met de verkoper

Seller avatar
nitin8 SRM Institute of Science and Technology
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
6 maanden
Aantal volgers
0
Documenten
8
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen