SKILL Procedures

Discussion in 'Cadence' started by roddyalan, Jul 8, 2005.

  1. roddyalan

    roddyalan Guest

    Hi,

    I understand that Procedures use only local variables. How do I
    return a variable back to the program.

    Regards
    Alan Rodricks
     
    roddyalan, Jul 8, 2005
    #1
  2. You could read the manual. Start with the SKILL User Guide.

    procedures do _not_ only use local variables, and the return value of a
    procedure is the last thing it computes in the body of the procedure. Commonly
    a procedure is of this form:

    procedure(RTMbeforeAsking(a b c)
    let((d)
    d=a+b+c
    MYglobal=d-10
    printf("Sum is %n\n" d)
    d*3
    ) ; let
    ) ; procedure

    In this case, d is a local variable, MYglobal is a global variable, and the
    return value of the function is the result of d*3 - since it is the return
    value of the let (as the last thing computed) and consequently the return
    value of the procedure.

    Apologies for the function name; I couldn't resist ;-)

    Andrew.
     
    Andrew Beckett, Jul 9, 2005
    #2
  3. roddyalan

    Collin Weiss Guest

    A let() does not return a value but can modify a global variable.

    A prog() allows you to do a "return(some_value)" and the end of the
    prog().

    i.e.

    procedure(someFxn(arg1 arg2)
    prog( (var1 var2 var3)
    ;;body of fxn
    return(some_value)
    );;end prog
    );;end procedure
     
    Collin Weiss, Jul 14, 2005
    #3
  4. roddyalan

    Guest Guest

    It surely does. All Skill forms evaluate to some value unless an error occurs
    during evaluation or execution. For example:

    x = let( () 3 + 4 )

    will result in x having a value of 7.
    prog() is much more heavyweight and not necessary unless you need to return()
    out of the middle of a routine.

    The following:

    procedure(someFxn(arg1 arg2)
    let( (var1 var2 var3)
    ;;body of fxn
    some_value
    );;end let
    );;end procedure

    will have the same result without the overhead required for prog().

    -Pete Zakel
    ()

    Murphy's Seventh Collary: Every solution breeds new problems.
     
    Guest, Jul 14, 2005
    #4
  5. I'm sorry, but this is wrong. A let() DOES return a value. It returns the
    value of the last thing computed.

    Everything in SKILL returns a value. It's a functional language - everything
    is function, and everything has a return value.

    prog() just allows you to use spaghetti programming by returning early from a
    function.

    Your function could have been just as easily implemented as:

    procedure(someFxn(arg1 arg2)
    let((var1 var2 var3)
    ;; body of let
    some_value
    ) ; let
    ) ; procedure

    In older versions, prog() used to be a lot less efficient than let(). Since
    the byte-code compiler (4.3 - aka 9301, I think) the difference is now
    negligible. So now the main reason for using prog() would be because you
    either want to return early from the body of the prog(), or because you want
    to (horror!) use goto.

    Regards,

    Andrew.
     
    Andrew Beckett, Jul 14, 2005
    #5
  6. Negligible is a bit strong. I should have said that the difference is now a
    lot smaller.

    Andrew.
     
    Andrew Beckett, Jul 14, 2005
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.