Hi Simon,

> where a function allocates a new struct, and returns a pointer, which
> is then used as the first argument to all functions.

that should work.

epi:new_RNG returns a pointer which is represented as an integer
number in PicoLisp.  When you pass this integer to
epi:RNG_next_double, it gets converted back to the pointer and the C
function RNG_next_double will understand it fine.

> The code for RNG_next_double just returns integers (are these
> pointers to doubles?). How do I access a double?

PicoLisp does not have floating point numbers.  It has integer and
fixed-point numbers, see http://www.software-lab.de/ref.html#num-io
for example.

: *Scl
-> 0
: 1.0
-> 1
: (setq *Scl 4)
-> 4
: 1.0
-> 10000

As epi:RNG_next_double returns double and there are no floating point
numbers in PicoLisp, the return value is a fixed-point number (double
multiplied by 10000 and "converted to integer").

> Also, is
> (setq r (epi:new_RNG 1))
> the right way to allocate a pointer RNG* to r?


> - I saw this was on the 'todo' list.

It was on the TODO list because I did not know what the plans and
ideas were for miniPicoLisp regarding numbers.  It works, you just
need to think of a fixed-point/float number as 10000 times smaller.
This value of 10000 should not be hardcoded though but should probably
be controled by *Scl variable

Also, you can have a look at some OpenGL examples like
http://logand.com/mplisp/simul/gl/cube.l which use doubles on the C
level but use fixed-point numbers in PicoLisp.

It all depends what do you need to do with the numbers.  Floating
point numbers have their advantages and disadvantages (e.g. they cover
big range but have "holes" in them), but you might find that
fixed-point numbers will do for you well enough, especially with
(almost) 64 bit integers.



Reply via email to