X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=google.com; s=20120113;
h=x-beenthere:received-spf:mime-version:in-reply-to:references:date
:message-id:subject:from:to:cc:x-system-of-record:x-gm-message-state
:x-original-sender:x-original-authentication-results:precedence
:mailing-list:list-id:x-google-group-id:list-post:list-help
:list-archive:sender:list-subscribe:list-unsubscribe:content-type;
bh=xjlsuUjBttA9ueBsy8nLpKjAIFZhZbdErB2kJ2F93/c=;
b=RseTAMwG8RdSd0keKWzRKYrhTVQg9ZKALC5Vf6rBpgLRWz8AEeHJIQexGsAOo4RaiZ
dYH+jQFvNJZoNfBVRqCQJxey27ZjKAnG/w4/3tximszV5qpJ/MqozLI7a4In+Wn0JzD3
B2B5vMCoBFUUfihw+jk8zdipeNgJrGdvfvD/TvodVtbbeHi1MGL18B1/ZTTK6hos2iL8
8AV6vaN3Q5HEgil/gmLtwqVXR+E/GaNm3f/5qAJCFtpRJj7wujnq1VAkJWTCAvxy1+Fb
Wdxwo4MxcqgpG22kuO1+o8cTxnio5lyzituKflMrGDKycXNhArdyCY
Received: by 10.68.234.193 with SMTP id ug1mr3429241pbc.19.1348587798695;
Tue, 25 Sep 2012 08:43:18 -0700 (PDT)
X-BeenThere: golang-nuts-/***@public.gmane.org
Received: by 10.68.237.161 with SMTP id vd1ls1194297pbc.3.gmail; Tue, 25 Sep
2012 08:43:16 -0700 (PDT)
Received: by 10.66.90.36 with SMTP id bt4mr3405119pab.5.1348587795998;
Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
Received: by 10.66.90.36 with SMTP id bt4mr3405118pab.5.1348587795957;
Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
Received: from mail-pb0-f53.google.com (mail-pb0-f53.google.com [209.85.160.53])
by gmr-mx.google.com with ESMTPS id p7si217934pby.0.2012.09.25.08.43.15
(version=TLSv1/SSLv3 cipher=OTHER);
Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
Received-SPF: pass (google.com: domain of iant-hpIqsD4AKlfQT0dZR+***@public.gmane.org designates 209.85.160.53 as permitted sender) client-ip=209.85.160.53;
Received: by pbcwz12 with SMTP id wz12so328408pbc.40
for <golang-nuts-/***@public.gmane.org>; Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
Received: by 10.66.88.233 with SMTP id bj9mr41664753pab.72.1348587795837;
Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
Received: by 10.66.88.233 with SMTP id bj9mr41664725pab.72.1348587795658; Tue,
25 Sep 2012 08:43:15 -0700 (PDT)
Received: by 10.68.129.170 with HTTP; Tue, 25 Sep 2012 08:43:15 -0700 (PDT)
In-Reply-To: <CAB3Vzbo=waR636XBSQyAVcSuizYOhC+JrHvdf-_SRJkpk9Kqmg-JsoAwUIsXosN+***@public.gmane.org>
X-System-Of-Record: true
X-Gm-Message-State: ALoCoQkhQGd/thdPmG08+OZFqq9sWuZ00rERdNgal5OmjqspsBAK9aPJLPVT6rxj0SujvAhrCK9tx3VIywK2YPlzSRrNWpYFtjbmQ/kDUPgMuEVHrJmPWbkxWV7aIMMNWaBBu0BU+zIwAomoq9itBWc3jNCIW53dJYZQ9Rtf2IDq8k8NnwrYFi1OGf+qXJ19yL8y96YD1PoP3EL1/Fpygf8p6RjedrEt7w==
X-Original-Sender: iant-hpIqsD4AKlfQT0dZR+***@public.gmane.org
X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
domain of iant-hpIqsD4AKlfQT0dZR+***@public.gmane.org designates 209.85.160.53 as permitted sender)
smtp.mail=iant-hpIqsD4AKlfQT0dZR+***@public.gmane.org; dkim=pass header.i=@google.com
Precedence: list
Mailing-list: list golang-nuts-/***@public.gmane.org; contact golang-nuts+owners-/***@public.gmane.org
List-ID: <golang-nuts.googlegroups.com>
X-Google-Group-Id: 332403668183
List-Post: <http://groups.google.com/group/golang-nuts/post?hl=en-US>, <mailto:golang-nuts-/***@public.gmane.org>
List-Help: <http://groups.google.com/support/?hl=en-US>, <mailto:golang-nuts+help-/***@public.gmane.org>
List-Archive: <http://groups.google.com/group/golang-nuts?hl=en-US>
Sender: golang-nuts-/***@public.gmane.org
List-Subscribe: <http://groups.google.com/group/golang-nuts/subscribe?hl=en-US>,
<mailto:golang-nuts+subscribe-/***@public.gmane.org>
List-Unsubscribe: <http://groups.google.com/group/golang-nuts/subscribe?hl=en-US>,
<mailto:googlegroups-manage+332403668183+unsubscribe-/***@public.gmane.org>
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.go.general/72383>
Post by Michael JonesI had imagined also being able to get to a switch statement via this
mechanism. That lets common handling be centralized. (shown in first email)
But the key mechanism is that non-nil / non-zero assignment means "take an
action"
Yeah, my idea is laughably non-general. But here is a different idea,
that is more like yours: let labels be variables. A read from a label
is just an ordinary read. When writing to a label, though, if the
value is non-zero, the program does a goto the label.
Then we can write
func F(filename string) error {
f, err := os.Open(filename)
_, err = f.Write("hi")
err = f.Close()
fmt.Println("done")
return nil
err:
return err
}
And since I can't let well enough alone, let's permit this same idea
with the special label "return", where of course it is only meaningful
to use the label name as a result parameter.
func F(filename string) (return error) {
f, return := os.Open(filename)
_, return = f.Write("hi")
return = f.Close()
fmt.Println("done")
return nil
}
No special handling of the error type, very little additional syntax
(permit the return keyword in a couple more places, and permit an
optional type on the label declaration so we can write "foo
interface{}:").
Ian
Post by Michael JonesPost by Ian Lance TaylorPost by Peterf, panic := os.Create("filename")
where assigning a non-nil value to panic would cause it to panic?
That's kind of interesting. I don't see quite how to make it work
with panic, but I see how it could work with return, which is a
keyword. One could say that
f, return = os.Create("filename")
was permitted if 1) the function being called returns a parameter of
the builtin type error at the point the return keyword is used; 2) the
function making the call returns a single parameter of the builtin
type error. It would mean: if the value assigned to the "return"
keyword is non-nil, then the calling function immediately returns,
with that value as the error result, and with the other results
holding whatever value they hold at that point (if the results are
unnamed, zero).
Magic syntactic sugar, yes, but not too hard to understand. Might be
overused, though, and doesn't help with the problem of ignoring the
result entirely, e.g., of f.Close().
Ian
--
--
650-335-5765
--