I have a recursive function that does some work to an object for a repeated
amount of times.
f[h_, repeated_Integer /; repeated >= 0, level_Integer /; level > 0] :=
Module[{},
(* Do some stuff to h using level then call foo on h *)
foo[h, If[level < repeated, f[h, repeated, level + 1], final[h] ]]
]
I mostly pass in 1
for the level
parameter but there are times where I want to start at a different level (aka depth) of h
. I found I could use the longhand Optional
to skip passing in 1
for level all the time.
Optional[level_Integer /; level > 0 , 1]
However, before this I tried using shorthand optional :
with no success.
(level_Integer : 1) /; level > 0
and
(level_Integer /; level > 0) : 1
Both of these give syntax errors. Is there a way to do this with shorthand optional :
?
PatternTest
+Optional
. 4937 $\endgroup$g[x_Integer /; x >= 0, y_Integer /; y > 0] /; y > x := {x , y}
. Now that is powerful stuff. :-) $\endgroup$