[Jprogramming] Multiple Assignments
Raul Miller
rauldmiller at gmail.com
Sun Aug 10 14:27:31 UTC 2014
Here's another multiple assignment example:
poem=: ;:;._2]0 :0
desert morning
a coyote licks ice
on the tumbleweed
)
poem
┌──────┬───────┬──────────┬───┐
│desert│morning│ │ │
├──────┼───────┼──────────┼───┤
│a │coyote │licks │ice│
├──────┼───────┼──────────┼───┤
│on │the │tumbleweed│ │
└──────┴───────┴──────────┴───┘
'a b c'=: poem
a
desert
morning
b
a
coyote
licks
ice
c
on
the
tumbleweed
Thanks,
--
Raul
P.S. poem borrowed from http://tinywords.com/2010/02/16/396/
On Sun, Aug 10, 2014 at 9:31 AM, Henry Rich <HenryHRich at nc.rr.com> wrote:
> I recommend reading about multiple assignment in NuVoc.
>
> http://www.jsoftware.com/jwiki/Vocabulary/Assignment
>
> Multiple assignment can assign different values, as Raul points out. It
> also removes one level of boxing:
>
> 'a b' =: <5
> a
> 5
> b
> 5
> a =: b =: <5
> a
> +-+
> |5|
> +-+
> b
> +-+
> |5|
> +-+
>
> Henry Rich
>
>
> On 8/10/2014 12:50 AM, Jon Hough wrote:
>
>> A Quick Question:
>> Is there any difference between:
>> ' var1 var2' =: 10
>>
>> and
>> var1 =: var2 =: 10
>> ?
>> JforC breifly mentions the handy multiple assignment (the former, above)
>> http://www.jsoftware.com/help/jforc/more_verbs_for_boxes.htm
>> but doesn't mention the two are equivalent. From my brief experimenting
>> it seems they are. I'm guessing for a long list of variables the former is
>> neater.
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
More information about the Programming
mailing list