Philip W. Brooks ([info]pbrooks) wrote,
@ 2005-10-12 16:02:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
C is BAD
As part of a homework assignment a few years ago, I needed to be able to use Prolog to generate random numbers from a Gaussian (bell curve) distribution with a given mean and standard deviation. A friend found the code that does this in the Python standard library, so I translated it into Prolog.

When SWI Prolog 5.2.10 decompiles a compiled program, it names the first variable to occur A, the second B, and so on. Part of my translation of the Python looked like this in the source file:
gaussian(SD,Mean,R) :-
	gaussian_z(Z),
	!,
	retractall(gaussian_z(_)),
	R is Mean + SD * Z.
When compiled and displayed, it reads:
gaussian(A, B, C) :-
        gaussian_z(D), !,
        retractall(gaussian_z(E)),
        C is B+A*D.
In spite of its apparent dislike of the language, I've since translated this from Prolog into C (really, C++) for a quick and dirty Gaussian random number generator for use in SAGA.


Advertisement


(Read 2 comments)

Post a comment in response:

From:
Help
Identity URL: 
Username:
Password:
Don't have an account? Create one now.
Subject:
No HTML allowed in subject
   Help
Message:

 
Notice! This user has turned on the option that logs IP addresses of anonymous posters. Help
Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…