Re: [pure-lang-users] C macros
Status: Beta
Brought to you by:
agraef
From: Eddie R. <er...@bm...> - 2008-08-26 13:06:06
|
On Tue, 2008-08-26 at 02:54 +0200, Albert Graef wrote: > Better yet: HYGIENIC macros. :-P I'm looking forward to playing with this. > I'm falling asleep at the keyboard (past 2:30am over here), will reply > to your questions in more detail tomorrow. Just some quick remarks: I would probably do this to if I had a computer at home. It is probably best that I don't because I would never get anything around the house done ;-) > You can make a C function fail, but only if it returns an expr* > (pure_expr* on the C side), then you can just return a null pointer. So > you need to provide a wrapper for the GSL function which returns a real > pure_expr*, that's probably not what you want I guess. But for hard > error conditions like alloc failure it would be ok to just throw a Pure > exception, no? In csv.c and csv.pure I just invoked an error rule with a message about the error. Maybe I should revisit csv.c and throw a Pure exceptions in the alloc cases? > - I'd eventually like the GSL matrices to be some kind of native type in > Pure if possible. For the time being, I'd suggest to wrap them up in a > Pure constructor (matrix p or something like that where p is the pointer > to the GSL struct or whatever it is). Yes, it is a GSL struct. I've been playing with the following constructor. Matrix (x:xs) = (gsl_matrix_alloc rows cols, rows, cols) when rows = #(x:xs); cols = #x end; To take a list of lists to convert it to the GSL struct and returns a tuple with the pointer, the number of rows and cols. Since I can access fields, I can completely do away with the rows and cols and access the rows and cols with getter functions. Now, I just need a constructor for a zero matrix and an identity matrix. So you're suggesting to differentiate matrices and vectors. I should do something like Matrix (x:xs) = matrix (gsl_matrix_alloc rows cols) when rows = #(x:xs); cols = #x end; and Vector (x:xs) = vector (gsl_vector_alloc len) when len = #(x:xs) end; ? Then the operations become: (matrix a) + (matrix b) = ... (vector a) + (vector b) = ... Am I following correctly? > - Accessing the fields of a struct through pointers in Pure is possible > (see the stuff at the end of primitives.pure), but probably > non-portable. You'd probably need some getter/setter functions in your > wrapper to do that in a safe way. Got it. I hope you got a good rest. e.r. |