Jsoftware
High-Performance Development Platform

monadic amend with left argument

View: New views
7 Messages — Rating Filter:   Alert me  

monadic amend with left argument

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I want to use Item Amend (the monadic form of m} )  where the m selects the item of y to take the result from. i.e.
   (4 ?.@$ 2)} 'aaaa',:'bbbb'
abba

The same thing can be written as a verb using the gerund form (v1`v2)} y
   nextletter=: >:&.(a.&i.)
   myverb=: ($ ?.@$ 2:)`(] ,: nextletter)}
   myverb 'aaaa'
abba

And setting the probability of getting a 'b' to 0.2
   myverb=: (0.2 > $ ?.@$ 0:)`(] ,: nextletter)}
   myverb 'aaaa'
abaa

However I'm stuck on writing a tacit version of myverb where the probability of getting a 'b' is given as the left argument i.e.

   0.2 myverb 'aaaa'

My solution so far is to create an adverb:
   myverb=: 1 : '(m > $ ?.@$ 0:)`(] ,: nextletter)}'
   0.2 myverb 'aaaa'
abaa

Is there a non-adverbial solution?

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: monadic amend with left argument

by Raul Miller-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric <R.G.Sherlock@...> wrote:
> Is there a non-adverbial solution?

I did not bother with your nextletter logic because it
seemed too restrictive.  Other than that:

    0.2 ({::~&0 > 0 ?.@$~ #@{::~&(1;0))`(1 {:: ])}@; 'aaaa',:'bbbb'
abaa

(beware line wrap and mailer munging of atop).

FYI,

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: monadic amend with left argument

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Raul Miller
>
> On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric wrote:
> > Is there a non-adverbial solution?
>
> I did not bother with your nextletter logic because it
> seemed too restrictive.  Other than that:
>
>     0.2 ({::~&0 > 0 ?.@$~ #@{::~&(1;0))`(1 {:: ])}@; 'aaaa',:'bbbb'
> abaa

Thanks, yes that works.

Ric
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: tacit definition (was: monadic amend ...)

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric wrote:
>
> My solution so far is to create an adverb:
>   myverb=: 1 : '(m > $ ?.@$ 0:)`(] ,: nextletter)}'
>   0.2 myverb 'aaaa'
>abaa
>

Can the adverb definition above be called tacit?
Although it doesn't mention the x or y arguments, isn't "m" an explicit reference to an argument? (Also the definition uses the Explicit conjunction!!)

Is it possible to define a "pure" tacit version of the above adverb?
By "pure" I meanFor instance
  topowerA=: ^&              NB. "pure"
  topowerB=: 1 : '^&m'       NB. not "pure"?

Jose has recently shown a couple of versions of a conjunction "while", for example:
   u while v
0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))

Is it possible to define "while" without using the Explicit conjunction?

How would you describe "u" and "v" in the definition below?
while=: 2 : 0
0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))
)

Explicit references to the conjunction's verb arguments?


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: tacit definition (was: monadic amend ...)

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> From: Sherlock, Ric
>
> > On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric wrote:
> >
> > My solution so far is to create an adverb:
> >   myverb=: 1 : '(m > $ ?.@$ 0:)`(] ,: nextletter)}'
> >   0.2 myverb 'aaaa'
> >abaa
> >
[snip other questions]
> Is it possible to define a "pure" tacit version of the above adverb?
> By "pure" I meanFor instance
>   topowerA=: ^&              NB. "pure"
>   topowerB=: 1 : '^&m'       NB. not "pure"?

Inspired by an earlier forum post by Dan Bron, I worked out an answer to one of my questions:
http://www.jsoftware.com/pipermail/programming/2007-March/005425.html

