help-octave
[Top][All Lists]
Advanced

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

Re: ["Can I ", sprintf ("make this code work?\n")]


From: William Poetra Yoga Hadisoeseno
Subject: Re: ["Can I ", sprintf ("make this code work?\n")]
Date: Tue, 30 May 2006 10:12:34 +0800

On 5/30/06, Bill Denney <address@hidden> wrote:
On Tue, 30 May 2006, William Poetra Yoga Hadisoeseno wrote:
> On 5/30/06, Keith Goodman <address@hidden> wrote:
>> On 5/29/06, Etienne Grossmann <address@hidden> wrote:
>>
>>> this is just to ask whether there is a 2.9.5 setting that would allow me to
>>> run this (legacy) code unchanged?
>>>
>>>     ["Can I ", sprintf ("make this code work?\n")]
>>
>> The parser thinks you are trying to concatenate three things. Just
>> remove the space between sprintf and (.
> So, is this a bug or a feature?

It's the best of both worlds: both.

The longer answer (that I think is right) is:

When Octave's parser reaches something like

["Can I ", sprintf ("make this code work?\n")]

It parses it as

a concatenation: [
an interpreted string: "Can I "
a separator: ,
a function or variable: sprintf
a grouping or function argument opening: (
an interpreted string: "make this code work?\n"
a group or function argument closing: )
a concatenation closing: ]

The problem is that it doesn't know if sprintf is a function or a variable
here, and as such, it can't be sure if the grouping after it is just a
grouping or if it is the argument to the function.  Removing the space
after sprintf removes the doubt.


Oh well, since the general convention (IMO) for Octave code is "func
(arg1, arg2, ...)" with a space in between, is it better then to write
it like this instead:

["Can I ", (sprintf ("make this code work?\n"))]

?

(Etienne, could something about this go into the FAQ)

Bill

--
"We are accustomed to see men deride what they do not understand, and
snarl at the good and beautiful because it lies beyond their sympathies."
   -- Johann Wolfgang von Goethe




--
William Poetra Yoga Hadisoeseno


reply via email to

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