Re: [Jprogramming] State machine add multiple words action

2023-01-16 Thread Raul Miller
The sequential machine is a very simple device. When it emits a word, there's a starting index and an ending index and it emits all of that subsequence. The emit vector mechanism is a minor adjustment to emit word -- it basically just changes the current ending index. It still includes the

[Jprogramming] State machine add multiple words action

2023-01-16 Thread Pawel Jakubas
Hi Raul, I am not giving up on learning multiple words action. I have seen the example you referenced and try to use it on example we processed. M=: (a.=LF)+2*a.e.'0123456789' S=: +.".>cutLF {{)n 1j0 0j0 2j1 NB. start here 1j0 3j0 2j1 NB. other 1j5 3j5 2j0 NB. digit 1j0 4j1 2j1 NB. LF

[Jprogramming] State machine add multiple words action

2023-01-13 Thread Pawel Jakubas
Oh, I see what I was missing. Column are character classes and rows are arbitrary states that are not the same as the classes depicted in columns. So I can have 10 states and 5 columns... Thanks a lot! Cheers, Pawel -- For

Re: [Jprogramming] State machine add multiple words action

2023-01-13 Thread Raul Miller
Here, I think we're talking about M=: (a.=LF)+2*a.e.'0123456789' S0=: +.".>cutLF {{)n 1j1 2j1 1j1 NB. start here 1j0 2j0 1j0 NB. non-newline 1j0 1j2 1j0 NB. newline }} The columns correspond to character classes defined in M: column 2 is numbers, column 1 is line feeds, column 0 is

[Jprogramming] State machine add multiple words action

2023-01-13 Thread Pawel Jakubas
When looking at S0 as it it is used with M where 0 is other characters, 1 is LF and 2 digits I would expect rows to follow this and you have comments that seems not the case. For example the third row in S0 is 1j0 1j2 1j0 NB. newline I would expect it to represent digit. No? Also, when we

Re: [Jprogramming] State machine add multiple words action

2023-01-13 Thread Raul Miller
In ijrd there's a constraint that j must be strictly less than i. So you might try (0;s0;m0;1 0 0 1) ;: test1 Note that this will fail if the right argument to ;: is empty. Was there anything else that you did not understand about my approach there? Thanks, -- Raul On Fri, Jan 13, 2023 at

[Jprogramming] State machine add multiple words action

2023-01-13 Thread Pawel Jakubas
Thanks Raul. I realized I do not understand your S0, how you come up with it. Shouldn't it be just 2 state machine? And if so why the following does not work? test1=: {{)n 1000ddd 2000 ab3000 1xxx 11 22 }} m0=: a.=LF s0=: +.".>cutLF {{)n 0j0 1j0NB. when r=0 and c=0 we

Re: [Jprogramming] State machine add multiple words action

2023-01-12 Thread Raul Miller
The fastest to find example here would be parsing of numbers in the original dictionary parsing example: https://www.jsoftware.com/help/dictionary/d332.htm Here, when parsing '1 2 3', each time a space is encountered, the word is "terminated" and the subsequent 4 actions extend the word. (And in

[Jprogramming] State machine add multiple words action

2023-01-12 Thread Pawel Jakubas
Thanks Raul for the solution! Wow! Could you please share some illustrative example of action code 4 and 5, especially useful in contrast to one word actions? Kindest regards, Pawel -- For information about J forums see

Re: [Jprogramming] State machine add multiple words action

2023-01-12 Thread Raul Miller
Action codes 4 and 5 aren't specifically what I think you would want in this context. What they allow you to do is tentatively emit a token and then return to that state to potentially extend the length of that token. In other words, action codes 4 (and 5) simply give you a longer word which

[Jprogramming] State machine add multiple words action

2023-01-12 Thread Pawel Jakubas
Dear J enthusiasts, I try to learn state machine parsing and try to use 4 or 5 action code in practice. Here is an example to be concrete. 1. So we have the file: $ cat test1.txt 1000ddd 2000 ab3000 1xxx 11 22 2. now I want to ideally have three boxes, one containing 1000, 2000,