Yes it can:
   myadverb=: &(> $ ?.@$ 0:)(`(] ,: nextletter))}
   0.2 myadverb 'aaaa'
abaa

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: tacit definition (was: monadic amend ...)

by Jose Mario Quintana :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Since it does not mention any arguments I would say that it is functional in the sense of functional programming but I would not call tacit a definition based on the explicit conjunction (as opposed to the “pure” tacit version that you found afterwards).
As far as I can see, J no longer provides the means to define conjunctions tacitly; however, one can replace a conjunction with an adverb operating on a gerund and we can now go a very long way defining tacit adverbs employing @.  with boxed agendas (there are certain limitations for reasons that I do not yet understand but that is another subject).  See http://www.jsoftware.com/pipermail/programming/2009-October/016726.html for a simple example of this workaround.
 




________________________________
From: "Sherlock, Ric" <R.G.Sherlock@...>
To: Programming forum <programming@...>
Sent: Wed, November 4, 2009 5:33:14 PM
Subject: Re: [Jprogramming] tacit definition (was: monadic amend ...)

> On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric wrote:
>
> My solution so far is to create an adverb:
>  myverb=: 1 : '(m > $ ?.@$ 0:)`(] ,: nextletter)}'
>  0.2 myverb 'aaaa'
>abaa
>

Can the adverb definition above be called tacit?
Although it doesn't mention the x or y arguments, isn't "m" an explicit reference to an argument? (Also the definition uses the Explicit conjunction!!)

Is it possible to define a "pure" tacit version of the above adverb?
By "pure" I meanFor instance
  topowerA=: ^&              NB. "pure"
  topowerB=: 1 : '^&m'      NB. not "pure"?

Jose has recently shown a couple of versions of a conjunction "while", for example:
  u while v
0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))

Is it possible to define "while" without using the Explicit conjunction?

How would you describe "u" and "v" in the definition below?
while=: 2 : 0
0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))
)

Explicit references to the conjunction's verb arguments?


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: tacit definition (was: monadic amend ...)

by Sherlock, Ric :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Jose,
That clarifies my own thoughts.

Regarding the tacit definition of conjunctions (and adverbs), I think I'm mainly curious, rather than really motivated to do this myself. Having said that, I think I'd have said the same thing about tacit definition of verbs if you'd asked me 2 years ago!

Ric

> From: Jose Mario Quintana
>
> Since it does not mention any arguments I would say that it is
> functional in the sense of functional programming but I would not call
> tacit a definition based on the explicit conjunction (as opposed to the
> “pure” tacit version that you found afterwards).
> As far as I can see, J no longer provides the means to define
> conjunctions tacitly; however, one can replace a conjunction with an
> adverb operating on a gerund and we can now go a very long way defining
> tacit adverbs employing @.  with boxed agendas (there are certain
> limitations for reasons that I do not yet understand but that is
> another subject).  See
> http://www.jsoftware.com/pipermail/programming/2009-
> October/016726.html for a simple example of this workaround.
>
> From: "Sherlock, Ric"
>
> > On Tue, Nov 3, 2009 at 7:08 PM, Sherlock, Ric wrote:
> >
> > My solution so far is to create an adverb:
> >  myverb=: 1 : '(m > $ ?.@$ 0:)`(] ,: nextletter)}'
> >  0.2 myverb 'aaaa'
> >abaa
> >
>
> Can the adverb definition above be called tacit?
> Although it doesn't mention the x or y arguments, isn't "m" an explicit
> reference to an argument? (Also the definition uses the Explicit
> conjunction!!)
>
> Is it possible to define a "pure" tacit version of the above adverb?
> By "pure" I meanFor instance
>   topowerA=: ^&              NB. "pure"
>   topowerB=: 1 : '^&m'      NB. not "pure"?
>
> Jose has recently shown a couple of versions of a conjunction "while",
> for example:
>   u while v
> 0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))
>
> Is it possible to define "while" without using the Explicit
> conjunction?
>
> How would you describe "u" and "v" in the definition below?
> while=: 2 : 0
> 0&({::)@:((((u (0 {:: ])) ; >:@(_1 {:: ]))^:(v (0 {:: ]))^:_) (0 ;~ ]))
> )
>
> Explicit references to the conjunction's verb arguments?

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm