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 7722739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:15:45+00:00 2026-06-01T04:15:45+00:00

Question about assignments and variables (* For example *) SP = SparseArray[{},5] or SP

  • 0

Question about assignments and variables

(* For example *) SP = SparseArray[{},5] or SP = Range[5]

now we want to work with this array in some another function :

(* example *) Fun[array_]:= array[[3]] = 100 ; (* set cell №3 equal to 100*)

then we eval

Fun[SP]

ERROR! output will be an Error like: Set::write Tag SparseArray in ... is Protected.

So what is the right way to change the arguments of function in function (non-pure-functions)? How to creare analog-like of Part[]?

maybe smth like:

Clear[f]; f[a_]:=Set[Symbol[a][[3]],100]; A =SparseArray[{},5]; f["A"]; 

But it’s error again

  • 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-01T04:15:46+00:00Added an answer on June 1, 2026 at 4:15 am

    I believe that Chris Degnen’s method should generally be avoided.
    Mathematica provides a better way: the Hold attributes.

    a = Range[5];
    
    SetAttributes[fun, HoldFirst]
    
    fun[array_] := array[[3]] = 100
    
    fun[a];
    
    a
    
    {1, 2, 100, 4, 5}
    

    As a “pure function”:

    b = Range[5];
    
    fun2 = Function[array, array[[3]] = 100, HoldFirst];
    
    fun2[b];
    
    b
    
    {1, 2, 100, 4, 5}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a simple question about how Python handles data and variables. I've done
This question about Timers for windows services got me thinking: Say I have (and
Quick question about Wordpress PHP: I am writing a theme and I want to
I asked this question about overloading the copy constructor and assignment operator with template
I have a kind of 'basics' question about php. In the example code for
note: please suppress comments about C++? Use std::string! . This question is using C
I already know how to make this code work, but my question is more
I have a question about the colnames function in the base package Let's say
Related question, about assignment-initialization-declaration. $ javac MatchTest.java MatchTest.java:7: ')' expected for((int i=-1 && String
I've got some questions about Java's assigment. Strings I've got a class: public class

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.