using a port in sub-procedure

V

vlsidesign

Guest
I open a port for writing using the outfile function at my main
procedure. I want to use this port and write to it in some of my sub-
procedures. I pass the port into the sub-procedure and then return it
back and it seems to work. And then finally at the end of my main
procedure, I then close the port.

I was wondering if this was an okay way of doing it??

By the way, if I want to return multiple things, do I just create a
list and then return the list?? Any help is appreciated. Thanks.
 
I open a port for writing using the outfile function at my main
procedure. I want to use this port and write to it in some of my sub-
procedures. I pass the port into the sub-procedure and then return it
back and it seems to work. And then finally at the end of my main
procedure, I then close the port.

I was wondering if this was an okay way of doing it??
Of course, you can pass an opened port to a procedure and back.

You can even do a bit more general by allowing filename or output port, by including such code at
the beginning of your procedure :

let( ( port closeport )
caseq( typep( arg )
(string
port = outfile( arg )
closeport = t
) ; string
(port
unless( outportp( arg ) error( "Given port is not open for writing" ) )
port = arg
) ; port
(t
error( "Argument must be a filename or an output port" )
)
) ; caseq
) ; let

;;
;; body
;;

when( closeport close( port ) )

By the way, if I want to return multiple things, do I just create a
list and then return the list?? Any help is appreciated. Thanks.
Yes, that's the easiest way. Other data types may be used as well (array, defstruct, ...)


Stéphane
 
vlsidesign wrote:
I open a port for writing using the outfile function at my main
procedure. I want to use this port and write to it in some of my sub-
procedures. I pass the port into the sub-procedure and then return it
back and it seems to work. And then finally at the end of my main
procedure, I then close the port.

I was wondering if this was an okay way of doing it??
Yes. I think so.

By the way, if I want to return multiple things, do I just create a
list and then return the list?? Any help is appreciated. Thanks.
Yes. In the receiving end you can use mapcar to unpack the values and
assign to variables this way:

mapcar('set '(value info1 info2) mySubProc())
;Start using the variables value, info1, info2 from here

I sometimes prefer to create a disembodied property list and return, so
that it looks like a structure in the receiving end and the code is more
readable.
like
procedure( mySubProc()
let((...
list(nil 'value 12 'info1 33 'info2 44) ; Return the structure.
);let
);proc


result = mySubProc()
Now, I can access result->value, result->info1, result->info2

-
Suresh
 
On Feb 16, 3:49 am, Suresh Jeevanandam <sure...@DELETETHISti.com>
wrote:
<snip>
cool, thanks for the replies.
 

Welcome to EDABoard.com

Sponsor

Back
Top