What if its scope were delineated explicitly?

 -E

On Wed, 9 Feb 2022, 'Pascal Jasmin' via Programming wrote:

Just to follow up that this limitation/feature of f. is a necessary one.  When using $: 
as recursion (potential multiple repeats) limiting its scope to just its (named) self is 
or at least feels like a prudent way to avoid recursion errors.  Errors that are more 
painful than most since infinite recursion requires a "break" to get control 
back.






On Wednesday, February 9, 2022, 11:29:25 a.m. EST, 'Pascal Jasmin' via Programming <programm...@jsoftware.com> wrote:




dictionary page for f. mentions "problems" with f. when u includes $:

this example seems ok though:

 + 1 : ' 0 & $: : (u/ % #) f.'

0&$: :(+/ % #)

cut f.

' '&$: :([: -.&a: <;._2@,~)

but:

, 1 : ' u@cut f.'

,@(' '&$: :([: -.&a: <;._2@,~) (1 : 0))

u y

:

x u y

)

adds some "explicit boilerplate"

n&$: is an extremely useful pattern for providing default x argument to dyad.


I still passionately hate the new AC train interpretation.  (should be uACv 
instead of uACu), but it does offer an elegant-ish workaround.

([: -.&a: <;._2@,~) ((' '&) :)

' '&([: -.&a: <;._2@,~) :([: -.&a: <;._2@,~)

that should be faster as well in that $: is an extra call that probably 
includes edge cases that interfere with f.

An even more elegant workaround though is:

mdef =: 2 : 'n&u : u'  NB. monad default parameter n to dyad u

cut =: ([: -.&a: <;._2@,~) mdef ' '  NB. same result as tacit AC modifier above.


"explicit junk boilerplate" now removed.

, 1 : ' u@cut f.'

,@(' '&([: -.&a: <;._2@,~) :([: -.&a: <;._2@,~))
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to