Specman has the apply()
method to perform the same action on all elements of a list:
var a: list of int;
a = somefunction.that.returns.list.of.int();
var b:= a.apply(it * 2);
Where apply()
does the same as:
for each in a {
b.add(it.*2);
};
Now, if I want to call a method on the elements of a
, I can use apply()
so long as the method returns a value. However, if I have:
struct bar {
x: int;
foo() is {
message(LOW, "x is ", x);
};
};
And I try to do:
var a: list of bar;
a = somefunction.that.returns.list.of.bar();
a.apply(it.foo());
It doesn't compile, because foo()
returns void
. Instead, I have to use an explicit loop:
for each in a {
it.foo();
};
Is there a method in specman similar to apply()
that doesn't require a return value?