Here are the kind of steps I take to understand an explanation like Raul's
f=:>: :[:
f A=:2 3 5 7
3 4 6 8
0 f A
|domain error: f
| 0 f A
g=:[:>:]
g A
3 4 6 8
0 g A
3 4 6 8
f
f
>: :[:
g
[: >: ]
5!:4 <'f'
-- >:
-- : -+- [:
5!:4 <'g'
-- [:
--+- >:
L- ]
These tools help to show the differences and they sometimes are helpful.
Linda
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Raul Miller
Sent: Monday, March 03, 2014 4:05 PM
To: Programming forum
Subject: Re: [Jprogramming] Dictionary data type
Monad=: :[:
RightId=: @]
example1=: >: Monad
example2=: >: RightId
example1 2 3 5 7
3 4 6 8
example2 2 3 5 7
3 4 6 8
0 example1 2 3 5 7
|domain error: example1
| 0 example1 2 3 5 7
0 example2 2 3 5 7
3 4 6 8
In other words, :[: produces a verb with an empty dyadic domain, while
@] produces a verb whose dyadic definition which ignores its left
argument and otherwise matches its monadic definition.
Thanks,
--
Raul
On Mon, Mar 3, 2014 at 3:19 PM, Pascal Jasmin <[email protected]>
wrote:
> interesting implementation.
>
> Could you please explain
>
> Monad =: :[:
>
>
> ?
> is it equivalent in use to @:] ?
>
>
> ----- Original Message -----
> From: David Lambert <[email protected]>
> To: programming <[email protected]>
> Cc:
> Sent: Monday, March 3, 2014 2:29:35 PM
> Subject: [Jprogramming] Dictionary data type
>
> The standard answer to "Does J have a dictionary data type?" seems to be
> "Use symbols."
> (Two other answers today recommend locales.) To which we ask, "How do
> we use symbols?" Given that I may have overlooked a lab, I'll show my
> effort. My goal is to maintain a database of probabilities written in a
> standard long form. "P(a)" is an invalid j pronoun.
> I solve this with string keys mapped to symbols. J implements symbols
> with red-black trees. They're quickly accessed. The symbol values are
> indexes into a boxed list of values. This is my dict.ijs file. The
> note at the end gives example use. I've fancifully called the wikipedia
> "Encyclopedia Galactica", so the example refers to that of
> http://en.wikipedia.org/wiki/Posterior_probability .
>
> coclass 'dict'
>
> NB. implement associative array
>
> VALUE =: 0$a:
>
> Monad =: :[:
> symbol =: s:^:('literal'-:datatype) Monad
>
> NB. index'`literal'
> index =: 6&(s: symbol) Monad
>
> NB. may fetch multiple items, returns boxed items
> get =: (index { ".@:('VALUE'"_)) Monad
>
> NB. may fetch multiple items, opens the boxes!
> openGet =: >@:get Monad
>
> put =: dyad define
> KEY =. symbol y
> if. 1 (= #) KEY do.
> V =. < x
> else.
> assert KEY =&# x
> V =. ;/ x
> end.
> I =. index KEY
> L =. >: >./ I
> if. L (> #) VALUE do. VALUE =: (+:L){.VALUE end.
> VALUE =: V I} VALUE
> KEY
> )
>
> cutSTRING =: #@:[ }.&.> , <;.1~ [ E. ,
> assert ((,0);4 5 6 7) -: 1 2 3 cutSTRING i.8
>
> embed =: >@:{.@:[ , ] , >@:{:@:[
> assert 'bats' -: 'bs'embed'at'
>
> Filter =: (#~`)(`:6)
> assert 0 1 2 -: <&3 Filter i.6
> assert 'SUPPER'-:<&(a.i.'a')Filter&.:(a.&i.)'SelectUPPERcase'
>
> getAllSymbols =: _6 s: [: i. s:~@:0:
>
> mp =: ($: |:@:+) :(+/ .*)
>
> NB. probability of pants, from law of total probability
>
> NB. y is the value for which to compute total probability
> NB. totalProbability =: openGet :: (verb define)
>
> NB. y is the value for which to compute total probability
> totalProbability =: verb define
> NB. returns P(y|CONDITIONi)P(CONDITIONi)
> assert 'P()' -: 1 2 _1 { y
> CONDITIONAL_GOAL =. '|'_1}y
> SYMBOLS =. getAllSymbols''
> LITERALS =. ": SYMBOLS
> A =. ('`'~:{.&>) Filter CONDITIONAL_GOAL cutSTRING LITERALS
> B =. ({.~i.&')')&.>A NB. B are boxes of conditionals.
> PYI =. openGet;('`P(';')')&embed&.>B
> PXYI =. openGet;(CONDITIONAL_GOAL;')')&embed&.>B
> assert PYI -:&# PXYI
> y put~ PYI mp PXYI
> openGet y
> )
>
> Note 'Encyclopedia Galactica: posterior probability'
> NB. wikipedia example on Tue Oct 22 15:18:33 EDT 2013
> load'dict.ijs'
> D=:conew'dict'
>
> NB. probability student is a boy, complementary girl
> ((,-.)0.6)put__D'`P(B)`P(G)'
>
> NB. probability wearing pants given sex
> 1 0.5 put__D'`P(P|B)`P(P|G)'
>
> NB. compute and store probability to observe pants.
> EMPTY [ totalProbability__D'`P(P)'
>
> NB. Finally, Bayes Law. Find P(G|P).
> %/ ; openGet__D'`P(P|G)`P(P)`P(G)'
> 0.25
> )
>
>> Date: Mon, 3 Mar 2014 09:06:00 -0600
>> From: Yike Lu<[email protected]>
>> To:[email protected]
>> Subject: Re: [Jprogramming] Sorry state of slow parsing of JSON in J
>> Message-ID:
>> <CAO=ap+cujrjnshftlhipnyzrk2mfrav_wak+-qzbl5vigee...@mail.gmail.com>
>> Content-Type: text/plain; charset=UTF-8
>>
>> A tangential but related question: does J have a dictionary data type?
>> Where can I read about it?
>>
>> Thanks.
> ----------------------------------------------------------------------
> 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