Sign in Join

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

Mailing lists / fpc-devel / 2010-08

Proposal: Multiple assignments

11 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

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

Unknown author

Hello everybody,

probably this is not really new stuff, but... May I propose multiple assignments, e.g.
  a,b:=0;
or
  a,b += c+d;
The right hand expression should be evaluated once and assigned (independently and in no particular order) to all the entries to the left of := .

Jasper
___________________________________________________________ Neu: WEB.DE De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: https://produkte.web.de/go/demail02

Reply by email

Michael Schnell
to Unknown author
a,b:=0;

Does _any_ language support that paradigm ?

AFAIK, lisp can do assignments to lists, but I don't know the syntax.

I once used a language that allowed for functions with multiple return values:

a, b := myfunc(x);

I felt that this makes some sense, but

a,b := 0    just as a short for
a := 0; b := 0;

does not seem like a great improvement.

-Michael

Reply by email

Michael Schnell
to Sven Barth
Sven Barth wrote 7 lines
Am 06.08.2010 09:18, schrieb Michael Schnell: > On 08/05/2010 10:17 PM, wrote: >> a,b:=0; > Does _any_ language support that paradigm ? Python: http://docs.python.org/reference/simple_stmts.html#assignment-statements

Seems like a different paradigm:

Show quoted text 6 lines
i, x[i] = 1, 2 Java: http://www.freejavaguide.com/assignment_operators.htm Although "a=b=c" is more like "assign c to b and assign (the new value of) b to a" (but it might work in C as well that way).

Seems like a different paradigm as well:

d = a = b;

Michael

Reply by email

Mark Morgan Lloyd
to Sven Barth: Python: http://docs.python.org/reference/simple_stmts.html#assignment-statements Java:…
Sven Barth wrote
> Does _any_ language support that paradigm ? Python: [...] Java:

Also Perl as (a, b) = (0, 0); I can't remember whether a single value on the RHS is expanded.

Although "a=b=c" is more like "assign c to b and assign (the new value of) b to a" (but it might work in C as well that way).

Please excuse a comment from a non-developer but I really don't like this form. I've coded a number of parsers for script languages etc. and in general provided that you don't allow multiple assignment you can always work out unambiguously whether you're looking at an assignment or a test for equality, even without mandating distinct tokens.

I think that the OP needs to research first whether what he is trying to do could be done by a typed constant assignment, or if there is some way of building on the associated semantics rather than attempting ill-considered mutilation of Pascal's underlying syntax.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Alexander Klenin
to Michael Schnell: Does _any_ language support that paradigm ? AFAIK, lisp can do assignments to lists, but…
Michael Schnell wrote
a, b := myfunc(x); I felt that this makes some sense, but

Agree, especially combined with built-in "dummy" variable, so you can do
(_, _, a, _, b) := FuncWithManyOutputs(x);
to get only some of outputs.

Show quoted text 5 lines
a,b := 0    just as a short for a := 0; b := 0; does not seem like a great improvement.

Also agree.

Alexander S. Klenin

Reply by email

Alexander Klenin
to Marcos Douglas
Marcos Douglas wrote 15 lines
On Fri, Aug 6, 2010 at 7:12 AM, Alexander Klenin wrote: > > On Fri, Aug 6, 2010 at 18:18, Michael Schnell wrote: > > > a, b := myfunc(x); > > > > I felt that this makes some sense, but > > Agree, especially combined with built-in "dummy" variable, > so you can do > (_, _, a, _, b) := FuncWithManyOutputs(x); > to get only some of outputs. It sounds like Lua language, look: http://www.lua.org/manual/5.1/manual.html#2.4.3

It also sounds like Python, Perl, Haskell, Prolog... basically every language except Pascal family and C ;-)

Alexander S. Klenin

Reply by email

Sven Barth
to Mark Morgan Lloyd: Also Perl as (a, b) = (0, 0); I can't remember whether a single value on the RHS is…
Mark Morgan Lloyd wrote 8 lines
> Although "a=b=c" is more like "assign c to b and assign (the new value > of) b to a" (but it might work in C as well that way). Please excuse a comment from a non-developer but I really don't like this form. I've coded a number of parsers for script languages etc. and in general provided that you don't allow multiple assignment you can always work out unambiguously whether you're looking at an assignment or a test for equality, even without mandating distinct tokens.

Well... in C a test for equality is always "==". So, when reading it (and not having read a Pascal code some minutes before :P ) one should recognize without problems whether it's an assignment or a comparison expression (it's another story that many people - including me - don't recognize it that easily ^^)

Regards,
Sven

Reply by email

Mark Morgan Lloyd
to Sven Barth
Sven Barth wrote 5 lines
Well... in C a test for equality is always "==". So, when reading it (and not having read a Pascal code some minutes before :P ) one should recognize without problems whether it's an assignment or a comparison expression (it's another story that many people - including me - don't recognize it that easily ^^)

As in the classic patch

+       if ((options == (__WCLONE|__WALL)) && (current->uid = 0))
+                       retval = -EINVAL;

which somebody tried to slip into the Linux kernel.

I think though that you only need distinct tokens (i.e. == vs = in the case of C) if the language includes multiple assignments. Or possibly I should say indeterminate assignments, lest there are cases where being able to discard a function's return value introduces ambiguity.

So some variant of OP's suggestion such as (a, b):= 0 does have
something going for it, at least when compared with a:= b:= 0. In fact-
although I don't know whether this is parseable- (a, b):= X with
implicit duplication as compared with (a, b):= (X, Y) where both sides
have to match, since <wild_speculation> this is beginning to look like
something that could be parallelised </>.
Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Vinzent Höfler
to Sven Barth: Well... in C a test for equality is always "==". So, when reading it (and not having read…

Sven Barth :

Well... in C a test for equality is always "==".

No, it's not. There's also strcmp(). ;)

Show quoted text 5 lines
So, when reading it (and not having read a Pascal code some minutes before :P ) one should recognize without problems whether it's an assignment or a comparison expression (it's another story that many people - including me - don't recognize it that easily ^^)

a=b=c
a==b=c
a=b==c
a==b==c

C's main flaw is that assignments are expressions as well. And I'm not sure, I'd spot the difference immediately.

Vinzent.

Neu: GMX De-Mail - Einfach wie E-Mail, sicher wie ein Brief! Jetzt De-Mail-Adresse reservieren: http://portal.gmx.net/de/go/demail

Reply by email