Re: "Call by reference" in Skill/Ocean procedure



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)
.



Relevant Pages

  • RE: Using Match function with duplicate values in an array
    ... > set up a helper column ... >> function to find the row reference in the array. ... >> are multiple equal values in the column. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Reference a Service
    ... How would I go about making GetInstancereturn a reference to the active ... Access from multiple applications implies multiple, ... Pass requests through the pipe/socket (I think you can use the Marshal APIs ...
    (microsoft.public.dotnet.framework.clr)
  • Re: how to return mulitple corresponding values
    ... Although, for some reason, it wouldn't let me reference ... Microsoft Excel MVP ... Can this function handle multiple reoccurring group names (i.e. loop ... debih, biff, etc.) in column B for each group. ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Price calculations in Word
    ... These then become the cell addresses referenced in the ... CellC references, but not for the CellA reference. ... This is to stop multiple ... SEQ references on the same row changing the SEQ No. (and hence the source ...
    (microsoft.public.word.vba.general)
  • "Call by reference" in Skill/Ocean procedure
    ... I am learning to use procedures in Skill, more particularly in Ocean. ... I would like to write a procedure that can either modify variables ... One alternative would be to have the procedure return multiple values, ...
    (comp.cad.cadence)