"Or, you can use ]^:]" Sneaky? (See, http://www.jsoftware.com/pipermail/programming/2013-January/031234.html and http://www.jsoftware.com/pipermail/programming/2013-January/031236.html )
" But maybe it's also easy enough to use J's parser and not bother with tacit for this kind of exercise? " Maybe, but the question that started this thread was, "Is it possible to define f tacitly?" On Sun, Feb 1, 2015 at 3:38 PM, Raul Miller <[email protected]> wrote: > Or, you can use ]^:] > > It's not really that hard. > > http://www.jsoftware.com/help/dictionary/d202n.htm says: > > u^:( v1`v2)y ↔ u^:(v1 y) (v2 y) > > So let's make v1 be 0: and v2 be a data structure which represents our > entire calculation: > > ]^:] 0:`(+:@:(0 1 2 3 4"_)) > 0 2 4 6 8 > > Now all we need is a verb which transforms > (+:`*:;i.5) > to > 0:`(+:@:(0 1 2 3 4"_)) > > It's straightfoward to do this explicitly. > > Let's define a test: > > ex=: +:`*:;i.5 > assert 0:`(+:@:(0 1 2 3 4"_)) -: fe ex > > Now we just need to define fe so that the above script does not throw > an error. So take a look at what 0:`(+:@:(0 1 2 3 4"_)) looks like and > transcribe that to code: > > fe=:3 :0 > '0:';<'@:';<((0;0){::y);<(,'"');<((,'0');1{::y);<((,'0');_) > ) > > Testing: > > ]^:] fe ex > 0 2 4 6 8 > > Now.. that expression for fe is messy, and a little tedious to write, > but if you don't mind a little bit of trial and error and > investigation while you work through whatever uncertainties you have > about what you are seeing, you can do it. > > And converting it to tacit can be done like this: > > fe=:13 :0 > '0:';<'@:';<((0;0){::y);<(,'"');<((,'0');1{::y);<((,'0');_) > ) > > (And then look at the definition of fe using linear representation.) > > Oh, but that's cheating! > > Um... why? > > It's not, not really. You learn from whatever interests you. > > That said, it *can* be an interesting exercise to construct sensibly > named concepts for building that kind of data structure. > > But maybe it's also easy enough to use J's parser and not bother with > tacit for this kind of exercise? > > Thanks, > > -- > Raul > > > On Sun, Feb 1, 2015 at 3:09 PM, Jose Mario Quintana > <[email protected]> wrote: > > " > > The agenda trick doesn't quite solve the problem though due to train > > formation rules: > > " > > > > Actually, when evaluating atomic representations, gerunds, etc. whatever > > one can accomplish using train (`:6) one can accomplish it using agenda > > (@.) as well (and vice versa). > > > > JVERSION > > Installer: j602a_win.exe > > Engine: j701/2011-01-10/11:25 > > Library: 6.02.023 > > > > ( agenda=. Cloak <'@.' ) NB. @. verbalized > > ,^:(0:`@.) > > > > u=. agenda&0 1@:({.@:(0&({::)) ; an@:>@:{:) f. > > u (+:`*:;i.5) > > 0 2 4 6 8 > > > > Alternatively, > > > > caravan=. agenda&0@:< > > > > u=. caravan@:({.@:(0&({::)) ; an@:>@:{:) f. > > u (+:`*:;i.5) > > 0 2 4 6 8 > > > > I find train more intuitive but agenda more suitable for heavy duty. > > > > > > On Fri, Jan 30, 2015 at 9:30 AM, Joe Bogner <[email protected]> wrote: > > > >> I hear a faint whisper calling me to this dark side... > >> > >> I have seen these posts[1] when I had just started using J and didn't > >> understand them. I went down the rabbit hole for a few hours this > >> morning > >> > >> The first post in the list was particularly enlightening > >> > >> NB. was gfy in Dan's post > >> an=. <@:((,'0') ,&< ]) > >> > >> NB. 2 + i.5 > >> ((an 2);'+';(an i. 5);'*:') @. (0 1 2) > >> 2 3 4 5 6 > >> > >> NB. Let's square everything > >> ((an 2);'+';(an i. 5);'*:') @. (3 0 1 2) > >> 4 9 16 25 36 > >> > >> NB. You can even see syntax errors, which can help debugging > >> ((an 2);'+';(an i. 5);'*:') @. (0 1 1 1) > >> |syntax error > >> | 2+++ > >> > >> Let's get some more syntax errors: > >> > >> ((an 2);'+';(an i. 5);'*:') @. (3#(3 0 1 2)) > >> |syntax error > >> | *:*:*:2 2 2+++0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 > >> > >> > >> NB. +: +: +: +: (2+i.5) > >> ((an 2);'+';(an i. 5);'+:') @. ((4#3),(0 1 2)) > >> 32 48 64 80 96 > >> > >> > >> NB. adverbs too > >> ('+';'/';(an i.5)) @. (0 1 2) > >> 10 > >> > >> add1=.1&+ > >> ((ar 'add1');(an (2 4 6))) @. (0 1) > >> 3 5 7 > >> > >> And then coming back around to my original question: > >> > >> ((ar 'add1');'+:';(an (2 4 6))) @. (0 1 0 2) > >> 7 11 15 > >> > >> versus this monstrosity (beware of linebreaks) > >> gapply=:([: >@:}. (([: }. >&{.) ; >@:{.@:>@:{. 128!:2 > >> >@:}.)^:({.@:$@:>@:{.)) > >> > >> gapply ('1&+';'+:';'1&+');(2 4 6) > >> 7 11 15 > >> > >> The agenda trick doesn't quite solve the problem though due to train > >> formation rules: > >> > >> gapply ('1&+';'+:';'1&+';'1&+');(2 4 6) > >> 8 12 16 > >> > >> ((ar 'add1');'+:';(an (2 4 6))) @. (0 1 0 0 2) > >> 9 13 17 > >> > >> You train verb worked well though as an alternative > >> > >> Thank you! > >> > >> [1] - > >> http://www.jsoftware.com/pipermail/programming/2013-March/031883.html > >> [2] - > >> http://www.jsoftware.com/pipermail/programming/2013-January/031236.html > >> > >> On Thu, Jan 29, 2015 at 5:55 PM, Jose Mario Quintana > >> <[email protected]> wrote: > >> > "Is it possible to define f tacitly?" > >> > > >> > J tacit programming is Turing complete; thus, any verb can be defined > >> > tacitly. It can be difficult sometimes but this case is easy... If > one > >> is > >> > prepared to venture to the dark side. > >> > > >> > > >> > an=. <@:((,'0') ,&< ]) > >> > > >> > NB. Dark side of the force... > >> > > >> > Cloak=. ((5!:1)@:<'Cloak')Cloak=. (0:`)(,^:) > >> > ( train=. (Cloak <'`:')&6 ) NB. `:6 verbalized > >> > ,^:(0:``:)&6 > >> > > >> > v=. train@:({.@:(0&({::)) ; an@:>@:{:) f. > >> > > >> > > >> > v (+:`*:;i.5) > >> > 0 2 4 6 8 > >> > > >> > > >> > On Thu, Jan 29, 2015 at 1:20 PM, Joe Bogner <[email protected]> > wrote: > >> > > >> >> Is it possible to define f tacitly? > >> >> > >> >> f=: 3 : '({.@:>@:{.y)`:0 (>@:}.y)' > >> >> f (+:`*:;i.5) > >> >> > >> >> 0 2 4 6 8 > >> >> > >> >> It's meant to take the first gerund from a box that contains a list > of > >> >> gerunds and data to operate on > >> >> > >> >> It's an odd circumstance that needed it. I could probably rework the > >> >> logic but now I'm curious if it can be done > >> >> > >> >> Some things I tried: > >> >> > >> >> a=:(+:`*:;i.5) > >> >> > >> >> f1=:{.@:>@:{. > >> >> f1 a > >> >> ┌──┐ > >> >> │+:│ > >> >> └──┘ > >> >> > >> >> f2=:>@:}. > >> >> f2 a > >> >> 0 1 2 3 4 > >> >> > >> >> > >> >> Tried various version of combining f1 and f2 to no avail > >> >> > >> >> This works: > >> >> > >> >> g`:0 f2 a [ g=. f1 a > >> >> 0 2 4 6 8 > >> >> > >> >> I'm thinking there might be a way to do it without the assignment? > >> >> > ---------------------------------------------------------------------- > >> >> 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 > >> > > ---------------------------------------------------------------------- > > 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
