help-octave
[Top][All Lists]
Advanced

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

Re: open socket with listen() and still have command line available?


From: Paul Kienzle
Subject: Re: open socket with listen() and still have command line available?
Date: Thu, 31 May 2007 03:33:09 -0400


On May 30, 2007, at 2:18 PM, Tom Holroyd (NIH/NIMH) [E] wrote:


Paul Kienzle wrote:
On May 27, 2007, at 11:49 AM, Tom Holroyd (NIH/NIMH) [E] wrote:
Hmm... that still leaves the send/recv function in parallel which will conflict with the posix socket interface.

Is there no way to implement namespaces?

Something like this needs to be done sometime.

pkg load socket
send(blah)
pkg load socket as skt
skt.send(blah)
We could get this sort of functionality with a new octave type 'module'.

Why not just use struct()? Let's say I'm defining a package called moo in /tmp/moo:

---8<---
function b = f(a)
 b = a + 2;
end
function b = g(a)
 b = a + 3;
end
# emulate package being loaded as
# pkg load moo as moo
moo = struct("f", @f, "g", @g);
clear f
clear g
---8<---

Then I can do:

octave:1> source('/tmp/moo')
octave:2> moo.f(4)
ans =  6
octave:3> moo.g(4)
ans =  7
octave:4> f
error: `f' undefined near line 4 column 1

where I am using the "source" command above as a replacement for "pkg load moo as moo".

Clever.

Using subfunctions has some advantages:

 function m = sock
  persistent fns = struct('p',@p);
  m = fns;

  function y = p(x), y = x+2; end
 end

That way you don't have to worry about functions which are already in the namespace.

You invoke the functions the same as before:

 octave-2.9.9:2> sock.p(3)
 ans =  5

Things not defined as subfunctions (e.g., oct-files) can be tagged with the name of the package.

This doesn't resolve the original problem which is that 'send' is defined in two different packages, neither of which is written in this style. Converting everything to this style just in case names might collide isn't the right answer either.

        - Paul



reply via email to

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