Identifier not found "result"

classic Classic list List threaded Threaded
36 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Identifier not found "result"

Rainer Stratmann
This bevaviour is likely when someone starts with fpc, because the default
mode is Free Pascal  (-Mfpc).

Wouldn't it be good to give an additional suggestion if the identifyer ist
result and the mode is -Mfpc?

For example: Identifier not found "result", may could be resolved with other
syntax mode (-M...)
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

leledumbo
Administrator
Since this behavior is documented, one should read the documentation first:
http://www.freepascal.org/docs-html/ref/refse76.html

Anyway, how could one find that Result is used as function result without reading the docs?
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
> Since this behavior is documented, one should read the documentation first:
> http://www.freepascal.org/docs-html/ref/refse76.html

There is much documentation spread over many servers.

> Anyway, how could one find that Result is used as function result without
> reading the docs?

The scenario occures when someone starts freepascal as I already documented in
my first E-Mail.

When someone wants to compile a TurboPascal or Delphi program with freepascal.
Then he already knows that result is a function result, but freepascal gives
an error about this.

Of course now you can say he has to read the documentation, but this you can
say nearly to every question for which a solution is documented in the docs.

As I read from your statement your opinion is that my suggestion is completely
needless. I know it now, but for the beginners it will be a help to not get
demotivated with reading all the docs.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Mark Morgan Lloyd-5
Rainer Stratmann wrote:

> Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
>> Since this behavior is documented, one should read the documentation first:
>> http://www.freepascal.org/docs-html/ref/refse76.html
>
> There is much documentation spread over many servers.
>
>> Anyway, how could one find that Result is used as function result without
>> reading the docs?
>
> The scenario occures when someone starts freepascal as I already documented in
> my first E-Mail.
>
> When someone wants to compile a TurboPascal or Delphi program with freepascal.
> Then he already knows that result is a function result, but freepascal gives
> an error about this.

I agree. However I don't know whether a blanket "you're in the wrong
mode, lackwit!" error message would be a solution, since it's possible
to envisage cases where result is an ordinary variable and should be
referenced as such- irrespective of mode.

procedure xxx(var result2: yyy);

begin
   result := zzz

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Reinier Olislagers
In reply to this post by Rainer Stratmann
On 30-8-2012 15:08, Rainer Stratmann wrote:
> Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
>> Since this behavior is documented, one should read the documentation first:
>> http://www.freepascal.org/docs-html/ref/refse76.html
>
> There is much documentation spread over many servers.
I don't understand that remark: Leledumbo is referring to correct spot
in the official FPC documentation.

> When someone wants to compile a TurboPascal or Delphi program with freepascal.
> Then he already knows that result is a function result, but freepascal gives
> an error about this.
Perhaps if in Lazarus he could just press F1 when on the result
identifier[1]. If in the fpc IDE, presumably there's context sensitive
help. That would work for other similar problems, too.

If the user doesn't use an IDE then yes, I think he should go through
the documentation manually.

If you feel so strongly about the issue though, why not submit an
issue+patch?

[1] However, that doesn't seem to work. See bug
http://bugs.freepascal.org/view.php?id=22754
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
In reply to this post by Mark Morgan Lloyd-5
Am Thursday 30 August 2012 15:20:46 schrieb Mark Morgan Lloyd:

> > When someone wants to compile a TurboPascal or Delphi program with
> > freepascal. Then he already knows that result is a function result, but
> > freepascal gives an error about this.
>
> I agree. However I don't know whether a blanket "you're in the wrong
> mode, lackwit!" error message would be a solution, since it's possible
> to envisage cases where result is an ordinary variable and should be
> referenced as such- irrespective of mode.
>
> procedure xxx(var result2: yyy);
>
> begin
>    result := zzz

For people who switch from Delphi or TurboPascal to Freepascal this scenario
is very unlikely because the source already compiles errorfree (I hope so).

Also if starting with freepascal your scenario is unlikely (not that I don't
see what you want to say).

