[Jprogramming] monad vs. dyad
Geoff Canyon
geoffc at inspiredlogic.com
Tue Mar 20 16:15:47 HKT 2007
Thanks for the help!
0 is the obvious answer, but there are other numbers that meet this
criteria.
I modified your code like this:
f=:((1<])#@:~.@:(/:~@:":"0)@:((>:i.6)*]))+]
(f^:_) 1
And got my answer. This leaves me with the following questions:
1. So what _does_ =/ mean?
2. If it doesn't mean anything, is it possible for me (any user) to
define =/=:1&=#] ? (apparently not)
3. Is there a way to compose my two lines above into a single command?
4. To avoid all the @: above, should I be looking for ways to turn it
into forks and/or hooks?
I have to add: my brain hurts! (in a good way)
gc
On Mar 19, 2007, at 11:58 PM, Roger Hui wrote:
> Functions are usually composed with @ or @: ;
> juxtaposition works only if the desired composition
> is a hook or a fork. Thus instead of
> =/ /:~ each ": each <"0 (>:i.6)*]
> you need to say
> =/@:(/:~ each)@:(": each)@:(<"0)@:((>:i.6)*])
>
> The number of "each"es can be reduced as follows:
> =/@:(/:~@:": each)@:((>:i.6)*])
>
> =/ is not the right thing to do to compute
> "whether they are all the same". Instead, do
> 1&=@:#@:~.@:(/:~@:": each)@:((>:i.6)*])
>
> On the face of it, f y would be 1 only if y is 0
> and is 0 otherwise. Perhaps you mean something
> other than "whether they are all the same".
>
> f=: 1&=@:#@:~.@:(/:~@:": each)@:((>:i.6)*])
> f"0 i.20
> 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> I. f"0 i.2000
> 0
>
>
>
> ----- Original Message -----
> From: Geoff Canyon <geoffc at inspiredlogic.com>
> Date: Monday, March 19, 2007 11:31 pm
> Subject: [Jprogramming] monad vs. dyad
>
>> I'm trying to write a monadic function that will take a number,
>> create a list of that number times 1..6, with each number's
>> characters sorted, and return whether they are all the same. So f
>> 17
>> would look at the list 17 34 15 68 58 012 and return 0. Here's my
>> closest attempt so far:
>>
>> =/ /:~ each ": each <"0 (>:i.6)*]
>>
>> <"0 (>:i.6)*26 returns
>>
>> +--+--+--+---+---+---+
>> |26|52|78|104|130|156|
>> +--+--+--+---+---+---+
>>
>> But
>>
>> f=:<"0 (>:i.6)*]
>> f 26
>> 0 1 1 1 1 1
>>
>> That looks to me like < is being treated dyadically, and returning
>>
>> false, true, true, etc. What do I need to do to force it to box
>> instead?
>> =/ /:~ each ": each NB. seems to work, but is there a better way
>> than
>> two eaches?
>>
>> Finally, putting it all together:
>>
>> f=: =/ /:~ each ": each <"0 (>:i.6)*]
>> f 4
>> |domain error: f
>> | f 4
>>
>> Any suggestions?
>>
>> thanks,
>>
>> geoff
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list