Convert some LISP to C #

I read Paul Graham A Plan for Spam and want to understand better, but my LISP is really rusty. It has a piece of code that calculates the probability as such:

(let ((g (* 2 (or (gethash word good) 0)))
      (b (or (gethash word bad) 0)))
   (unless (< (+ g b) 5)
     (max .01
          (min .99 (float (/ (min 1 (/ b nbad))
                             (+ (min 1 (/ g ngood))   
                                (min 1 (/ b nbad)))))))))

My question is twofold: (1) is there a web resource that converts LISP to another language? (my preference would be a C language) or crash (2) can someone rewrite this piece of code in C # for me?

+3
source share
2 answers

I think something like this (warning, possible errors ahead. This fragment is intended as a guide, not a solution):

var g = 2 * (gethash(word, good) | 0);
var b = gethash(word, bad) | 0;

if( (g + b) >= 5)
{
    return Math.Max( 
        0.01, 
        Math.Min(0.99, 
            Math.Min(1, b / nbad) / 
            (Math.Min(1, g / ngood) + Math.Min(1, b / nbad))));
}
+9
source

, , Lisp , # . "nbad" "ngood", , ( ) .

. # fixnum - , ( Lisp, , , ).

checked {
    var fbad = (double)nbad;
    var fgood = (double)ngood;
    var g = 2 * (gethash(word, good) | 0);
    var b = gethash(word, bad) | 0;


    if( (g + b) >= 5)
    {
        return Math.Max( 
            0.01, 
            Math.Min(0.99, 
                    Math.Min(1, b / fbad) / 
                    (Math.Min(1, g / fgood) + Math.Min(1, b / fbad))));
    }
}
+6

Source: https://habr.com/ru/post/1702281/


All Articles