jweinst1
10/22/2016 - 9:47 PM

## schemeqs.py

``````#Transition to Scheme
"""
Scheme is a functional programming language. This means there are no classes or objects, and no methods.
More importantly, it works off a lambda calculus.
All of Scheme's function are processed with a single parameter and single return value.
The language makes heavy use of recursive linked lists called Pairs, the equivalent of tuples in Python

These problems serve as a gateway between Python and Scheme, to get used to functional style vs. object oriented.
"""

#optional tuple making function. Not required
def Pair(x, y):
return (x, y)

#Example
#Turn a Python list into a Scheme style list
"""
cons([1, 2, 3, 4])
=> (1, (2, (3, 4)))
cons([x for x in range(40)])
=> (0, (1, (2, (3, (4, (5, (6, (7, (8, (9, (10, (11, (12, (13, (14, (15, (16, (17, (18, (19, (20, (21, (22, (23, (24, (25, (26, (27, (28, (29, (30, (31, (32, (33, (34, (35, (36, (37, (38, 39)))))))))))))))))))))))))))))))))))))))

"""
def cons(lst):
if len(lst) == 1:
return lst[0]
else:
return (lst[0], cons(lst[1:]))

#Problem 2
#Create a Scheme list of descending order from n to 0
"""
dcons(7)
=> (7, (6, (5, (4, (3, (2, (1, 0)))))))
"""
def dcons(n):
pass

#Problem 3
#Make a function that counts the length of scheme list
#Hint, you will need to use isinstance here
def scheme_len(con):
pass

#Problem 4
#Write a function that sums the numbers in a scheme list
#Also, isinstance needs to be used here
"""
f = dcons(7)
=> None
sum_lst(f)
=> 28

"""
def sum_lst(con):
pass``````