[1144] in Coldmud discussion meeting

root meeting help first first in chain previous in chain previous next next in chain last in chain last

Re: [COLD] scatter/optional assignments - request for discussion

daemon@ATHENA.MIT.EDU (Fri Nov 29 16:25:24 1996 )

From: Andrew Wilson <andrew@aaaaaaaa.demon.co.uk>
To: Miroslav Silovic <Miroslav.Silovic@public.srce.hr>
Date: Fri, 29 Nov 1996 19:48:20 +0000 (GMT)
Cc: coldstuff@cold.org
In-Reply-To: <199611291401.PAA11414@jagor.srce.hr> from "Miroslav Silovic" at Nov 29, 96 03:01:55 pm

I didn't look too closely at this patch, but am I right in thinking
that the ?= operator is a simple test of existing value, rather
then an operation which is only performed if a variable has not
been assigned to previously?

Perl has a useful:

	$foo = $bar unless $foo;

construction, which only assigns a value to $foo if no previous
assignment has taken place.

Wouldn't this be logic (expressed as '$foo ?= $bar') be more useful?

Ay (prepared to be clueless...)

> This patch implements two new features:
> 
> Optional assignment expression:
> 
> 	foo ?= bar;
> 
> is equivalent to
> 
> 	if (!foo) foo=bar;
> 
> Scatter assignment is easiest to explain with a few examples:
> 
> 	[foo, bar] = [1,2]
> 	=> foo=1, bar=2
> 
> 	[foo, bar ?= 10] = [1]
> 	=> foo=1, bar=10
> 
> 	[foo, bar, @baz] = [1,2,3,4,5]
> 	=> foo=1, bar=2, baz=[3,4,5]
> 
> 	[[foo, bar], @rest] = [[1,2],[3,4],[5,6]]
> 	=> foo=1, bar=2, rest=[[3,4],[5,6]]
> 
[snip]