-
-
Save Varriount/8484926 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Current styles of generic procedures | |
# Generic | |
proc foo[T](a: int, b: T): T = | |
result = b | |
var i = 0 | |
while i < a: | |
result = result+b | |
# Typedesc | |
proc foo(T:typedesc, a: int, b: T): T = | |
result = b | |
var i = 0 | |
while i < a: | |
result = result+b | |
# The generic style procedure can be 'instanciated' | |
var genProc = foo[int] | |
# But the Typedesc can't | |
# However the typedesc supports more calling kinds (can't remember atm) | |
# So why not make the [] accept more than just types? | |
var newProc = foo[int, 5] # Only accepts one argument, a number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment