Hello all,

I am in the process of translating a program from 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. If anyone can help me translate these two pieces of code into C# I'd be very grateful.

The COUNT-HIGHEST function:

(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)))

And the sort function that it calls:

(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)))

FYI: array-2 is an array of floats.
Thanks!

BTW:
If anyone is curious, these two 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.

Maybe someone in here will know LISP, but you would probably get a much faster response if you translate the above LISP code into pseudo code first, then we can translate that into C# code.

Maybe someone in here will know LISP, but you would probably get a much faster response if you translate the above LISP code into pseudo code first, then we can translate that into C# code.

Thanks for the response DdoubleD,

Well that is sort of my problem too, if I could translate the code into pseudo code then I could translate it into C# myself =)

I have managed to translate the majority of the program into C#, and I even understand most of the 2 snippets I need help with, but unfortunately the lisp syntax in a couple of those lines is beyond my grasp (even with the aid of reference materials), so I'm not totally certain what is going on.

Oops, I realized that I left out a function that is being called by COUNT-HIGHEST that might help someone understand better what is going on. Here it is:

(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))))

The first step to understand is that (loop for item in foo collecting bar) will ...

Heck, install SBCL yourself and run the code and do experiments that figure it out.

This article has been dead for over six months. Start a new discussion instead.