Home > Community > Forums > Custom IC SKILL > passing variable by reference

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 passing variable by reference 

Last post Thu, Oct 4 2007 1:19 AM by archive. 2 replies.
Started by archive 04 Oct 2007 01:19 AM. Topic has 2 replies and 1691 views
Page 1 of 1 (3 items)
Sort Posts:
  • Thu, Oct 4 2007 1:19 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    passing variable by reference Reply

    Hello,

    I'm wondering how can a variable be passed by reference instead of value in skill functions ?

    Regards,
    David


    Originally posted in cdnusers.org by david.denis
    • Post Points: 0
  • Thu, Oct 4 2007 2:11 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: passing variable by reference Reply

    Hi David,

    In fact all variables [u]are [/u] passed by reference in SKILL. This is fairly obvious when passing lists, structures, tables, arrays and so on - but less obvious when passing "atomic" values such as integers, floats and strings - primarly because of the fact that there aren't functions to change a value of an atomic value in place.

    The purpose of you asking is probably to allow the function you're calling to change the value of a variable passed in. There are several ways this can be done:

    1. If the data passed is a list, structure, table, array, class instance, database object etc, then you can change it already. With lists you'd need to use a destructive operation (e.g. rplaca, rplacd and so on).
    2. You could write a macro instead of a function (see sourcelink solution 11025352 for an overview of macros)
    3. You could pass the name of the variable to the function. This is sort of equivalent to pointers in other languages. For example:

    procedure(MYupdateVar(varName "s")
    set(varName symeval(varName)+1)
    )

    a=1
    MYupdateVar('a)
    a => 2

    Regards,

    Andrew.


    Originally posted in cdnusers.org by adbeckett
    • Post Points: 0
  • Thu, Oct 4 2007 3:38 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,950
    RE: passing variable by reference Reply

    Thanks for the details.
    David


    Originally posted in cdnusers.org by david.denis
    • Post Points: 0
Page 1 of 1 (3 items)
Sort Posts:
Started by archive at 04 Oct 2007 01:19 AM. Topic has 2 replies.