[PD] need help with recursive patching for arithmetic patch

Matt Barber brbrofsvl at gmail.com
Tue Nov 10 17:31:42 CET 2015


If it were me I would patch a parser that did several passes iteratively
instead of recursively:

1) Check for unbalanced parens, and count nesting depth
2) Pass all parts of the list unchanged, except those constitute a max
depth expression, which are evaluated and substituted
3) Repeat 2 until the entire expression is reduced

Order of operations is a bit harder, but you could do that with multiple
passes too.



On Mon, Nov 9, 2015 at 9:13 AM, Liam Goodacre <liamg_uw at hotmail.com> wrote:

> I'm trying to make a patch which can simplify arithmetic expressions given
> as a single message. I want to, for example, send it the message "( 2 + 5
> )" and get "7", or send it "foo ( 8 / 4 )" and get "foo 2". This much I
> have achieved, using [list-drip] and [route] to identify the data inside
> brackets, and [list-reduce] to perform the arithmetic. The difficulty I'm
> having is in getting it to work recursively, so that eg. "bar ( 5 - ( 3 - 2
> ) )" gives "bar 1". Ideally, the abstraction would be able to process any
> number of bracket-levels, just as a scientific calculator does.
>
> I know that programming recursively on PD is not for the faint hearted,
> and I feel pretty much out of my depth. If anyone can point me in the right
> direction, I will be most grateful. Alternatively, if it turns out to be
> too hard, I'll settle for what I've made already.
>
> I'm attaching the patch, although I think it's pretty far removed from
> what the solution will look like. Note that I'm using Zexy and list-abs
> here.
>
> _______________________________________________
> Pd-list at lists.iem.at mailing list
> UNSUBSCRIBE and account-management ->
> http://lists.puredata.info/listinfo/pd-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20151110/746dd91a/attachment.html>


More information about the Pd-list mailing list