Nim macro parameters -


here' code want compile:

macro definesomething(amount:expr):stmt=    var amountint = intval(amount).int    # boring staff  definesomething(42); 

it works perfectly. have want inside macro can operate staff in own way.

but think, that, better remove magic number const settings:

const magic_amount:int = 42  # whole lot of strings definesomething(magic_amount) 

this code fails. because magic_amount literally not integer value unlike 42 magic number.

so, how variable value inside macros in nim?

expressions untyped. since want integers can specify parameter typed , should compile:

import macros  macro definesomething(amount: typed):stmt=   echo gettype(amount)   var amountint = intval(amount).int   echo "hey ", amount_int  const magic_amount = 42 definesomething(43) definesomething(magic_amount) 

or use normal int parameter type unless want passed other types case on parameter's kind inside macro.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -