# M. primitive question

17 views

Apr 17, 2024, 11:53:01 PMApr 17
to fo...@jsoftware.com
Trying to use M. to memoize a simple function. The page seems to imply that the arguments must be atomic, and in the definition of atomic it mentions a single box is considered atomic. I experimeted with a single box:

t=:{{
y
}}M.

t < 1 2 3
|domain error in t, executing monad 0!:1
| t<1 2 3

Seems to not like the box but does fine w/o it. With the caveat on the M. wiki page I presume it is not memoizing an input array. Am I missing something?

Thanks
Pete

### LdBeth

Apr 18, 2024, 12:00:26 AMApr 18
to fo...@jsoftware.com
>>>>> In <5B64F652-B658-4C2E...@gmail.com>
On the same page, it says:

Oddities
1. If an argument to u M. is an atom, it must be numeric.

A box is not numeric. This renders M. only usable for numeric computations
that receives up to 2 inputs.

---
L:dBeth

Apr 18, 2024, 1:26:32 AMApr 18
to fo...@jsoftware.com
I interpreted that to mean that the box should contain numbers, but yours is the likely correct interpretation given the results. Kind of disappointing for an array language, but that is neither here or there, I’ll do the memoization manually. Thanks.
> To unsubscribe from this group and stop receiving emails from it, send an email to forum+un...@jsoftware.com.
>

### Devon McCormick

Apr 18, 2024, 3:04:50 AMApr 18
to fo...@jsoftware.com
These examples, from https://code.jsoftware.com/wiki/Essays/Memo, still seem to work OK and show the power of M. :
```comb0=: 4 : 0   NB. All size x combinations of i.y
if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x comb0&.<: y),1+x comb0 y-1 end.
)

combm=: 4 : 0 M.
if. (x>:y)+.0=x do. i.(x<:y),x else. (0,.x combm&.<: y),1+x combm y-1 end.
)

comb=: 4 : 0
k=. i.>:d=.y-x
z=. (d\$<i.0 0),<i.1 0
for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end.
; z
)```
`   (100) ts '10 comb0 20'0.457109 3.35573e7   (100) ts '10 combm 20'7.62e_7 1280   (100) ts '10 comb 20'0.0212303 4.98343e7`

--

Devon McCormick, CFA

Quantitative Consultant