Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: mata: passing additional arguments to functions passed to


From   [email protected] (William Gould, Stata)
To   [email protected]
Subject   Re: st: mata: passing additional arguments to functions passed to
Date   Fri, 09 Jun 2006 08:00:53 -0500

Matt Weinberg <[email protected]> writes, 

> This seems to work well, except for the proposed subroutine callf_setup.
> The suggested code for this routine was:
>
>       pointer vector callf_setup(pointer(function) scalar f, real scalar n, 
>                                  a1, a2, a3, a4, a5)
>       {
>               pointer vector     p
>               real scalar        mycopy
>
>               p = J(1, 5+2, .)
>
>               p[1] = f
>               mycopy = n ; p[2] = &mycopy
>               p[3] = &a1 ; p[4] = &a2 ; p[5] = &a3 ; p[6] = &a4 ; p[7] = &a5
>
>               return(p)
>       }
>
> 
> but this will generate error 3253, "non-real found where real expected".  

Change 

                p = J(1, 5+2, .)
to
                p = J(1, 5+2, NULL)

I admit the error message is misleading, but what happened was that Mata 
did not notice the problem when it executed -p = J(1, 5+2, .)-.  
Instead, it made p a real vector.  Then later, when Mata tried to 
assign -p[1] = f-, it did notice the problem.  By this point, p was real, 
and so the error-message-generating routine decided to say that a "non-real
was found where real expected" when what in fact happened was that a real 
was found earlier where a nonreal was expected.

Anyway, the point of 

                p = J(1, 5+2, NULL)

is to make p a 1x7 vector filled in with missing.  NULL is a pointer missing.

-- Bill
[email protected]
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index