[PD] Should message objects be able to pre-parse $0 into valid dollarzero?
grib at billgribble.com
Wed Sep 10 20:51:35 CEST 2014
On 09/10/2014 02:21 PM, Miller Puckette wrote:
> This leads to an interesting point - '$0' might recently have become more
> important than it was before because of the multiple-libpd-instances features
> in 0.46 - any libpd patch wanting to support multiple instances will need
> some $0-ish disambiguation.
Scope hygiene and namespace management was one of the main issues that
led me to start working on MFP . While my code base is totally
different from PD's, I think the approach I came up with for this works
pretty well and is at least a proof-of-concept that hints that working
this stuff out in PD will make for cleaner patches.
I don't think there's enough overlap in the implementation for a
detailed description to be useful, but the highlights are: The app knows
about lexical scopes. Every patch has at least one scope and possibly
more (nested scopes are possible, UI is a bit kludgy). Any time a name
is created (by naming an object in a patch, or by creating an [r]
object) it goes into a specific scope. Trying to resolve names, by
creating an [s] for example, searches in the local scope of the [s]
first, then works upward. There are always-available names ("patch",
"self", "app") which resolve to the patch, the object containing the
name reference, and the top-level program respectively. Names can
include explicit tree-walking to target an object in a scope that's not
a parent of the current scope (i.e. [s someotherpatch.scopename.name])
With this approach there's no need for $0 or anything like it. Names are
local to the object in which they were created. The whole thing is
still young, but I am finding that patches have a lot less name-mangling
and are a lot more readable to my programmer's eyes.
As a bonus, with clean scope semantics you can pretty easily create user
patches that have dynamic (per-instance) numbers of inlets and outlets,
with fairly arbitrary semantics about how the templating and cloning of
patch-pieces works. The trick is "hygienic scope cloning"... take all
the objects in a scope, copy them into a new scope within the patch.
This lets you use [s] and [r] within portions of a patch that need to be
cut-n-pasted to add more inlets/outlets, and have everything Just Work.
Last I looked, this was pretty hard to do in PD.
More information about the Pd-list