< Back to IRCAM Forum

Sub-patch misunderstandings

Dear OMers,

I’m asking for your help again with a sub-patch issue. In the attached folder, there’s a recursive patch and two patches in which I use it. In 01_good_try, the patch works (it’s about obtaining a prime factorization; I know the factorize function is present, but in this case, I needed a different view of the list of lists resulting from factorize), while in 02_bad_try, the patch, with only some input values ​​(for example, multiples of 2 don’t cause problems), results in an error.
The only change I made to the recursive patch in patch #02 was to group some elements together, which evidently creates an error due to multiple evaluations (I imagine?). I’d like, if possible, an explanation on how to avoid such errors (because this isn’t the first time I’ve asked for help with similar problems, and I clearly have a soft spot for this topic).

Thank you for your time and best regards,

your Neo

00_prime_fact.omp (13.9 KB)
02_bad_try.omp (16.3 KB)
01_good_try.omp (2.0 KB)

Dear neo,

First of all, i don’t see what’s bad in the 02_bad_try, It stills output ((43))

But what’s bad, is that it is complicated.
Maybe if you first begin explaining what are you looking for. There are maybe simpler solutions to your problem.
K

Dear Maestro Haddad,

Thanks again for yet another quick reply.

My goal in this patch is to obtain a function that returns a list of prime factors that, when multiplied together, result in the value (a natural number) defined in the input.

There is the “factorize” function, but it groups each factor into a sublist, paired with the exponentiation value. So my goal is, for example, given the number 18, to obtain the list (2 3 3). This, I believe, happens correctly with patch 01, while in the second patch I get this error (attached screenshot).

In any case, after a short retry, I didn’t get any errors, but if I selected the internal patch (odd) contained in the internal patch of 02 and unencapsulated it, then evaluated the patch normally, then reencapsulated the objects in the odd subpatch, then the error reappears.

I hope I’ve been as clear as possible, and if I’m wrong, I apologize. I don’t want to waste anyone’s time.

Kind regards, and thank you so much for your help.

neo
Screenshot 2025-09-05 alle 14.50.08

If you need a recursive function you should keep the patch in green and not in red.
Next, concerning the above error, with what argument and which patch version (good/bad, etc…?) did you get this.
Please try to be as much specific as you can. For instance your “bad” patch has still argument 43 but the output points out that you used another value. Its hard in this case to follow up the bugs :slight_smile:

By the way your patch is very good!

Best
K

Dear Maestro Haddad,

I sincerely apologize for my lack of clarity. I hope I haven’t wasted your time by distracting you from your work.

Let me try to explain as best I can: the error photo attached to the previous comment refers to the “02_bad_try” patch.

Inserting any value into the “02_bad_try” patch actually yields the correct result (at least from my various attempts). If I open the internal patch (00_prime_fact) — located in 02_bad_try — and uncap the internal patch (named “odd”), then return to the outer layer of the 02_bad_try patch to re-evaluate it, I still get a correct result.

Now, if I go back into the internal patch (00_prime_fact) – present in 02_bad_try – and group into an internal patch all the elements that were previously part of the internal patch called “odd”, then, when I go back to the external level of the 02_bad_try patch to evaluate it again, I get the error I reported previously.

I hope I’ve articulated the issue better than before. I’m sorry to bother you so briefly. Please give priority to any other commitments.

Kind regards, and thanks again for all your help and clear instruction in this and the other comments.

neo

P.S.

Fearing that I am not being clear, I am attaching a short video, in the hope of making your work as easy as possible.

Best
neo

02_bad_try.mov.zip (3.8 MB)

Dear neo,

Since 00_prime_fact is a recursive patch, changing its contents on the fly is rather perilous. I would stick to the first version o f00_prime_fact (in blue mode) which is safer to use. If it works then keep the first version.

BEst
K

1 Like