JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
FUNCTIONAL PROGRAMMING LAB
M.Tech I Year II Semester (R22)
Course Objectives:
1. To be able to introduce core programming basics and program design with functions using functional programming languages.
2. To understand a range of Object-Oriented Programming, as well as in-depth data and information processing techniques.
Course Outcomes:
1. Students should be able to understand the basic concepts of scripting and the contributions of Functional Programming Languages.
2. Ability to explore python especially the object-oriented concepts, and the built in objects of Python. List of Programs:
1. Write a program to demonstrate different number data types in Python.
2. Write a program to perform different Arithmetic Operations on numbers in Python.
3. Write a program to create, concatenate and print a string and accessing sub-string from a given string.
4. Write a python script to print the current date in the following format “Sun May 29 02:26:23 IST 2017”
5. Write a program to create, append, and remove lists in python.
6. Write a program to demonstrate working with tuples in python.
7. Write a program to demonstrate working with dictionaries in python.
8. Write a python program to find largest of three numbers.
9. Write a Python program to convert temperatures to and from Celsius, Fahrenheit. [ Formula : c/5 = f-32/9 ]
10. Write a recursive function, (defun nth (pos list) ???), that returns the n'th item from a list. Assume the list has at least n items. (nth 1 aList) is to return the first item in aList.
11. Write simple lisp functions such as the following. Take into account lists which are too short.
(remove-first '( a b c ...) ) -> ( b c ...) --- remove the first item from the list.
(remove-second '(a b c ...) ) -> (a c ...) -- remove the second item from the list.
(insert-as-second 'b '(a c ...) ) -> (a b c ...) --- insert as the second element.
12. Write a Lisp macro mycase that translates the following macro call. Assume the input will be error free. The input lists can be any length. You must document your solution. (mycase (C1 C2 ... Cn) (P1 P2 ... Pn)) translates to the following (mycond (C1 P1) (C2 P2) ... (Cn Pn))
13. Write a Lisp macro mycase that translates the following macro call as shown. Assume the input will be error free. The input lists can be any length. Use standard Lisp functionals. If you need support functions, your answer should have only non-recursive support functions. (mycase (C1 C2 ... Cn) (P1 P2 ... Pn)) translates to the following (mycond (C1 (P1 P2 ... Pn)) (C2 (P2 ... Pn)) ... (Cn (Pn)) )
14. Assume the following forms have been typed into the Lisp interpreter and evaluated. ( defun a ( x ) ( values (list x) x ) ) ( setq a '( a b ) ) ( defun b ( x ) `( x ,x ) ) (setq b ( cdr a ) ) ( setq c ( car a ) ) ( setq d c ) ( setq e ( (lambda ( x ) ( list x ) ) d ) )
15. What will the following forms evaluate to? ( cons c ( car a ) ) ( cons e b ) ( eval a ) ( let (( a b ) ( y a )) ( append a y ) ) ( multiple-value-list ( a a ) ) (bc) ( set ( car a ) (cdr a) ) ( setf ( car a ) (cdr a) )
TEXT BOOKS:
1. The Haskell School of Expression: Learning Functional Programming through Multimedia, Paul Hudak.
2. Functional Programming in Python, David Mertz, O’Reilly Media.