I agree that examples are one of the best ways to understand things. Will Gajate put up a list of examples using F. here: https://code.jsoftware.com/wiki/User:Will_Gajate/FoldVariants .
On Fri, Feb 26, 2021 at 2:59 AM 'Bo Jacoby' via Programming < [email protected]> wrote: > Loopless code? > I struggled in vain to make this program loopless. > > En=: 4 : 0 NB. tombola summary program > y=.x*(+/%#)(,y)^/1+i.x > e=.1 > for_i. 1+i.x do. > e=.e,~i%~+/(_1^i.i)*e*i{.y > end. > _1&x:|.->{:p. e > ) > > > > > > 5j2":b=.4 En a=.?1000$0 NB. summary of 1000 numbers > 0.12 0.44 0.57 0.89 > > 1 En a NB. mean value of 1000 numbers > 0.504887 > 1 En b NB. mean value of just 4 numbers > 0.504887 > > > > > > > Can it be done? > Thanks! > Bo > > Den fredag den 26. februar 2021 08.30.53 CET skrev Hauke Rehr < > [email protected]>: > > I remember that knaves example. > Glad to see you agree x/y are better used the other way around. > P is a state altered by each of the knaves in K, respectively. > Another good example showing that, if 'control' vs 'data' were > a decisive creterion, the order of arguments would need to be changed. > > When I first read about it, I considered it a fun and approachable > example – and it lends itself to folding so I support elaborating on > this when compiling some learning material/show casing of folds. > > > Automata are another example: a starting state is altered by > successive transitions depending on items of a control input > into an accepting state. > So replaying a macro (fixed array of commands) takes any current > situation (data) and applies the commands one after the other, > resulting in the (hopefully intended) final situation. > > Maybe a “robot in a maze”-like game could show this where > users are given a set of macros and some goal to achieve, > and can apply the macros until they reach it, macros being > replayed by a fold. I’ll add that one to the list of projects > I’d hope to get around to implementing. Might even be used > for teaching programming, just as the “laby” game does. > > https://sgimenez.github.io/laby/ > > > Am 26.02.21 um 02:33 schrieb Jose Mario Quintana: > > Different people may have different preferences, mine is a form that I > have > > used for many years and roughly corresponds to, > > > > fold=. {{ y (v F:. u) x}} > > > > > > Thus, the example in, > > > > Loopless Code VI: Temporary Variables (jsoftware.com) > > <https://www.jsoftware.com/help/jforc/loopless_code_vi_temporary_v.htm> > > > > becomes, > > > > knave=. [ ,~ \:~ @: (] }.~ [: # [) > > > > ( P=. 100 25 100 50 5 10 ) > > 100 25 100 50 5 10 > > ( K =. _2 ]\ 50 50 100 25 5 10 25 50 25 10 ) > > 50 50 > > 100 25 > > 5 10 > > 25 50 > > 25 10 > > > > K ([ (knave fold ] ) {:@:[ , ]) P > > 100 100 50 25 10 5 50 50 > > 50 50 50 25 10 5 100 25 > > 100 50 25 25 10 5 5 10 > > 25 25 10 10 5 5 25 50 > > 50 25 10 10 5 5 25 10 > > > > I hope it helps > > > > > > > > > > > > On Thu, Feb 25, 2021 at 7:03 PM Hauke Rehr <[email protected]> > wrote: > > > >> For labs and the wiki, we should have some examples > >> easily understood. I have an example where at least > >> what it does is easily understood but I won’t show > >> the implementation – I did a bad job there > >> Essentially, it’s $ with fill. > >> Just like the other example I mentioned, { > >> > >> > >> 2 4 7 (] F.: step)~ i.100 > >> 0 1 2 3 4 5 6 > >> 7 8 9 10 11 12 13 > >> 14 15 16 17 18 19 20 > >> 21 22 23 24 25 26 27 > >> > >> 28 29 30 31 32 33 34 > >> 35 36 37 38 39 40 41 > >> 42 43 44 45 46 47 48 > >> 49 50 51 52 53 54 55 > >> > >> > >> 56 57 58 59 60 61 62 > >> 63 64 65 66 67 68 69 > >> 70 71 72 73 74 75 76 > >> 77 78 79 80 81 82 83 > >> > >> 84 85 86 87 88 89 90 > >> 91 92 93 94 95 96 97 > >> 98 99 0 0 0 0 0 > >> 0 0 0 0 0 0 0 > >> > >> > >> Am 25.02.21 um 17:51 schrieb Eric Iverson: > >>> I am a member of the silent majority on this issue. > >>> > >>> I have been pleased with the civility of the fold discussion > considering > >>> how emotional language issues can be. > >>> > >>> J is not designed by vote or committee. There are always going to be > >> strong > >>> disagreements. But we are a small community and are best served by, at > >> the > >>> appropriate time, burying those disagreements and moving on. I think > that > >>> time has come for fold. > >>> > >>> J is the better for having fold. Let's focus now on using it and > sharing > >>> how it can be used. Some labs or wiki pages would be nice! > >>> > >>> > >>> > >>> > >>> On Thu, Feb 25, 2021 at 11:25 AM Hauke Rehr <[email protected]> > >> wrote: > >>> > >>>> Good point about the silent ones: you’re right, I guess. > >>>> > >>>> I still disagree regarding fold being used the way you tell us. > >>>> What you want to do can be done with / and the likes. > >>>> Again, the main advantage of the fold verbs from my pont of view > >>>> is that there may be any kind of initial data processed by v > >>>> in a way given by x’s items’ values. > >>>> > >>>> But let’s just settle on “we agree to disagree” – I don’t think > >>>> further back and forth will lead us somewhere. > >>>> > >>>> (and maybe I need to get some rest ere I write more rubbish here) > >>>> > >>>> Hauke > >>>> > >>>> Am 25.02.21 um 17:19 schrieb 'Sergey Kamenev' via Programming: > >>>>> I think Henry Rich is most likely a genius programmer. > >>>>> > >>>>> By the way, I am a supporter of meritocracy, > >>>>> when the weight of a person's voice depends on his merits. > >>>>> > >>>>> But a programming language is written for the community. > >>>>> And so the voice of the community when discussing new features > >>>>> should carry a lot of weight. > >>>>> > >>>>> The definition of a fold itself implies that there is an array that > >> will > >>>>> fold. > >>>>> However, the initial value does not have to be an array, > >>>>> but what is collapsed arg must be an array. > >>>>> > >>>>> Right argument have more arrayness in comparing with left arg. > >>>>> > >>>>> The silent majority most likely does not use Fold verbs, > >>>>> therefore they are silent, since this topic does not concern them. > >>>>> > >>>>> Sergey. > >>>>> > ---------------------------------------------------------------------- > >>>>> For information about J forums see > http://www.jsoftware.com/forums.htm > >>>> > >>>> -- > >>>> ---------------------- > >>>> mail written using NEO > >>>> neo-layout.org > >>>> > >>>> ---------------------------------------------------------------------- > >>>> For information about J forums see > http://www.jsoftware.com/forums.htm > >>>> > >>> ---------------------------------------------------------------------- > >>> For information about J forums see http://www.jsoftware.com/forums.htm > >>> > >> > >> -- > >> ---------------------- > >> mail written using NEO > >> neo-layout.org > >> > >> ---------------------------------------------------------------------- > >> For information about J forums see http://www.jsoftware.com/forums.htm > >> > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > -- > ---------------------- > mail written using NEO > neo-layout.org > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Devon McCormick, CFA Quantitative Consultant ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
