v
v copied to clipboard
passing a function to a function as a parameter does not work
module parselona
pub struct ParserResult[O] {
i []u8
o O
}
type TParser[O] = fn([]u8) !ParserResult[O]
type TF[O] = fn([]u8) O
fn take_part(count u32) TParser[[]u8] {
return fn [count] (i []u8) !ParserResult[[]u8] {
if i.len<count { return error('error len: ${i}') }
return ParserResult[[]u8] {
i: i[count..],
o: i[..count],
}
}
}
fn map<O>(p TParser[u8], f TF[O]) TParser[O] {
return fn [p, f] <O>(i []u8) !ParserResult[O] {
r:=p(i)!
return ParserResult{i:r.i, o:f(r.o)}
}
}
fn test_1() {
input := '10_ttt_uuuu_qqq_'.bytes()
nnn:=take_part(2)
println(' it is: ${nnn(input)!}')
fnf := fn(i[]u8) int { return 1 }
n := map[int](nnn, fnf)
assert ['nn'] == ['ttt_', 'uuuu_', 'qqq_']
}
--- Testing... --------------------------------------------------------------------------------------------------------------------------------------
FAIL 0.000 ms /home/prof/projects/v/parselona/src/parselona_test.v
compilation failed:
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/tsession_704f1d69f740_01J4Q5YZCTYXCVAK9ESWAGAX7W/parselona_test.01J4Q5Z0T9ZS2Q9JCXM6E0YW4D.tmp.c:106: error: identifier expected
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error: