{"id":417,"date":"2007-05-13T21:39:26","date_gmt":"2007-05-13T21:39:26","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/05\/13\/process-declarations-in-pica\/"},"modified":"2014-06-07T15:15:41","modified_gmt":"2014-06-07T19:15:41","slug":"process-declarations-in-pica","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/05\/13\/process-declarations-in-pica\/","title":{"rendered":"Process Declarations in Pica"},"content":{"rendered":"<p> Sorry for the slow pace of things around here lately; life interferes sometimes. I&#8217;ve mentioned my fathers illness before; things took a drastic change for the worse a week ago, which made things more than a little bit crazy. Of course, life wouldn&#8217;t be life in things happened one at a time; so naturally, my asthma picked now to act up as well, so I&#8217;ve been coughing my lungs out. It&#8217;s been a fun week, really.<\/p>\n<p> Anyway, I&#8217;ve been wanting to look a bit more at Pica. I&#8217;ve been thinking about how a named process definition looks, and what it does. The type part of a definition is relatively straightforward: a process is defined by a set of externally visible channels; each channel is defined by a type. In a named definition, there are two types of channels to think about. One is a set of channels supplied to the process when it&#8217;s created; the other is a set of channels created by the process, but which are &#8216;exported&#8217;: that is, made visible to other processes. The type of a process is a tuple of all of the channels which the process exports the outside world.<\/p>\n<p><!--more--><\/p>\n<p> Of course, there&#8217;s always a hitch, right? Nothing is ever simple. One of the defining characteristics of the &pi;-calculus is <em>mobility<\/em>: channels can be moved around. A process can send a channel to another process, and no longer retain any ability to use it; or it can receive a channel via a message from some other process, effectively adding an externally visible channel; and finally, it can create a new channel via &#8220;new&#8221;, and then send that channel via a message to another process, effectively adding a new externally visible channel.<\/p>\n<p> For the purposes of <em>declaring<\/em> a process and its channels, we&#8217;ll adopt the following rules:<\/p>\n<ol>\n<li> A process type declares a set of <em>fundamental<\/em> channels for the process. Identifiers for a processes fundamental channels are treated as being immutable variables associated with a process instance.<\/li>\n<li> A process may have more channels associated with it than its fundamental<br \/>\nchannels &#8211; but those channels do not affect its <em>static<\/em> type.<\/li>\n<\/ol>\n<p> The basic syntax of processes is the following pattern:<\/p>\n<pre>\n<b>proc<\/b> Name[pchannels...] <b>shows<\/b> [echannels...] <b>does<\/b>\nprocess-body-stuff <b>end<\/b>\n<\/pre>\n<p> where:<\/p>\n<ul>\n<li> <em>pchannels<\/em> is a set of <em>fundamental<\/em> channels associated with the process, and which are supplied to the process as parameters when a process instance is created; and<\/li>\n<li> <em>echannels<\/em> is a set of <em>fundamental<\/em> channels associated with the process, and which are created by an implicit &#8220;new&#8221; when a process instance is created.<\/li>\n<\/ul>\n<p> So, for example, let&#8217;s bring back the old storage cell example from an earlier post. We wrote that in &pi;-calculus syntax as:<\/p>\n<pre>\nNewCell[creator,initval]&equiv;new(read,write).{Cell[read,write,initval]\n| !creator(read,write) }\nCell[read,write,val]&equiv;{!read(val).Cell[read,write,val]\n+ ?write(v).Cell[read,write,v]}\n<\/pre>\n<p> In Pica syntax, that would be:<\/p>\n<pre>\nproc Cell[init:Val] shows [read:Val,write:Val] does\n   !read(init).Cell[init]\n|| ?write(v).Cell[v]\nend\n<\/pre>\n<p> It looks a lot simpler than the &pi;-calculus version, but the differences are pretty much all syntactic sugar. One of the syntax tricks that I&#8217;ve  used for the Pica version is creating a syntactic distinction between &#8220;invoking&#8221; a process definition, and instantiating a process. In the &pi;-calculus version, we didn&#8217;t have that distinction. The split between &#8220;NewCell&#8221; and &#8220;Cell&#8221; in the &pi;-calculus version, and the existence of &#8220;read&#8221; and &#8220;write&#8221; as parameters of &#8220;Cell&#8221; are all artifacts of that &#8211; we needed to explicitly separate the process invocation that would <em>create<\/em> a new cell. For Pica, when we just refer to a process by name, we&#8217;ll treat that as an in-place invocation of the named processes <em>behavior<\/em> in the current process. So recursively invoking &#8220;Cell&#8221; inside of &#8220;Cell&#8221; just continues &#8220;Cell&#8221;, re-using its exported channels. So just invoking &#8220;Cell&#8221; won&#8217;t create new copies of its fundamental exported channels. To really create a new process with new channels, you&#8217;d need to invoke it via &#8220;<code>spawn Cell[v]<\/code>&#8220;.<\/p>\n<p> Creating this distinction does, of course, introduce some trouble. Since new channels aren&#8217;t created unless you do a spawn, what does the following mean?<\/p>\n<pre>\nproc A[] shows [x:X,y:Y] does\n  <em>something<\/em>.B[]\nend\n\nproc B[] shows [a:X,b:X] does\n  <em>something<\/em>\nend\n<\/pre>\n<p> When &#8220;A&#8221; invokes the behavior of &#8220;B&#8221;, what&#8217;s the value of the &#8220;a&#8221; channel of B? Or the &#8220;b&#8221; channel of B? We need some more syntax to allow us to say how to assign name bindings of fundamental channels when we invoke a processes behavior without spawning it. The easiest part of that is that we&#8217;ll just say that if &#8220;A&#8221; invokes &#8220;B&#8221;, and B has a fundamental channel which matches a fundamental channel of &#8220;A&#8221; in both name and type, the matches channels will be unified. For other channels, we&#8217;ll steal some syntax from the reduction rules:<\/p>\n<pre>\nproc A[] shows [x:X,y:Y] does\n  <em>something<\/em>.B[][x\/a,y\/b]\nend\n\nproc B[] shows [a:X,b:X] does\n  <em>something<\/em>\nend\n<\/pre>\n<p> So when we invoke a process as a behavior, if its channel names don&#8217;t match, then we can add a second set of &#8220;[]&#8221;s which specify how to match the names.<\/p>\n<p> One last thing for today. Suppose we have an instantiated process P, with visible channels [a:X,b:Y]. To reference process P&#8217;s channel &#8220;a&#8221;, you&#8217;d use the syntax &#8220;P::a&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sorry for the slow pace of things around here lately; life interferes sometimes. I&#8217;ve mentioned my fathers illness before; things took a drastic change for the worse a week ago, which made things more than a little bit crazy. Of course, life wouldn&#8217;t be life in things happened one at a time; so naturally, my [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[50],"tags":[],"class_list":["post-417","post","type-post","status-publish","format-standard","hentry","category-pi-calculus"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-6J","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/comments?post=417"}],"version-history":[{"count":2,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/417\/revisions"}],"predecessor-version":[{"id":2991,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/417\/revisions\/2991"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=417"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}