help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best practices for loading packages


From: Helios de Rosario
Subject: Re: Best practices for loading packages
Date: Thu, 27 Mar 2014 14:56:02 +0100

>>> El día 27/03/2014 a las 12:38, Daniel Kraft
<address@hidden>
escribió:
> Hi!
> 
> I've recently started to appreciate what packages can do to keep
code
> structured in Octave.  Now I'm wondering what the "best practices"
for
> loading packages are.
> 
> In particular, if I write a function "foo" that uses some package
"bar",
> and then use the function itself from my main program.  What I'm
> currently doing in the main script is something like this:
> 
>   clear ("all");
>   pkg load bar;
>   ... other things ...
>   foo ();
> 
[...]
> 
> What is the recommended way of handling this situation?  Just load
all
> packages in the main program?  Or is there a way to "ensure" that a
> package is loaded just for the scope of a function executing? 
(Similar
> to #include of headers in some .cpp file or import directives in
certain
> languages that only concern a "local" scope (one compilation unit).)
> 

I don't think there is a straightforward way to do that. Packages work
globally within the scope of the session, more or less like Matlab's
toolboxes. If you want that your function "foo" using the package "bar",
without disturbing the rest of the session, what you may do is copy the
functions of "bar" in the "private" folder where "foo" resides.
https://www.gnu.org/software/octave/doc/interpreter/Private-Functions.html

That may do what you want if "bar" is only a bunch of functions ready
to use. If there are actions that should be executed when the package is
installed or loaded, it might not be that easy.

Helios De Rosario


INSTITUTO DE BIOMECÁNICA DE VALENCIA
Universidad Politécnica de Valencia • Edificio 9C
Camino de Vera s/n • 46022 VALENCIA (ESPAÑA)
Tel. +34 96 387 91 60 • Fax +34 96 387 91 69
www.ibv.org

  Antes de imprimir este e-mail piense bien si es necesario hacerlo.
En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección
de Datos de Carácter Personal, le informamos de que el presente mensaje
contiene información confidencial, siendo para uso exclusivo del
destinatario arriba indicado. En caso de no ser usted el destinatario
del mismo le informamos que su recepción no le autoriza a su divulgación
o reproducción por cualquier medio, debiendo destruirlo de inmediato,
rogándole lo notifique al remitente.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]