[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #58780] 'source' throws unexpected syntax erro
From: |
John W. Eaton |
Subject: |
[Octave-bug-tracker] [bug #58780] 'source' throws unexpected syntax error. |
Date: |
Mon, 24 Aug 2020 16:58:20 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0 |
Update of bug #58780 (project octave):
Status: Confirmed => Need Info
_______________________________________________________
Follow-up Comment #5:
The attached change appears to help, but something strange still happens when
sourcing files that are functions instead of scripts.
With the change, I see the following:
>> source foo ## Does not automatically append .m
error: source: error sourcing file '/tmp/foo': no such file, '/tmp/foo'
>> source foo.m ## Improved error reporting:
error: source: error sourcing file '/tmp/foo.m': parse error near line 1 of
file /tmp/foo.m
syntax error
>>> (1))
^
>> source foo.m ## Syntax error fixed; code executed
ans = 1
>> type foo.m ## Make it a simple function instead:
foo.m is the user-defined function defined from: /tmp/foo.m
function foo ()
'this is FOO!!'
end
>> source foo.m ## Source works, but function not executed
>> foo ## Is it defined? Yes.
ans = this is FOO!!
>> which foo ## Hmm, this seems wrong.
'foo' is a command-line function
So it seems that when we parse the file, it is being entered into Octave's
table of known functions. But I'm not sure that's the best thing to do.
Note that the existing code has the comment
// For compatibility with Matlab, accept both scripts and functions.
but I don't think Matlab has the "source" function. So I assume this comment
was added because Octave's "run" function (which Matlab does have) calls
"source", and Matlab's "run" function will execute functions that have no
arguments.
I'm curious to know whether Matlab's "run" function parses the file every
time, or whether it caches the result. We should be able to test as follows.
Create a file foo.m with the contents
function foo ()
persistent val
if (isempty (val))
val = 1
else
val = val + 1
end
end
then execute
run foo.m
run foo.m
Does it print val = 1 each time, or is val incremented or is there some
error?
(file #49704)
_______________________________________________________
Additional Item Attachment:
File name: source-diffs.txt Size:2 KB
<https://file.savannah.gnu.org/file/source-diffs.txt?file_id=49704>
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?58780>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [Octave-bug-tracker] [bug #58780] 'source' throws unexpected syntax error.,
John W. Eaton <=