[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: default values
From: |
etienne grossmann |
Subject: |
Re: default values |
Date: |
Thu, 23 Mar 2000 10:31:21 +0000 (WET) |
Hello
From: address@hidden (Paul Kienzle)
#
# I need a mechanism for defaulting the default values for variables.
# For example, should the default frame_step on a spectrogram be 1ms,
# 5ms or 10ms? Granted, the frame_step can be sent in as a parameter,
# but in an interactive environment, it is better if the defaults have
# the value the user usually wants.
#
# One way is to use:
#
# function myfunc(pa, pb)
# global myfunc_pb = 37;
# if nargin<2 || isempty(pb), pb=myfunc_pb; endif
# ...
# endfunction
I usually do
function myfunc(pa, pb)
if exist("pb") != 1, pb = 37 ; end
...
end
Simple, no global variable is needed, but you can't change the
default from the command line ...
#
# This does exactly what I want, except that it leaves the definition
# of myfunc_pb in the global symbol table. Instead, I wrote a function
# default.cc which takes the name of the global variable and a default
# value, returning the value of the global if it is defined, otherwise
# returning the default. E.g.,
#
# function myfunc(pa, pb)
# if nargin<2 || isempty(pb), pb=default("myfunc_pb",37); endif
# ...
# endfunction
#
# Is this something which should be part of the main distribution of
# Octave? Or should I just go ahead and pollute the global namespace
# with default defaults?
Cheers,
Etienne
ps : The original post was on octave-source.
-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.che.wisc.edu/octave/octave.html
How to fund new projects: http://www.che.wisc.edu/octave/funding.html
Subscription information: http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: default values,
etienne grossmann <=