Understanding 'self' - problem with .z.s[]

I wrote a function for permutation:

q) perm:{[a] $[2 = count a ; (a;reverse a);raze each[{ (first
x) ,/: perm[x _ 0]} ] each[{x rotate y}[;a]] til count a ]}
and
q) perm 1 2 3
works fine.

However, when i replace the recursive call to ‘perm’ with ‘.z.s’, it
gives error 'stack.

q) perm:{[a] $[2 = count a ; (a;reverse a);raze each[{ (first
x) ,/: .z.s[x _ 0]} ] each[{x rotate y}[;a]] til count a ]}
q)perm 1 2 3

GIVES ERROR:

'stack
@
{ (first x) ,/: .z.s[x _ 0]}
`int$()

Can anyone explain the reason for the same ?
Thanks

.z.s in the place you’ve put it is not equals perm, but rather nested lambda it’s lodged in. So, you’re blowing up the call stack by never exiting recursion.

Cheers,
Oleg

Yeah, .z.s is the self call for the function??

{ (first x) ,/: .z.s[x _ 0]}

and does not call perm as intended.

Example :?

f:{show `Hi;{$[x<0;x;[show x;.z.s[x-1]]]}}

Output : f 4

`Hi

4

3

2

1

0

-1


Cheers !

Sayantan.