Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:52:21+00:00 2026-06-15T07:52:21+00:00

please find below a snippet of code that passes an array, manipulates the array,

  • 0

please find below a snippet of code that passes an array, manipulates the array, but i cannot return the new version of array.

here is the snippet :

    proc    get_mroute_active { &multicast }   {
        upvar   ${&multicast} MULTICAST ;

                set group   -1 ;
                set src -1 ;
                                set     mcast_group_source_id   -1 ;
                                set     MULTICAST($mcast_group_source_id,id) $mcast_group_source_id ;
                                set     MULTICAST($mcast_group_source_id,mcast_group) $group ;
                                set     MULTICAST($mcast_group_source_id,mcast_source) $src ;

        puts    [array size MULTICAST] ;
    parray  MULTICAST ;
}


array set     multicast { } ;

get_mroute_active [array get multicast] ;
puts    [array size multicast] ;
parray multicast ;

And the output of the code is :

3
MULTICAST(-1,id)           = -1
MULTICAST(-1,mcast_group)  = -1
MULTICAST(-1,mcast_source) = -1
0

Could you please help show me how the “MULTICAST” variable can be assigned to “multicast” ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:52:22+00:00Added an answer on June 15, 2026 at 7:52 am

    The short answer is: you can’t return an array from a procedure as arrays are not values — they are peculiar named collections of named values.

    There are several ways to deal with this:

    The usual approach is to pass arrays by names and make the called procedure modify the array in place. For instance, the code

    proc foo {arrayName} {
        upvar 1 $arrayName ary
        incr ary(one)
    }
    set x(one) 1
    foo x
    puts $x(one)
    

    will print “2” as the procedure foo modified a specific value in the specified array in the caller’s scope.

    Notice how the caller passed the name of an array, “x”, instead of “its value” (as you cannot extract a value from an array; but see below) and then the called procedure bound a local variable to that array by its name using the upvar command.

    The other approach is to employ array get and array set commands to extract keys and values from arrays and populate arrays with keys and values, respectively. For instance:

    set x(one) 1
    set x(two) 2
    array set another [array get x]
    parray another
    

    would print

    another(one) = 1
    another(two) = 2
    

    The array get command, given an array, returns a flat list with its keys and their respective values interleaved. This way you can return the contents of an array from a procedure and then make the caller do whatever it wishes with these contents, for instance, use the array set command to populate another array in its scope (possibly the same which has been passed to that procedure in the first place).

    Note that array set has merge semantics: it does not empty the target array before inserting/replacing its values using the source list.

    The third (and may be the best) approach is to use dictionaries which are key/value maps as arrays do but are themselves values, so they can be passed around freely as other values. This requires Tcl 8.5 or later (in Tcl 8.4, you can use a backport of this code in the form of a package. With dicts you get it like this:

    proc foo d {
        dict set d one 2
        return $d
    }
    set x [dict create]
    dict set x one 1
    set y [foo $x]
    puts $y
    

    which would print “one 2” as the procedure modified the original dictionary then returned it and then the caller assigned it to another variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please find the below code <?xml version=1.0 encoding=utf-8?> <mx:Application xmlns:mx=http://www.adobe.com/2006/mxml layout=absolute> <mx:Script> <![CDATA[ [Bindable]
Please find below the piece of code that I use to tokenize a string.
Possible Duplicate: Concatenating null strings in Java Please find below the code snippet String
Please find below code. Map<Long,String> unsortMap = new HashMap<Long,String>(); unsortMap.put(new Long(123), a); unsortMap.put(new Long(123),
Please find the code at http://jsfiddle.net/wlogeshwaran/NGL8P/4/ Here i want to make the 'hi' ,
Please find below the script snippet declare @xml xml set @xml = '<Message> <MessageData>
Please take a look at the code snippet below. I want the 2nd MongoDB
Please find the relevant snippets of my code below: public static final String GREEK
In my code, ontouch listener of a button is fired twice. please find below
Please find below entity code, @Entity public class A implements Serializable { @Id @GeneratedValue(strategy=GenerationType.AUTO)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.