How to Write Procedures in Gauss

Hi,

How to write procedures in Gauss? I have sometimes seen proc 1 and proc (1) or proc without any number and I do not know how that makes a difference. Also, I know that within a proc before endp; retp() captures the final outcome to print, but what if I am interested in printing more than one outcome variable within retp()? Finally, how a proc is called/used? Is there any chance you can write a blog on this topic? If not, I will appreciate if these questions can be clarified in this forum.

1 Answer



0



Those are all great questions! We have a video in our GAUSS Basics series planned for procedures in GAUSS. It is not scheduled for a few weeks, but let me see if we can get a tutorial or blog post with the main content. That is a good idea.

Multiple returns

To make your GAUSS procedure return more than one output, set the number in parentheses to match the number of outputs and place that list of returns in your retp statement like this:

// Create a matrix to use in our procedure
A = rndn(3, 2);

{ r, c } = matSize(A);
print r c;

// proc (2), because we have 2 returns
proc (2) = matSize(X);
    local nrows, ncols;

    nrows = rows(X);
    ncols = cols(X);

    retp(nrows, ncols);
endp;

Using the procedure

Once the procedure has been run, either as a program file or interactively, the procedure can be used just like a built-in GAUSS procedure until you clear it out with the new command. If you want to keep it around longer, you can add it to a GAUSS library. We are happy to answer any questions about GAUSS libraries, but they would be best in a separate thread to make it easier for future viewers to get help from the forum.

Where to find proc help

Find help on GAUSS procedures.

aptech

1,773

Your Answer

1 Answer

0

Those are all great questions! We have a video in our GAUSS Basics series planned for procedures in GAUSS. It is not scheduled for a few weeks, but let me see if we can get a tutorial or blog post with the main content. That is a good idea.

Multiple returns

To make your GAUSS procedure return more than one output, set the number in parentheses to match the number of outputs and place that list of returns in your retp statement like this:

// Create a matrix to use in our procedure
A = rndn(3, 2);

{ r, c } = matSize(A);
print r c;

// proc (2), because we have 2 returns
proc (2) = matSize(X);
    local nrows, ncols;

    nrows = rows(X);
    ncols = cols(X);

    retp(nrows, ncols);
endp;

Using the procedure

Once the procedure has been run, either as a program file or interactively, the procedure can be used just like a built-in GAUSS procedure until you clear it out with the new command. If you want to keep it around longer, you can add it to a GAUSS library. We are happy to answer any questions about GAUSS libraries, but they would be best in a separate thread to make it easier for future viewers to get help from the forum.

Where to find proc help

Find help on GAUSS procedures.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy