This file contains hidden or 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
| fun duplicate(L) = | |
| if L=nil then nil | |
| else hd(L)::hd(L)::duplicate(tl(L)); |
This file contains hidden or 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
| fun duplicate(nil) = nil | |
| | duplicate(x::xs) = x::x::duplicate(xs); |
This file contains hidden or 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
| fun reverse(nil) = nil | |
| | reverse(x::xs) = reverse(xs)@[x]; | |
| fun ends(L) = | |
| [hd(L), hd(reverse(L))]; |
This file contains hidden or 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
| fun eval(nil, a) = 0.0 | |
| | eval(p::ps, a) = p + eval(ps, a)*a; |
This file contains hidden or 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
| fun evenel(nil) = nil | |
| | evenel(nil::zzs) = evenel(zzs) | |
| | evenel([x]::zzs) = evenel(zzs) | |
| | evenel((x::y::zs)::zzs) = y::evenel(zs::zzs); |
This file contains hidden or 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
| fun exists(p, nil) = false | |
| | exists(p, x::xs) = p(x) orelse exists(p, xs); |
This file contains hidden or 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
| open TextIO; | |
| exception Syntax; | |
| fun digit(c) = (#"0" <= c andalso c <= #"9"); | |
| fun integer(IN, i) = | |
| case lookahead(IN) of | |
| SOME c => | |
| if digit(c) then | |
| (input1(IN); |
This file contains hidden or 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
| fun factorial(n) = | |
| if n = 1 then 1 | |
| else n * factorial(n-1); |
This file contains hidden or 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
| fun factorial n = | |
| let | |
| fun fact1 1 result = result | |
| | fact1 n result = fact1 (n-1) (n * result) | |
| in | |
| fact1 n 1 | |
| end; |
This file contains hidden or 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
| fun factorial_pat(1) = 1 | |
| | factorial_pat(n) = n * factorial_pat(n-1); |