-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stuff that made it into the article.
- Loading branch information
Showing
18 changed files
with
1,616 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Unit-Test-Based Programming | ||
=========================== | ||
|
||
UTBP is a new subparadigm of Declarative Programming, in which code is generated from a description of its intended behavior, specified through unit tests. This work was presented at SIGBOVIK 2014. | ||
|
||
For more information, read doc/article.pdf or point your browser to http://blog.debiatan.net/utbp.html . | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
add: ((number number) number (define add (lambda (a b) (if a (add (pred a) (succ b)) b)))) | ||
mul: ((number number) number (define mul (lambda (a b) (if a (add (mul (pred a) b) b) 0)))) | ||
logical_not: ((number) number (define logical_not (lambda (a) (if a 0 (succ a))))) | ||
logical_or: ((number number) number (define logical_or (lambda (a b) (if a a b)))) | ||
logical_and: ((number number) number (define logical_and (lambda (a b) (if a b 0)))) | ||
logical_nand: ((number number) number (define logical_nand (lambda (a b) (logical_not (logical_and b a))))) | ||
logical_xor: ((number number) number (define logical_xor (lambda (a b) (if a (logical_not b) b)))) | ||
logical_parity: ((list) number (define logical_parity (lambda (l) (if l (logical_xor (logical_parity (cdr l)) (car l)) 0)))) | ||
index: ((list number) S-expression (define index (lambda (l a) (if a (index (cdr l) (pred a)) (car l))))) | ||
length: ((list) number (define length (lambda (l) (if l (succ (length (cdr l))) 0)))) | ||
sum: ((list) number (define sum (lambda (l) (if l (add (sum (cdr l)) (car l)) 0)))) | ||
power: ((number number) number (define power (lambda (a b) (if b (mul (power a (pred b)) a) 1)))) | ||
factorial: ((number) number (define factorial (lambda (n) (if n (mul (factorial (pred n)) n) 1)))) |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from utbp import UTBP | ||
|
||
@UTBP | ||
def add(a, b): | ||
""" | ||
add(2, 2) == 4 | ||
add(3, 3) == 6 | ||
""" | ||
|
||
@UTBP | ||
def mul(a, b): | ||
""" | ||
mul(2, 2) == 4 | ||
mul(3, 5) == 15 | ||
""" | ||
|
||
@UTBP | ||
def power(a, b): | ||
""" | ||
power(1, 1) == 1 | ||
power(2, 3) == 8 | ||
power(5, 3) == 125 | ||
power(5, 2) == 25 | ||
power(5, 0) == 1 | ||
""" | ||
|
||
@UTBP | ||
def factorial(n): | ||
""" | ||
factorial(0) == 1 | ||
factorial(1) == 1 | ||
factorial(2) == 2 | ||
factorial(3) == 6 | ||
""" | ||
|
||
if __name__ == '__main__': | ||
assert add(23, 23) == 46 | ||
assert mul(8, 8) == 64 | ||
assert power(2, 4) == 16 | ||
print(factorial(4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from utbp import UTBP | ||
|
||
@UTBP | ||
def index(l, a): | ||
""" | ||
index((4, 7, 8), 1) == 7 | ||
index((4, 7, 8), 2) == 8 | ||
index(((4, 7), 8), 0) == (4, 7) | ||
""" | ||
|
||
@UTBP | ||
def length(l): | ||
""" | ||
length(()) == 0 | ||
length((2, 2, 2, 2, 2)) == 5 | ||
""" | ||
|
||
@UTBP | ||
def add(a, b): | ||
""" | ||
add(2, 2) == 4 | ||
add(3, 3) == 6 | ||
""" | ||
|
||
@UTBP | ||
def sum(l): | ||
""" | ||
sum((2, 2)) == 4 | ||
sum((3, 3, 3)) == 9 | ||
""" | ||
|
||
|
||
if __name__ == '__main__': | ||
assert index((2, 3, 4), 1) == 3 | ||
assert length((4, 4, 4)) == 3 | ||
assert add(23, 23) == 46 | ||
assert sum((8, 8, 8, 8)) == 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from utbp import UTBP | ||
|
||
@UTBP | ||
def logical_not(a): | ||
""" | ||
logical_not(1) == 0 | ||
logical_not(0) == 1 | ||
""" | ||
|
||
@UTBP | ||
def logical_or(a, b): | ||
""" | ||
logical_or(0, 0) == 0 | ||
logical_or(0, 1) == 1 | ||
logical_or(1, 0) == 1 | ||
logical_or(1, 1) == 1 | ||
""" | ||
|
||
@UTBP | ||
def logical_and(a, b): | ||
""" | ||
logical_and(0, 0) == 0 | ||
logical_and(0, 1) == 0 | ||
logical_and(1, 0) == 0 | ||
logical_and(1, 1) == 1 | ||
""" | ||
|
||
@UTBP | ||
def logical_nand(a, b): | ||
""" | ||
logical_nand(0, 0) == 1 | ||
logical_nand(0, 1) == 1 | ||
logical_nand(1, 0) == 1 | ||
logical_nand(1, 1) == 0 | ||
""" | ||
|
||
@UTBP | ||
def logical_xor(a, b): | ||
""" | ||
logical_xor(0, 0) == 0 | ||
logical_xor(0, 1) == 1 | ||
logical_xor(1, 0) == 1 | ||
logical_xor(1, 1) == 0 | ||
""" | ||
|
||
@UTBP | ||
def logical_parity(l): | ||
""" | ||
logical_parity((0,)) == 0 | ||
logical_parity((1,)) == 1 | ||
logical_parity((0, 0)) == 0 | ||
logical_parity((0, 1)) == 1 | ||
logical_parity((0, 0, 0)) == 0 | ||
logical_parity((0, 0, 1)) == 1 | ||
logical_parity((0, 1, 1)) == 0 | ||
""" | ||
|
||
if __name__ == '__main__': | ||
assert logical_not(1) == 0 | ||
assert logical_or(1, 1) == 1 | ||
assert logical_and(1, 1) == 1 | ||
assert logical_nand(1, 1) == 0 | ||
assert logical_xor(1, 1) == 0 | ||
assert logical_parity((1, 1, 1, 1, 0, 0, 1, 1)) == 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
def factorial(n): | ||
""" | ||
Returns the factorial of n | ||
int -> int | ||
>>> factorial(2) | ||
2 | ||
>>> factorial(3) | ||
6 | ||
""" | ||
if n: | ||
return n*factorial(n-1) | ||
else: | ||
return 1 | ||
|
||
print(factorial(1)) | ||
print(factorial(2)) | ||
print(factorial(3)) | ||
print(factorial(4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
from utbp import UTBP | ||
|
||
@UTBP | ||
def add(a, b): | ||
""" | ||
add(2, 2) == 4 | ||
add(3, 3) == 6 | ||
""" | ||
|
||
assert add(23, 23) == 46 | ||
|
||
|
Oops, something went wrong.