Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (print("print me daddy 0w0\n") ; 69)
- ???????????????????????????????????????????????????????????????????????????????????????????
- let
- type intList = {head: int, tail: intList}
- function cons(elem:int, list:intList):intList = intList{head = elem, tail = list}
- function length(list:intList):int = if list = nil
- then 0
- else 1 + length(list.tail)
- function concat(l1:intList, l2:intList):intList = if l1 = nil
- then l2
- else cons(l1.head, concat(l1.tail, l2))
- function snoc(elem:int, list:intList):intList = concat(list, intList{head = elem, tail = nil})
- function filtra(filter:int, list:intList):intList =
- if list = nil
- then nil
- else if list.head = filter
- then filtra(filter, list.tail)
- else cons(list.head, filtra(filter, list.tail))
- function isin(elem:int, list:intList):int =
- if list = nil
- then 0
- else if list.head = elem
- then 1
- else isin(elem, list.tail)
- function remove(elem:int, list:intList):intList =
- if list = nil
- then nil
- else if list.head = elem
- then list.tail
- else cons(list.head, remove(elem, list.tail))
- function removeall(elem:int, list:intList):intList =
- if list = nil
- then nil
- else if list.head = elem
- then removeall(elem, list.tail)
- else cons(list.head, removeall(elem, list.tail))
- function reverse(list: intList):intList =
- if list = nil
- then nil
- else snoc(list.head, reverse(list.tail))
- function printint(i : int) =
- let function f(i : int) =
- if i > 0
- then (f (i/10); print(chr(i-i/10*10+ord("0"))))
- in if i < 0
- then (print("-"); f(i))
- else if i>0
- then f(i)
- else print("0")
- end
- function printlist(list: intList):int =
- if list = nil
- then (print("\n") ; 420)
- else (printint(list.head) ; print(" ") ; printlist(list.tail))
- in
- printlist(filtra(73, reverse(cons(3,cons(73, cons(100, cons(73, nil)))))))
- /*(printint( isin(73, cons(3,cons(73, cons(100, nil))))) ; 5)*/
- end
- ???????????????????????????????????????????????????????????????????????????????????????????
- let
- function printint(i : int) =
- let function f(i : int) =
- if i > 0
- then (f (i/10); print(chr(i-i/10*10+ord("0"))))
- in if i < 0
- then (print("-"); f(i))
- else if i>0
- then f(i)
- else print("0")
- end
- type tree = {key : int, children : treelist}
- type treelist = {hd : tree, tl : treelist}
- function length(tList : treelist):int =
- if tList = nil
- then 0
- else 1 + length(tList.tl)
- function isBin(t : tree):int =
- (length(t.children) < 3) & isBinList(t.children)
- function isBinList(tList : treelist):int =
- if tList = nil
- then 1
- else isBin(tList.hd) & isBinList(tList.tl)
- function isComp(t : tree):int =
- (length(t.children) = 0 | length(t.children) = 2) & isCompList(t.children)
- function isCompList(tList : treelist):int =
- if tList = nil
- then 1
- else isComp(tList.hd) & isCompList(tList.tl)
- var tunit := tree{key = 3, children = nil}
- in
- (printint( isBin( tree{key = 3, children =
- treelist{hd = tunit, tl =
- treelist{hd = tunit, tl =
- treelist{hd = tunit, tl =
- treelist{hd = tunit, tl =
- treelist{hd = tunit, tl = nil}}}}}} ) ) ; 420 )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement