hughperman / pure-lang

Automatically exported from code.google.com/p/pure-lang
0 stars 0 forks source link

Interpreter doesn't like __lambda__ [] 1 #78

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
> __lambda__ [] 1;
Assertion failed: (!args->empty()), function lambda, file expr.cc, line 140.
Abort trap: 6 (core dumped)

What is the expected output?
I don't know if this should even be legal. I was creating some __lambda__ [] 
... forms as part of a recursive macro, and wanted to see what it expanded to 
on its own. Perhaps a nullary function? But even if it's correct for it to be 
illegal, it'd still be nice not to crash the interpreter and lose my history.

What version of the product are you using?
Pure 0.53 on FreeBSD

Original issue reported on code.google.com by dubious...@gmail.com on 16 Jun 2012 at 1:07

GoogleCodeExporter commented 8 years ago
Well spotted. :) Actually, there are similar problems with the __case__, 
__when__ and __with__ macros as well.

In the case of __lambda__, __when__ and __with__ one might argue that the 
corner cases with an empty list argument should evaluate to just the target 
expression (or body of the lambda, respectively). But I think that for 
consistency these cases should all be left undefined since these constructs 
aren't permitted in the language either.

Also, this gives the programmer the opportunity to define these cases any way 
he likes. So if you want to just eliminate trivial 'when' blocks then you may 
want to have:

def x __when__ [] = x;

But for __lambda__ it may be preferable to emulate a parameterless closure 
using a thunk, so you'd define:

def __lambda__ [] x = x&;

I'm currently giving this a try, so stay tuned.

Original comment by aggraef@gmail.com on 16 Jun 2012 at 7:46

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 372995eb1c1c.

Original comment by aggraef@gmail.com on 16 Jun 2012 at 8:19

GoogleCodeExporter commented 8 years ago
Terrific turnaround time!

Original comment by dubious...@gmail.com on 16 Jun 2012 at 12:29