Guest User

Untitled

a guest
Feb 4th, 2015
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.82 KB | None | 0 0
  1. # Test assigning anonymous procs with macro pragmas.
  2. import macros
  3.  
  4. type
  5.     iiproc = proc (a :int): int
  6.  
  7. macro procmacro(actions: stmt): expr {.immediate.} =
  8.     # This macro will eventually do something
  9.     # interesting, if it works at all.
  10.     # When called with a proc expression
  11.     # it should expand to an expression.
  12.     echo()
  13.     echo(treeRepr(actions))
  14.     result = actions
  15.  
  16. # Assigning a lambda works.
  17. var add_one: iiproc
  18. add_one = proc (a: int): int =
  19.     return a+1
  20.  
  21. # Using the procmacro works.
  22. proc add_two(a: int): int {.procmacro.} =
  23.     return a+2
  24.  
  25. # Combine the two into one easy to use statement, fails on 0.10.2
  26. # with:
  27. # Error: value of type 'proc (int): int{.gcsafe, locks: 0.}' has to be discarded
  28. var add_three: iiproc
  29. add_three = proc (a: int): int {.procmacro.} =
  30.     return a+3
Advertisement
Add Comment
Please, Sign In to add comment