I figured out one notGerund adverb, and an interesting implementation for if
else
ar=: [: < (,'0')"_ ; ]
ar2 =: 1 : '5!:1 <''u'''
notGerund =: 1 : 0
if. 1= L. u ar2 do. 1 return. end.
(((( < ,'0' )-:{.) *. 2=#) > ar u)
)
if =: 2 : 'if. u notGerund do. [`(u"_)@.(v"0) else. u@.(v"0) end.'
else =: 2 : '(u"_)`(v"_)'
0 else -: if (0>]) else +: if (0<]) i:5
_2.5 _2 _1.5 _1 _0.5 0 2 4 6 8 10
allows infinite extensions of ifs to the left, and mixed noun and verb results.
Also allows if without an else:
+: if (0<]) i:5
_5 _4 _3 _2 _1 0 2 4 6 8 10
-:`+: if (0<]) i:5
_2.5 _2 _1.5 _1 _0.5 0 2 4 6 8 10
-: else +: if (0<]) i:5
_2.5 _2 _1.5 _1 _0.5 0 2 4 6 8 10
-: else 3 if (0<]) i:5
_2.5 _2 _1.5 _1 _0.5 0 3 3 3 3 3
2 else ] if (0<]) i:5
2 2 2 2 2 2 1 2 3 4 5
----- Original Message -----
From: Pascal Jasmin <[email protected]>
To: "[email protected]" <[email protected]>
Cc:
Sent: Tuesday, February 4, 2014 12:15:54 PM
Subject: Re: [Jprogramming] 'if' and 'else' operators
the :. trick from Michal is cute.
Here is how I would like to be able to call the code (note this produces
incorrect results):
if =: 2 : '((u"_) :. ])^:([: -. [: +: [: -. v)"0'
else =: 2 : '(u"_):.(v"_)'
3 if (0<]) i:5
_5 _4 _3 _2 _1 0 3 3 3 3 3
+: else 3 if (0<]) i:5
_5 _4 _3 _2 _1 0 2 4 6 8 10
0 else -: if (0>]) else +: if (0<]) i:5
_5 _4 _3 _2 _1 0 1 2 3 4 5
What I need that I can't seem to write is an adverb isGerund, that returns 0 or
1 depending on whether m or u (the tricky part is handling both without error.
notGerund =: 1 : '(((( < ": 1 $ 0 )-:{.) *. 2=#) > ar m)'
3 notGerund
1
+`- notGerund
0
notGerundu =: 1 : '(((( < ": 1 $ 0 )-:{.) *. 2=#) > ar u 0)' NB. this
variation is needed if u is verb.
3: notGerundu
1
I would like to have a single adverb that can handle both m and u (noun/gerund
and verb) parameters.
----- Original Message -----
From: Raul Miller <[email protected]>
To: Programming forum <[email protected]>
Cc:
Sent: Tuesday, February 4, 2014 9:43:18 AM
Subject: Re: [Jprogramming] 'if' and 'else' operators
if=: 2 :0
u"_`(v"_)
)
else=: 2 :0
v"_`(0{m)@.((1{m)`:6)
)
('O' if (=0:) else ('<' if (<0:) else '>'))"0 i:5
<<<<<O>>>>>
Do you also want to see an implementation for your alternate proposal?
Thanks,
--
Raul
On Tue, Feb 4, 2014 at 3:48 AM, Michal Wallace <[email protected]> wrote:
> ('O' if (=0:) else ('<' if (<0:) else '>'))"0 i:5
> <<<<<O>>>>>
>
> There are nicer ways to make this output,
> but how would you code 'if' and 'else' above?
>
> Or... 'if'/'then'/'else' below, if you prefer?
>
> a =: assert
> a 4 1 0 2 4 -: if (<0:) then (*: else +:) i:2
> a 4 1 0 2 4 -: (if (<0:) then (*: else +:)) i:2
> a (if ] then (| else -.)) 1 1 0 0 1 0 1 0
> a if ] then (| else -.) 1 1 0 0 1 0 1 0
>
> My versions are here:
>
> https://github.com/tangentstorm/tangentlabs/blob/master/j/syntax.ijs
>
> Thoughts? :)
>
> -Michal
> ----------------------------------------------------------------------
> 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