[nem-bug] [Nemerle 0000724]: if/else & return values
feedback at nemerle.org
feedback at nemerle.org
Wed Aug 2 10:02:23 CEST 2006
A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=724>
======================================================================
Reported By: IT
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 724
Category: The Macro Library
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 07-31-2006 08:51 CEST
Last Modified: 08-02-2006 10:02 CEST
======================================================================
Summary: if/else & return values
Description:
This code gives me an error:
def foo() : int
{
if (1 > 2)
{
_ = 1;
}
else
3
4
}
_ = foo();
======================================================================
----------------------------------------------------------------------
Snaury - 07-31-06 09:39
----------------------------------------------------------------------
I don't see any bug here. First, you should have written it like this:
def foo() : int
{
if (1 > 2)
{
_ = 1;
}
else
3;
4
}
But then you'd get different values (void and int) in different branches
of int, so it really should have been:
def foo() : int
{
if (1 > 2)
{
_ = 1;
}
else
_ = 3;
4
}
----------------------------------------------------------------------
VladD2 - 07-31-06 23:10
----------------------------------------------------------------------
I agree with Snaury.
----------------------------------------------------------------------
IT - 08-01-06 03:21
----------------------------------------------------------------------
Got it. If/else is more an operator than a statement. But it's confusing at
least for beginning.
This issue needs to be closed.
----------------------------------------------------------------------
VladD2 - 08-01-06 21:39
----------------------------------------------------------------------
Nemerle has no statement. And it's cool! :)
----------------------------------------------------------------------
IT - 08-02-06 05:23
----------------------------------------------------------------------
In this particular case it's not cool, it's confusing. I did not expect two
different branches of code to return values of the same type. I did not
even mean the 'if' part to return anything.
Well, I understand I am talking as an imperative style developer. So, I
want to try and to see if this feature is not going to get annoying when I
get inspired :)
----------------------------------------------------------------------
Snaury - 08-02-06 10:02
----------------------------------------------------------------------
If you want imperative style parameters you can always use
Nemerle.Imperative. Just don't forget to ignore unneeded return values
(with _ = ...) and use regular break/continue/return like in other
languages. But in your example for this bug it was more of a forgotten
semicolon, btw. :)
using Nemerle.Imperative;
def foo() : int
{
if(1 > 2)
_ = 1
else
return 3;
return 4; // or just `4'
}
But honestly, once you understand that (almost) everything in Nemerle are
expressions, you will be able to do things you couldn't even imagine to do
in other languages. :) At lease so was for me...
Issue History
Date Modified Username Field Change
======================================================================
07-31-06 08:51 IT New Issue
07-31-06 09:39 Snaury Note Added: 0001383
07-31-06 23:10 VladD2 Note Added: 0001384
08-01-06 03:21 IT Note Added: 0001385
08-01-06 21:39 VladD2 Note Added: 0001388
08-02-06 05:23 IT Note Added: 0001389
08-02-06 10:02 Snaury Note Added: 0001390
======================================================================
More information about the bugs
mailing list