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
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ | |
(ByVal lpClassName As String, _ | |
ByVal lpWindowName As String) As Long | |
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ | |
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, _ | |
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long | |
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ | |
(ByVal hwnd As Long, ByVal wMsg As Long, _ |
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
/* Not tail recursive. */ | |
def reverseSlow [X] (xs:List[X]) : List[X] = xs match { | |
case Nil => Nil | |
case y :: ys => reverseSlow (ys) ::: List (y) | |
} | |
/* Tail recursive. */ | |
def reverseFast [X] (xs:List[X]) : List[X] = { | |
def aux (xs:List[X], result:List[X]) : List[X] = xs match { | |
case Nil => result |
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
def duplicateN [X] (n:Int, xs:List[X]) : List[X] = (n, xs) match { | |
case (n, xs) if n < 0 => throw new RuntimeException ("illegal op: negative N") | |
case (_, Nil) => xs | |
case (0|1, xs) => xs | |
case (_, h::t) => (h::Nil) ::: copyN(n-1, h::Nil) ::: copyN(n,t) | |
} |
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
/* unzip decomposes a list of pairs into a pair of lists. | |
* The recursive case illustrates pattern-matching the result of the | |
* recursive call in order to apply an operation to the elements. | |
*/ | |
def unzip [X,Y] (ps:List[(X,Y)]) : (List[X], List[Y]) = ps match { | |
case Nil => (Nil, Nil) | |
case (x, y) :: qs => { | |
val (xs, ys) = unzip (qs) | |
(x :: xs, y :: ys) | |
} |