Re: "Call by reference" in Skill/Ocean procedure
- From: Andrew Beckett <andrewb@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 25 Nov 2009 21:22:49 +0000
Stephen Greenwood wrote, on 11/24/09 23:50:
I am learning to use procedures in Skill, more particularly in Ocean.
I would like to write a procedure that can either modify variables
that have been passed ("call by reference"). Is this possible? I
didn't see a way to do that in the manual description for "procedure
()", and by experimenting I know that the default operation is "call
by value".
One alternative would be to have the procedure return multiple values,
which are then used to set multiple variables. But looking at the
manual it appears that the procedure can only return a single value.
If that's the case, then my suspicion is that the only way to return
multiple values is to return a list and to then manipulate the list.
Thoughts or comments on these questions? Thank you for your time.
Apologies if this has already been answered before, but I had no
success searching the archives.
Hi Stephen,
Actually SKILL does pass by reference. However, you cannot change the value pointed to by a variable, so it gives the appearance of being pass by value.
You can see that it's pass by reference if you pass a list, a defstruct, a table and so on - all the these allow you to modify the contents directly, and so that may allow you to achieve what you want. For example:
procedure(MYcollectSomeResults(data)
let((signal)
signal=v("/out" ?result 'tran)
data->max=ymax(signal)
data->min=ymin(signal)
data->average=average(signal)
data
)
)
Then you could do:
info=ncons(nil)
MYcollectSomeResults(info)
and then you'll be able to look at info->max, info->min etc (this is using a "Disembodied Property List"). The list is being modified "destructively" within the list - and consequently you can pass back multiple values.
Another way might be to use an association table (aka a "hash"). You could do this with the same code as above, but do:
info=makeTable('myInfoTable nil)
MYcollectSomeResults(info)
info is a hash; you can do either info['max] or info->max to get the value out. Association Tables can use anything as the key.
Returning multiple values is straightforward - you can return a list of the different things you want to return.
Finally, another way is to pass in the names of the variables you want to pass in (you can sort of think of this as being a pointer):
procedure(MYcollectSomeResults(maxVar minVar averageVar)
let((signal)
signal=v("/out" ?result 'tran)
set(maxVar ymax(signal))
set(minVar ymin(signal))
set(averageVar average(signal))
t
)
)
MYcollectSomeResults('myMax 'myMin 'myAverage)
and then you'll have myMax, myMin and myAverage set to the appropriate values after it returns.
I don't really like this approach though, because it relies (sort of) on run-time evaluation, and doesn't work (without some changes) in SKILL++ due to it needing to know the "environment" for the variables.
I hope that's given you enough info!
Regards,
Andrew.
--
Andrew Beckett
Senior Solution Architect - Cadence Design Systems Ltd (UK)
.
- Follow-Ups:
- Re: "Call by reference" in Skill/Ocean procedure
- From: Stephen Greenwood
- Re: "Call by reference" in Skill/Ocean procedure
- References:
- "Call by reference" in Skill/Ocean procedure
- From: Stephen Greenwood
- "Call by reference" in Skill/Ocean procedure
- Prev by Date: Re: Create a write lock for a text file
- Next by Date: Re: cells not translated during stream-in
- Previous by thread: "Call by reference" in Skill/Ocean procedure
- Next by thread: Re: "Call by reference" in Skill/Ocean procedure
- Index(es):
Relevant Pages
|