The message could be a question: "are you in the right syntax-mode?"
This is better than leave the beginner alone with reading the docs.

This message is even more a better help for beginners: "are you in the right
syntax-mode? only ObjFPC (-MObjfpc) or Delphi (-Mdelphi) mode supports a
function result"
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
In reply to this post by Reinier Olislagers
Am Thursday 30 August 2012 15:33:36 schrieb Reinier Olislagers:
> On 30-8-2012 15:08, Rainer Stratmann wrote:
> > Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
> >> Since this behavior is documented, one should read the documentation
> >> first: http://www.freepascal.org/docs-html/ref/refse76.html
> >
> > There is much documentation spread over many servers.
>
> I don't understand that remark: Leledumbo is referring to correct spot
> in the official FPC documentation.

But a beginner has to read many documents.
Wouldn't it be better to come to a solution (compiled program) as fast as
possible to stay motivated?

> > When someone wants to compile a TurboPascal or Delphi program with
> > freepascal. Then he already knows that result is a function result, but
> > freepascal gives an error about this.
>
> Perhaps if in Lazarus he could just press F1 when on the result
> identifier[1]. If in the fpc IDE, presumably there's context sensitive
> help. That would work for other similar problems, too.

I had this thing with lazarus but was not aware of a fast help about this.

> If the user doesn't use an IDE then yes, I think he should go through
> the documentation manually.

A short message would help the user faster than searching for the right
document.
Even more a beginner could turn away because of this behaviour and say
freepascal is not mature if it does not support a function result.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Reinier Olislagers
On 30-8-2012 15:49, Rainer Stratmann wrote:

> Am Thursday 30 August 2012 15:33:36 schrieb Reinier Olislagers:
>> On 30-8-2012 15:08, Rainer Stratmann wrote:
>>> Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
>>>> Since this behavior is documented, one should read the documentation
>>>> first: http://www.freepascal.org/docs-html/ref/refse76.html
>>>
>>> There is much documentation spread over many servers.
>>
>> I don't understand that remark: Leledumbo is referring to correct spot
>> in the official FPC documentation.
>
> But a beginner has to read many documents.
<snip>
As I said, perhaps best to raise an issue+patch if you feel so strongly
about it.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 15:59:12 schrieb Reinier Olislagers:

> On 30-8-2012 15:49, Rainer Stratmann wrote:
> > Am Thursday 30 August 2012 15:33:36 schrieb Reinier Olislagers:
> >> On 30-8-2012 15:08, Rainer Stratmann wrote:
> >>> Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
> >>>> Since this behavior is documented, one should read the documentation
> >>>> first: http://www.freepascal.org/docs-html/ref/refse76.html
> >>>
> >>> There is much documentation spread over many servers.
> >>
> >> I don't understand that remark: Leledumbo is referring to correct spot
> >> in the official FPC documentation.
> >
> > But a beginner has to read many documents.
>
> <snip>
> As I said, perhaps best to raise an issue+patch if you feel so strongly
> about it.

I am not familiar with the compilers soucecode. That will take some time I
think. I don't think that it is that difficult to implement.

If the identifyer that was not found is named "result" then a compiler
message "are you in the right syntax-mode? only ObjFPC (-MObjfpc) or Delphi
(-Mdelphi) mode supports a function result" is shown.

That will help beginners to stay motivated instead of (maybe) searching
another language.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Tomas Hajny-2
In reply to this post by Rainer Stratmann
On Thu, August 30, 2012 15:08, Rainer Stratmann wrote:

> Am Thursday 30 August 2012 14:39:06 schrieb leledumbo:
>> Since this behavior is documented, one should read the documentation
>> first:
>> http://www.freepascal.org/docs-html/ref/refse76.html
>
> There is much documentation spread over many servers.
>
>> Anyway, how could one find that Result is used as function result
>> without
>> reading the docs?
>
> The scenario occures when someone starts freepascal as I already
> documented in
> my first E-Mail.
>
> When someone wants to compile a TurboPascal or Delphi program with
> freepascal.
> Then he already knows that result is a function result, but freepascal
> gives
> an error about this.

Identifier Result was not known/supported as function result in TP/BP,
i.e. your statement applies to Delphi only. Still, people with Delphi
background are obviously more likely to come across FPC nowadays, but
these people usually need $MODE DELPHI anyway due to many other things
they are used to and I miss to see how this one particular case improves
the overall situation for them. On the other hand, pointing out all
differences among the different modes by similar compiler messages is
fairly likely to require considerable effort.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 16:50:30 schrieb Tomas Hajny:

> > The scenario occures when someone starts freepascal as I already
> > documented in
> > my first E-Mail.
> >
> > When someone wants to compile a TurboPascal or Delphi program with
> > freepascal.
> > Then he already knows that result is a function result, but freepascal
> > gives
> > an error about this.
>
> Identifier Result was not known/supported as function result in TP/BP,
> i.e. your statement applies to Delphi only. Still, people with Delphi
> background are obviously more likely to come across FPC nowadays, but
> these people usually need $MODE DELPHI anyway due to many other things
> they are used to and I miss to see how this one particular case improves
> the overall situation for them. On the other hand, pointing out all
> differences among the different modes by similar compiler messages is
> fairly likely to require considerable effort.
>
> Tomas

It is not about pointing out all differences.

It is _simply_ that what I guess occures often when a beginner starts with
freepascal. The realization of this message is easy I think. TP for DOS at
least supports a function result (as I remember) thus it is not Delphi only
as you mention. Even if it is Delphi only the programmer who switched to
freepascal sees the message 'identifier "result" not found' and is forced to
study the documentation (which he already has to do much when starting with
setting up the whole fpc environment). I have this thought that freepascal is
not mature when I saw this the first time. And if there is a _simple_ message
like described in other mails then the most obscurities are eliminated. In
TP/BP there was not a syntax mode as far as I remember (or preconfigured
one). The IDE worked out of the box!

What's wrong with such a message that is easy to implement and will help
beginners to freepascal a lot?
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Mark Morgan Lloyd-5
Rainer Stratmann wrote:

> TP for DOS at
> least supports a function result (as I remember) thus it is not Delphi only
> as you mention.

It supports a function result, but it doesn't IIRC treat 'result' as a
special identifier. Delphi /has/ to have 'result', since otherwise
redefining standard operators would result in something like

operator := (wle: WordLE): word;

begin
{$ifdef ENDIAN_LITTLE }
   Move(wle, result, SizeOf(:=))
..

which is clearly absurd :-)

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Mark Morgan Lloyd-5
In reply to this post by Rainer Stratmann
Rainer Stratmann wrote:

> I am not familiar with the compilers soucecode.

> I don't think that it is that difficult to implement.

Those two statements are contradictory. I've previously raised issues
related to command-line options and error messages, and had the issues
patiently explained to me by Jonas et. al.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 17:46:09 schrieb Mark Morgan Lloyd:
> Rainer Stratmann wrote:
> > I am not familiar with the compilers soucecode.
> >
> > I don't think that it is that difficult to implement.
>
> Those two statements are contradictory. I've previously raised issues
> related to command-line options and error messages, and had the issues
> patiently explained to me by Jonas et. al.

In other words, if I wrote the compiler I would know where to implement.
So we are at the point where you see my suggestion helpful?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Mark Morgan Lloyd-5
In reply to this post by Mark Morgan Lloyd-5
Mark Morgan Lloyd wrote:
> Rainer Stratmann wrote:
>
>> TP for DOS at least supports a function result (as I remember) thus it
>> is not Delphi only as you mention.
>
> It supports a function result, but it doesn't IIRC treat 'result' as a
> special identifier. Delphi /has/ to have 'result', since otherwise
> redefining standard operators would result in something like

My absurd example wasn't absurd enough :-) Should have read

operator := (wle: WordLE): word;

begin
{$ifdef ENDIAN_LITTLE }
   Move(wle, :=, SizeOf(:=))
.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Jonas Maebe-2
In reply to this post by Rainer Stratmann

On 30 Aug 2012, at 17:14, Rainer Stratmann wrote:

> TP for DOS at
> least supports a function result (as I remember) thus it is not Delphi only
> as you mention.

Turbo Pascal does not support the "result" alias for the function result.

> What's wrong with such a message that is easy to implement and will help
> beginners to freepascal a lot?


We give such a message when someone tries to define a "class" type without having ObjFPC/Delphi mode activated. That is a message that is always correct, because

type
  tsomething = class
  end;

does not and cannot have any other meaning in another compilation mode. As has been pointed out by other people, that is not true for random occurrences of the word "result" in the source code.


Jonas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 18:07:13 schrieb Jonas Maebe:

> On 30 Aug 2012, at 17:14, Rainer Stratmann wrote:
> > TP for DOS at
> > least supports a function result (as I remember) thus it is not Delphi
> > only as you mention.
>
> Turbo Pascal does not support the "result" alias for the function result.
>
> > What's wrong with such a message that is easy to implement and will help
> > beginners to freepascal a lot?
>
> We give such a message when someone tries to define a "class" type without
> having ObjFPC/Delphi mode activated. That is a message that is always
> correct, because
>
> type
>   tsomething = class
>   end;
>
> does not and cannot have any other meaning in another compilation mode. As
> has been pointed out by other people, that is not true for random
> occurrences of the word "result" in the source code.

Even then the message
"are you in the right
syntax-mode? only ObjFPC (-MObjfpc) or Delphi (-Mdelphi) mode supports a
function result"
can not be wrong. Added to this that the occurence of the identifier "result"
not using in combination with a function result is very unlikely. I think
99,99% has to do with the scenario that I described. And maximum in one of a
thousand cases it is the scenario that has been pointed out above.

>
> Jonas
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Tomas Hajny-2
In reply to this post by Rainer Stratmann
On Thu, August 30, 2012 17:14, Rainer Stratmann wrote:

> Am Thursday 30 August 2012 16:50:30 schrieb Tomas Hajny:
>> > The scenario occures when someone starts freepascal as I already
>> > documented in
>> > my first E-Mail.
>> >
>> > When someone wants to compile a TurboPascal or Delphi program with
>> > freepascal.
>> > Then he already knows that result is a function result, but freepascal
>> > gives
>> > an error about this.
>>
>> Identifier Result was not known/supported as function result in TP/BP,
>> i.e. your statement applies to Delphi only. Still, people with Delphi
>> background are obviously more likely to come across FPC nowadays, but
>> these people usually need $MODE DELPHI anyway due to many other things
>> they are used to and I miss to see how this one particular case improves
>> the overall situation for them. On the other hand, pointing out all
>> differences among the different modes by similar compiler messages is
>> fairly likely to require considerable effort.
>>
>> Tomas
>
> It is not about pointing out all differences.
>
> It is _simply_ that what I guess occures often when a beginner starts with
> freepascal. The realization of this message is easy I think. TP for DOS at
> least supports a function result (as I remember) thus it is not Delphi
> only as you mention.

I tried it with TP 7.0 before my post to make sure that my memory served
well. I'm not aware of any such function in TP/BP either, at least not in
unit System (I checked too, just in case ;-) ).


> Even if it is Delphi only the programmer who switched to
> freepascal sees the message 'identifier "result" not found' and is forced
> to
> study the documentation (which he already has to do much when starting
> with
> setting up the whole fpc environment). I have this thought that freepascal
> is
> not mature when I saw this the first time. And if there is a _simple_
> message
> like described in other mails then the most obscurities are eliminated. In
> TP/BP there was not a syntax mode as far as I remember (or preconfigured
> one). The IDE worked out of the box!

