octave-maintainers
[Top][All Lists]
Advanced

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

Re: Crash with inline


From: John W. Eaton
Subject: Re: Crash with inline
Date: Thu, 16 Sep 2004 11:01:15 -0400

On 16-Sep-2004, Teemu Ikonen <address@hidden> wrote:

| Now, an obligatory stupid question: Since Octave already seems to have
| functions as first-class objects,

They are not really first-class objects, are they?  If you write

  function f ... end

  g = f;

then g is not a function, but the result of calling the function.
Similarly, if you write

  f

you don't see the definition of the function (or some other message
saying, "f is a function") but instead, the function is called.  So
you can't directly pass functions around like any other data object.

Rather than fix this by saying "if you want to call a function, you
have to use "f (...)"; otherwise, you are referring to the function
object itself", the developers of the other leading brand decided to
invent "function handles".

| would it be hard to implement real closures?

I'm not sure.  How would this work within the current language?

| Also, I'm wondering about the difference between inline functions and user
| defined functions defined on the command line with the function keyword.
| Inline functions are listed as variables in the who output and can be saved
| at least in the octave binary format. Are there any deeper differences? Is
| there any way of saving functions defined by the function keyword?

We also have anonymous function handles.  Given those, it seems like
inline functions are not really necessary.

In Octave, inline functions are a special kind of function handle.

If you want to save a function that you've defined at the command
line, you can do this:

  function foo ... end

  f = fopen ("foo.m", "w");
  fprintf (f, "%s", type ("foo"));
  fclose (f);

If you've saved it somewhere in Octave's LOADPATH, then you can just
call it to reload it.  Or, you can do

  source ("foo.m")

or you can write

  f = fopen ("foo.m", "r");
  t = setstr (fread (f)');
  fclose (f);
  eval (t);

jwe

  



reply via email to

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