S: isn't relevant to recusion, though $: is for tacit versions.
if you want to double a fixed number of times, then ^: is iteration and
appropriate.
To help in using $:, nearly every problem can be formulated with @.
if monad
final_display ` $:@:intermediate_transform @.stop_condition
if dyad
final_display `(transformofleft@[ $: intermediate_transform@] )@.stop_condition
imt =: ] , +:@{:
if the problem was double y arg until it is greater than x arg
100 }:@]`([ $: imt@])@.([ >: {:@]) 2
2 4 8 16 32 64
if as originally tasked, a fixed amount of times (but transform both sides)
6 ]`(<:@[ $: imt@])@.(1 < [) 5
5 10 20 40 80 160
________________________________
From: Skip Cave <[email protected]>
To: "[email protected]" <[email protected]>
Sent: Tuesday, June 12, 2018 2:08 AM
Subject: [Jprogramming] Recursion
I want to try to understand recursive functions in J. To start this
learning process, I want to investigate J verbs that will generate a
doubling sequence. For example, the verb 'd' where x = the starting
integer, and y = the number of iterations:
2 d 6
2 4 8 16 32 64
5 d 4
5 10 20 40
7 d 10
7 14 28 56 112 224 448 896 1792 3584
Define three different simple recursive verbs in J, to implement this
recursive doubling function:
1. d1 - Just calling the function recursively
2. d2 - Using the Power operator ^:
3. d3 - Using Spread S: and Memo M.
Skip
Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm