[nem-bug] [Nemerle 0000724]: if/else & return values
feedback at nemerle.org
feedback at nemerle.org
Fri Aug 4 22:11:00 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-04-2006 22:10 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:03
----------------------------------------------------------------------
If you want imperative style statements 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...
----------------------------------------------------------------------
aleksey - 08-02-06 15:52
----------------------------------------------------------------------
"Code blocks" might be viable alternative for return and break.
def foo() : int
{
ret : {
if (1 > 2)
_ = 1;
else
ret(3);
4
}
}
I dunno why, but more code I write in Nemerle more do I prefer its
"indentation-based" syntax over curly-braced one. Seemingly code blocks
look much better in identation-based syntax too.
def foo() : int
ret :
if (1 > 2)
_ = 1
else
ret(3)
4
----------------------------------------------------------------------
Snaury - 08-02-06 15:58
----------------------------------------------------------------------
About indentation syntax, me too. :) Sadly current nemerle for emacs seems
to be buggy, so whenever I press Ctrl+Alt+\ it would just turn my
indentation into trash...
----------------------------------------------------------------------
IT - 08-04-06 22:10
----------------------------------------------------------------------
> 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...
I don't need too much right now. I just need to implement VS integration
:)
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
08-02-06 10:03 Snaury Note Edited: 0001390
08-02-06 15:52 aleksey Note Added: 0001391
08-02-06 15:58 Snaury Note Added: 0001392
08-04-06 22:10 IT Note Added: 0001393
======================================================================
More information about the bugs
mailing list