help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variables `inheriting' values


From: Mike B.
Subject: Re: variables `inheriting' values
Date: Mon, 25 Jan 2010 17:10:56 -0800 (PST)

Hi Jordi.

Thanks for replying.
I was thinking more like a symlink to variables (similarly to a symlink between files in linux), so something like:
symlink( a, b )  # symlink b to a, not sure if this exists
a = 1

so now b (automatically) equals 1 as well.
This ideally would also work even if `a' is still undefined, so I can fill-in values later, for example:
clear -a
symlink( a,b )
a = 1

Is this possible?.

Cheers,
Mike.

--- On Tue, 26/1/10, Jordi Gutiérrez Hermoso <address@hidden> wrote:

From: Jordi Gutiérrez Hermoso <address@hidden>
Subject: Re: variables `inheriting' values
To: address@hidden
Cc: "Octave mai. lis." <address@hidden>
Date: Tuesday, 26 January, 2010, 7:56 AM

2010/1/23 Mike B. <address@hidden>

> Is it possible to do define variables so they will `inherit' a value
> later on down the code, for example:
>
> # a is still not defined
> b = a
> # now a is set with a value, for example
> a = sin( 1 )

You want a reference or an alias. There isn't such a datatype in
Octave, possibly because writing the interpreter is difficult enough
as it is without having to worry about aliasing rules, but if you want
that syntax, a simple way to fake it is to make b a function like so,
using a global variable:

     octave:1> global a = 42;
     octave:2> function x = b()
     > global a;
     > x = a;
     > endfunction
     octave:3> b
     ans =  42
     octave:4> a = 5
     a =  5
     octave:5> b
     ans =  5

This is kinda ugly and not really what you want, so you must want the
wrong thing. ;-)

HTH,
- Jordi G. H.


Get your preferred Email name!
Now you can @ymail.com and @rocketmail.com.
reply via email to

[Prev in Thread] Current Thread [Next in Thread]