Using "get" inside a function



I saw Leo's first email and experimented in XMaxima before I saw the other emails, so I just sent Leo a reply I'd like to repeat here, because I think it's in-line with what Stavros is saying :

I think the ultimate problem is that due to the nature of GET and PUT, within the function I'm not going to be able to access *both* the value of the variable (1 in your example), and the value that I put on it (true in your example) at the same time, because one requires that I pass X and the other requires that I pass 'X. 

I've also tried using declare/feature :
    declare([Trank1U,Trank1L,Trank2UU,Trank2LL,Trank2UL,Trank2LU],feature)$
    declare(g_ll,Trank2LL)$
    featurep('g_ll,Trank2LL); --> true
But it also seems to suffer from the same problems (passing container vs. contents to a function).

I haven't had a chance to digest what Richard said yet (or Leo's hashing suggestion), and I have to get ready to go to work, so I won't be able to do any more with this until tomorrow morning (USA/EST).

Thank you all for your thoughtful input!
Bruce

  ----- Original Message ----- 
  From: Stavros Macrakis 
  To: Bruce Linnell 
  Cc: maxima at math.utexas.edu 
  Sent: Monday, March 07, 2011 2:28 AM
  Subject: Re: [Maxima] Using "get" inside a function


  Hi, there seem to be two issues here:


  1) the semantics of variable quoting
        and
  2) the semantics of properties.


  Both of them hinge on the difference between a *variable* (container) and its *value* (thing contained).  With put('foo,...), you have given the *container* a value.  If you now pass the contents of that container to a function, the function has no way of knowing the properties of the container.


  Maxima does not give users the possibility of giving values properties, so there are several possibilities:


  1) you could pass the container itself (e.g. myfunc('foo) ), but then to get its value within the function you would have to write ev(foo), not just foo.
  2) you could have a separate array of properties, e.g. you say myprop[foo] : 234$
  3) you could define your own objects of the form, e.g., [val, [prop1,val1], [prop2,val2]...] etc.


  I believe there is also an object system for Maxima, but I haven't used it myself.


              -s


  On Sun, Mar 6, 2011 at 14:29, Bruce Linnell <brlinnell at verizon.net> wrote:

    Hi - 

    I am trying to use "get" inside a function in order to make decisions based on the properties of the variable I've passed to the function.  I've used LISP as well as various versions of Macsyma/Maxima in the dim and distant past, but I've just started to use it again recently.  I'm using version 5.23.2 of XMaxima in Windows.  I am doing the following at the command line :

        g_ll:matrix([-1,0,0,0],[0,A^2/(1-K*r^2),0,0],[0,0,A^2*r^2,0],[0,0,0,A^2*r^2*sin(theta)^2]);
        put(' g_ll,' Trank2LL,' Trank);

    NOTE : I've intentionally put spaces after every ' in this email so that they can be seen (the ' is hard to see as 'T on my screen).  My actual code has no spaces.

    My function is currently (stripped down for testing, and to match the manual's example) : 

        TensorTrace (T) := 
        block
          (
          [temp],
          temp:get(' T,' Trank)
          )$

    And the function call is : TensorTrace(g_ll);



    My problem is this : WITH a ' before the T (as shown), the debugger says that T is a 4x4 matrix with the correct terms, but T only has the properties [value], whereas (also within the debugger) g_ll has the properties [value, [user properties, Trank]].  

    And WITHOUT a ' before the T, when I call the function I get a "get: argument must be a symbol or a string; found: errexp1" error message. But the example on (Adobe's) page 514 of the manual under get shows : 
            get(expr,'type) 
    where expr is the variable passed to the function!

    I'm so confused!  Is there some other option besides ' T and T ?  Why doesn't it work without a ' like the example in the manual?

    Thanks in advance to all who reply.
    Bruce Linnell, PhD


    _______________________________________________
    Maxima mailing list
    Maxima at math.utexas.edu
    http://www.math.utexas.edu/mailman/listinfo/maxima