[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: variables `inheriting' values
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: variables `inheriting' values |
Date: |
Mon, 25 Jan 2010 14:56:08 -0600 |
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.
- variables `inheriting' values, Mike B., 2010/01/23
- Re: variables `inheriting' values,
Jordi Gutiérrez Hermoso <=
- Re: variables `inheriting' values, Mike B., 2010/01/25
- Re: variables `inheriting' values, John W. Eaton, 2010/01/25
- variables `inheriting' values, rounding, Mike B., 2010/01/26
- Re: variables `inheriting' values, rounding, Jordi Gutiérrez Hermoso, 2010/01/26
- Re: variables `inheriting' values, rounding, Mike B., 2010/01/26
- Re: variables `inheriting' values, rounding, John W. Eaton, 2010/01/26
- Re: variables `inheriting' values, rounding, Mike B., 2010/01/27
Re: variables `inheriting' values, Dupuis, 2010/01/26