There are some solutions, but all a little awkward.

1\. ["do" 
notation](https://nim-lang.org/docs/manual_experimental.html#do-notation), 
which I believe was moved to _experimental_ just before Nim 1.0, therefore 
might be changed or scrapped in a future Nim version.

Personally I think it's even harder to read than the plain `proc` version. 
    
    
    let plusTwo = twice(10) do (n:int) -> int:
      echo "Another gratuitious echo"
      n + 1
    
    
    Run

2\. Sugar module with a [statement list 
expression](https://nim-lang.org/docs/manual.html#statements-and-expressions-statement-list-expression)
 where the last expression in the brackets is treated as the value.

Not idiomatic, wouldn't recommend. 
    
    
    let plusTwo2 = twice(10, n => (
      echo "Another gratuitious echo";
      n + 1
    ))
    
    
    Run

3\. Sugar module with a [block 
expression](https://nim-lang.org/docs/manual.html#statements-and-expressions-block-expression).

I almost like this one! Unfortunately if you remove the brackets, you get " 
_Error: expression expected, but found 'keyword block'_"
    
    
    let plusTwo3 = twice(10, n => (block:
      echo "Another gratuitious echo"
      n + 1
    ))
    
    
    Run

Does anyone know, is this a syntax limitation, or could the `=>` operator be 
modified to allow a block expression without brackets? 

Reply via email to