Need help translating Lisp code into C#
Posted: Sat Nov 28, 2009 1:39 pm
Hello all,
This is my first post, hopefully it's in the correct place. I am in the process of translating a program from Common Lisp into C#, most of it has gone smoothly but I have run across two blocks of code that are giving me a bit of trouble. The two functions I am having difficultly are the first two I list below. I am including the the last function, COUNT-THEM, because it is being used in the first function. If anyone can help me translate these two pieces of code into C#, or even simply translate them into pseudo code that I can understand (then I can translate it into C# myself), I'd be very grateful.
Thanks in advance for any assistance you all can provide!
The COUNT-HIGHEST function:
The MY-SORT function:
The COUNT-THEM function:
FYI:
array-2 referenced in above is initially defined as:
Also, if anyone is curious, these pieces of code come from a program called "Network" written by David Cope. The full program along with others can be found here. Unfortunately all of his files are archived in .sit format, so you'll need StuffIt Expander to open them.
This is my first post, hopefully it's in the correct place. I am in the process of translating a program from Common Lisp into C#, most of it has gone smoothly but I have run across two blocks of code that are giving me a bit of trouble. The two functions I am having difficultly are the first two I list below. I am including the the last function, COUNT-THEM, because it is being used in the first function. If anyone can help me translate these two pieces of code into C#, or even simply translate them into pseudo code that I can understand (then I can translate it into C# myself), I'd be very grateful.
Thanks in advance for any assistance you all can provide!
The COUNT-HIGHEST function:
Code: Select all
(defun COUNT-HIGHEST (lists)
"Returns the highest occuring pattern in its arg."
(let* ((sorted-numbers (my-sort #'< (mapcar #'second lists)))
(numbers-only (remove-duplicates sorted-numbers))
(counts (count-them numbers-only sorted-numbers)))
(find-all (nth (position (first (my-sort #'> counts)) counts) numbers-only) lists)))
Code: Select all
(defun MY-SORT (function lists)
"Non-destructive sort function."
(loop for item in (sort (loop for array-2 in lists
collect (list array-2)) function :key #'car)
collect (first item)))
Code: Select all
(defun COUNT-THEM (singles numbers)
"Returns the counts of its first arg in its second arg."
(if (null singles)()
(cons (count (first singles) numbers)
(count-them (rest singles) numbers))))
array-2 referenced in above is initially defined as:
Code: Select all
(defVar ARRAY-2 (make-array (list 5)))