-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncs.py
More file actions
42 lines (31 loc) · 685 Bytes
/
funcs.py
File metadata and controls
42 lines (31 loc) · 685 Bytes
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
40
41
42
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from operator import *
from math import *
# add1, adds 1 to a value (succ in Haskell)
def add1(x):
return add(x, 1)
# sub1, sub 1 from a value (pred in Haskell)
def sub1(x):
return sub(x, 1)
# Simple square
def square(x):
return pow(x, 2)
# Simple cube
def cube(x):
return pow(x, 3)
# Curry the pow() function to accept a value and return a new function
def power(x):
return lambda p: pow(p, x)
# Head of a sequence
def head(x):
return list(x)[0]
# Tail of a sequence
def tail(x):
return list(x)[1:]
# Test if a function is even or odd
def even(x):
return not x&1
def odd(x):
return x&1
# end