Yes, of course. FPC works out of the box too for supported syntax, equally
to TP/BP (and you even have more options to choose from).


> What's wrong with such a message that is easy to implement and will help
> beginners to freepascal a lot?

I'm afraid that this leads nowhere. I question your assumption that
"Result" is specifically more important than the other incompatibilities
among different modes (i.e. your statement that it "will help...a lot"). I
do not say that it is wrong to be more helpful in error messages, but
rather that your proposal tries to "fix" a very small fragment of
something much more general and moreover that the proposed message may be
very easily misleading as already demonstrated by Mark. Yet other cases
might not be detected by the compiler at all:
---
var
 Result: boolean;

function F: boolean;
begin
 F := false;
{some longer section of code may appear here}
 Result := true;
end;

begin
 WriteLn (F);
 WriteLn (Result);
end.
===

This code is valid for both fpc and objfpc modes, but the output is
different. Should the compiler try to detect it somehow?  It could point
it out by providing a hint about Result having some special meaning in
other modes but should it?

I could equally ask why TP 7.0 errors out on:
---
var
 S: string;
begin
 S := 3.1415926;
end.
===

 with:

---
TEST.PAS(4): Error 26: Type mismatch.
 S := 3.1415926;
               ^
===

instead of the much friendlier message

---
test.pas(4,7) Error: Incompatible types: got "Extended" expected
"ShortString"
===

provided by FPC. I'd assume that type incompatibilities are a much more
common issue for beginners (and not only them). Should FPC suggest the
user to add quotes around '3.1415926' or to use some other variable or to
call some conversion procedure like Str or ...? No, it should not because
it doesn't know what the user intended to do.

Tomas


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Rainer Stratmann
Am Thursday 30 August 2012 18:28:41 schrieb Tomas Hajny:
> I
> do not say that it is wrong to be more helpful in error messages, but
> rather that your proposal tries to "fix" a very small fragment of
> something much more general and moreover that the proposed message may be
> very easily misleading as already demonstrated by Mark. Yet other cases
> might not be detected by the compiler at all:

Ok so you prefer to let the beginner leave out in the rain.
Because he and someone else (more experienced) _could_ mislead a clearly
formulated message (are you in the right syntax mode?).
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Identifier not found "result"

Mark Morgan Lloyd-5
In reply to this post by Rainer Stratmann
Rainer Stratmann wrote:

> Am Thursday 30 August 2012 18:07:13 schrieb Jonas Maebe:
>> On 30 Aug 2012, at 17:14, Rainer Stratmann wrote:
>>> TP for DOS at
>>> least supports a function result (as I remember) thus it is not Delphi
>>> only as you mention.
>> Turbo Pascal does not support the "result" alias for the function result.
>>
>>> What's wrong with such a message that is easy to implement and will help
>>> beginners to freepascal a lot?
>> We give such a message when someone tries to define a "class" type without
>> having ObjFPC/Delphi mode activated. That is a message that is always
>> correct, because
>>
>> type
>>   tsomething = class
>>   end;
>>
>> does not and cannot have any other meaning in another compilation mode. As
>> has been pointed out by other people, that is not true for random
>> occurrences of the word "result" in the source code.
>
> Even then the message
> "are you in the right
> syntax-mode? only ObjFPC (-MObjfpc) or Delphi (-Mdelphi) mode supports a
> function result"
> can not be wrong. Added to this that the occurence of the identifier "result"
> not using in combination with a function result is very unlikely. I think
> 99,99% has to do with the scenario that I described. And maximum in one of a
> thousand cases it is the scenario that has been pointed out above.

But such an error message would have to come from code that recognised
'result' as a special case, which it is not: in no mode is 'result'
either a predefined identifier or a reserved word. Or rather
(speculating, and expecting Jonas to correct me :-) 'result' has a
special meaning when a function declaration is parsed, but not when the
block which forms the function body is compiled.

I'm not denying that an improved error message might be useful. However
its implementation might result in far more work than is justified.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
12