Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2011-01

+= with properties

8 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michael Schnell

+= does work for variables, even Strings.

AFAIR, there already has been a discussion about += and friends for properties.

In fact I don't see why the compiler not just generates "x.a := x.a + y" from "x.a += y" before doing any code generating, disregarding what x.a is. Of course an error message will occur if x.a is not writable for any reason.

Thanks,
-Michael

Reply by email

Alexander Klenin
to Michael Schnell
Michael Schnell wrote 9 lines
+= does work for variables, even Strings. AFAIR, there already has been a discussion about += and friends for properties. In fact I don't see why the compiler not just generates "x.a := x.a + y" from "x.a += y" before doing any code generating, disregarding what x.a is. Of course an error message will occur if x.a is not writable for any reason.

Blindly replacing "a += b" with "a := a + b" may lead to a semantic change if "a" is an expression with side-effects.
Nevertheless, I do think that implementing += for properties is a good idea, but unfortunately FPC developers disagree.

Alexander S. Klenin

Reply by email

Michael Schnell
to Alexander Klenin
Alexander Klenin wrote
Blindly replacing "a += b" with "a := a + b" may lead to a semantic change if "a" is an expression with side-effects. Nevertheless, I do think that implementing += for properties is a good idea, but unfortunately FPC developers disagree.

I do see that also properties could show site effects when used in a += expression, as they are accessed twice. But is this (in nearly all cases) not exactly what the user would expect ?

-Michael

Reply by email

Unknown author
to Michael Schnell
Michael Schnell wrote 9 lines
On 01/12/2011 04:48 PM, Alexander Klenin wrote: > Blindly replacing "a += b" with "a := a + b" may lead to a semantic change > if "a" is an expression with side-effects. > Nevertheless, I do think that implementing += for properties is a good > idea, > but unfortunately FPC developers disagree. I do see that also properties could show site effects when used in a += expression, as they are accessed twice. But is this (in nearly all cases) not exactly what the user would expect ?

Most of the time, yes. But there are some subtleties with interfaces and reference counting, which could bite you in the leg.

(as they already have for some people).

Michael.

Reply by email

Marco van de Voort
to Unknown author: Most of the time, yes. But there are some subtleties with interfaces and reference…

In our previous episode, said:

Show quoted text 6 lines
> exactly what the user would expect ? Most of the time, yes. But there are some subtleties with interfaces and reference counting, which could bite you in the leg. (as they already have for some people).

Moreover, that IMHO the c operators are mostly meant for porting of existing C code. And I never saw C code with properties :-)

Reply by email

Hans-Peter Diettrich
to Michael Schnell: += does work for variables, even Strings. AFAIR, there already has been a discussion…
Show quoted text 7 lines
+= does work for variables, even Strings. AFAIR, there already has been a discussion about += and friends for properties. In fact I don't see why the compiler not just generates "x.a := x.a + y" from "x.a += y" before doing any code generating,

This would result in the same error, because x.a is not an lval.

DoDi

Reply by email