passing functions as arguments and inline creation of lists
Posted: Thu Nov 14, 2013 4:03 am
Hello World!
Quite new to cobra i'm currently very excited about cobra's language design!
Beside of the obliged 4-space indentation (i prefer two- or one-space-indentation) cobra seems to be the language i always dreamed of!
So now about my issue.I want to do something like
As you may see, i'm used to play with the elder snake (python). There are two problems with this code:
It's kinda funny that i had the last problem also with c, with c++ and also with java (these are the only static typed languages i know). Most times i gave up restricting the passed functions after a while and just hoped for the best. As a beginner i'm now hoping that there's a nice way for coping this in cobra...
Quite new to cobra i'm currently very excited about cobra's language design!
Beside of the obliged 4-space indentation (i prefer two- or one-space-indentation) cobra seems to be the language i always dreamed of!
So now about my issue.I want to do something like
class Quantizer
...
get [i as int] as float
require 0 <= i < .count
return .first + (i*.delta)
def quantize(f as Func<of float>) as List<of float>
return [f(this[j]) for j in 0:.count]
As you may see, i'm used to play with the elder snake (python). There are two problems with this code:
- the inline list creation doesn't seem to work. The compiler says "error: Expecting GET, but got "]" (RBRACKET) instead." Is there a cobra'ish way for inline list creation?
- how can i make shure, that my quantize method only accepts functions which take a float as well as return a flot?
It's kinda funny that i had the last problem also with c, with c++ and also with java (these are the only static typed languages i know). Most times i gave up restricting the passed functions after a while and just hoped for the best. As a beginner i'm now hoping that there's a nice way for coping this in cobra...