Re: [Jprogramming] repeat n function

2022-01-27 Thread Hauke Rehr
Thanks Julian, this is Good Advice™ My cloumsy answer was meant to say “that’s not the J way” without actually spelling that out. But maybe it didn’t come across. Sometimes the best answer to “how?” is just “don’t!” Am 27.01.22 um 15:44 schrieb Julian Fondren: J doesn't have lexical scope so

Re: [Jprogramming] repeat n function

2022-01-27 Thread Julian Fondren
J doesn't have lexical scope so you're cutting against the grain of the language to want internal definitions like this. Those internal verbs are also defined every single time the function is called. The entire APL family of languages have their own ways of achieving readability and

Re: [Jprogramming] repeat n function

2022-01-27 Thread 'Pascal Jasmin' via Programming
and the last expression as a "parameterized function" that is adverb instead of dyad 2 (,^:)~ 1 2 3 1 2 3 1 2 3 1 2 3 On Thursday, January 27, 2022, 09:11:22 a.m. EST, 'Pascal Jasmin' via Programming wrote: J has a repeat conjunction ^:    A repeat adverb that repeats n times is

Re: [Jprogramming] repeat n function

2022-01-27 Thread Hauke Rehr
Is something like this what you want? repeat =: 4 : 0 rshowx =. 'This is x inside repeat:',LF, ": x rshowy =. 'This is y inside repeat:',LF, ": y f =. [;@#{.@] d =. y rshowf =. 'These are x and y for f; and its result:',LF,,LF,.":x (;;f) d;d rshowx,LF,rshowy,LF,rshowf ) 3

Re: [Jprogramming] repeat n function

2022-01-27 Thread 'Pascal Jasmin' via Programming
J has a repeat conjunction ^:    A repeat adverb that repeats n times is (^:n) or to use x instead of n (^:[) this won't behave as your original function, but produces the square of x copies of y.  ie. each function call changes/expands y such that the next call is on the larger y 2 ,~@]^:[

[Jprogramming] repeat n function

2022-01-27 Thread Pawel Jakubas
I am wondering how to embed definition of `f` inside `repeat`. so I would call `x repeat d` and inside this function `x f (d;d)` would be called. On both levels, repeat and f, we have names x and y.And I wonder what are the techniques to (a) reuse them at both `repeat` and `f` level, (b) separate

Re: [Jprogramming] repeat n function

2022-01-27 Thread Henry Rich
1. To debug a sentence, use Dissect. 2. To print expressions during execution, a quick way is load'printf'  NB. just once per session qprintf'x ' qprintf'x $y ' The last character of the argument is the delimiter between expressions. Henry Rich On 1/27/2022 8:23 AM, Pawel Jakubas wrote:

Re: [Jprogramming] repeat n function

2022-01-27 Thread 'Pascal Jasmin' via Programming
'only x less than 10 is accepted' assert 0 |only x less than 10 is accepted: assert | 'only x less than 10 is accepted' assert 0 3 (] $~ [ * $@]) 1 2 3 1 2 3 1 2 3 1 2 3 13 'only x less than 10 accepted'"_`(] $~ [ * $@])@.(10 > [) 1 2 3 only x less than 10 accepted builtin assert

Re: [Jprogramming] repeat n function

2022-01-27 Thread Julian Fondren
You can box y, repeat it with dyadic #, and then raze the boxes: 3 ([: ; [#<@]) 'hi' hihihi 3 ([: ; [#<@]) 1 2 3 1 2 3 1 2 3 1 2 3 3 {{ ; x # wrote: > Dear J enthusiasts, > > I am defining `x repeat y` function, that is appending y to itself x times. > > And defined something like

Re: [Jprogramming] repeat n function

2022-01-27 Thread Hauke Rehr
One way to get the simple repeat function is this: ] d =: >: i.3 1 2 3 f =: [ ;@# {.@] 1 f d;d 1 2 3 2 f d;d 1 2 3 1 2 3 3 f d;d 1 2 3 1 2 3 1 2 3 If you don’t call f with d;d but simply with d, then you can just define f =: ;@# which I consider an answer to your question 3.

Re: [Jprogramming] repeat n function

2022-01-27 Thread Hauke Rehr
2. you could try echo 'this' and smoutput 'that' 3. look up the definition of dyadic # (and $) (or just try it) 4. I don’t know exactly which behavior you want could you give some example in- and output of the more general function you’re after? Am 27.01.22 um 14:23 schrieb Pawel Jakubas: Dear

[Jprogramming] repeat n function

2022-01-27 Thread Pawel Jakubas
Dear J enthusiasts, I am defining `x repeat y` function, that is appending y to itself x times. And defined something like below (on intention like that to ask a couple of questions). f=: 4 : 0 assert (x < 10) segment=.>0{y if. (x = 1) do. (>1{y) else. (x-1) f (segment;( (>1{y),segment) )