I think that your *. approach should work, but I might look at using a version
of datatype with L: 0 and assert. to the pattern
datatype L: 0 (1;2;<('lit1';'lit2');<<11)
┌───────┬───────┬─────────────────────────────┐
│boolean│integer│┌─────────────────┬─────────┐│
│ │ ││┌───────┬───────┐│┌───────┐││
│ │ │││literal│literal│││integer│││
│ │ ││└───────┴───────┘│└───────┘││
│ │ │└─────────────────┴─────────┘│
└───────┴───────┴─────────────────────────────┘
datatype
3 : 0
n=. 1 2 4 8 16 32 64 128 1024 2048 4096 8192 16384 32768 65536 131072 262144
t=. '/boolean/literal/integer/floating/complex/boxed/extended/rational'
t=. t,'/sparse boolean/sparse literal/sparse integer/sparse floating'
t=. t,'/sparse complex/sparse boxed/symbol/unicode/unicode4'
(n i. 3!:0 y) pick <;._1 t
)
(0;2;<('well';'well');<<11465747) -:&(datatype L: 0 )
(1;2;<('lit1';'lit2');<<11)
1
(0;2.0;<('well';'well');<<11465747) -:&(datatype L: 0 )
(1;2;<('lit1';'lit2');<<11)
0
You might create a version of datatype that is not so concerned with the
differences between floats, integers and booleans. You also adjust the level of
L: to determine if the contents are boxed.
Cheers, bob
> On Sep 27, 2022, at 12:03, Pawel Jakubas <[email protected]> wrote:
>
> Dear J enthusiasts,
>
> Let's assume I want to make sure the following structure of the noun is
> delivered to function:
> ┌────┬────┬────────────────────┐
> │num1 │num2 │┌───────────┬──────┐│
> │ │ ││┌────┬────┐ │┌────┐││
> │ │ │││lit1 │lit2 │ ││num1 │││
> │ │ ││└────┴────┘ │└────┘││
> │ │ │└───────────┴──────┘│
> └────┴────┴────────────────────┘
> so the one that can be instantiated like for example
> (1;2;<('lit1';'lit2');<<11)
>
> How would you write a check for that, so something checking:
> (a) first box has number
> (b) second box has number
> (c) in third box there must be at least one box that could have either two
> literal boxes or one numeral box.
> (d) there must be three boxes described above.
>
> You would wrote just 4 checks and combine them with *. or approach this
> differently?
>
> Many thanks and cheers,
> Pawel
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm