{"id":405,"date":"2007-05-01T21:45:55","date_gmt":"2007-05-01T21:45:55","guid":{"rendered":"http:\/\/scientopia.org\/blogs\/goodmath\/2007\/05\/01\/moving-on-calculus-and-common-programming-idioms\/"},"modified":"2014-06-07T15:18:23","modified_gmt":"2014-06-07T19:18:23","slug":"moving-on-calculus-and-common-programming-idioms","status":"publish","type":"post","link":"http:\/\/www.goodmath.org\/blog\/2007\/05\/01\/moving-on-calculus-and-common-programming-idioms\/","title":{"rendered":"Moving on: \u03c0-calculus and common programming idioms"},"content":{"rendered":"<p> Before diving off into real content, the name of my little &pi;-calculus monstrosity has been chosen. As several people recommended in the comments, I&#8217;m going to go with <em>Pica<\/em>.<\/p>\n<p> So, today, we&#8217;re going to take the dive, and start looking at some interesting semantics of the language. The goal of this is still to work on Pica&#8217;s type system: I want to work towards a first draft of what a process type will look like. But to figure out what a process type should look like, we need to think about how process abstractions will be defined and used in Pica, what control structures are going to look like. So that&#8217;s what I&#8217;m going to do in this post: ramble on a bit about what processes are really going to end up looking like. Just a warning: this post is definitely on the half-baked side &#8211; it&#8217;s much more of a train-of-thought\/brainstorming thing than the things I usually post. <\/p>\n<p><!--more--><\/p>\n<p> The overriding principle of Pica is making communication and synchronization <em>explicit<\/em>. After all, the basic problem that I&#8217;m hoping to address is the weakness of languages for dealing with the issues of distribution and concurrency, so those issues need to be brought up front and center. So the point of process typing is to allow us to express something about how a process is going to interact with the world around it in terms of communication.<\/p>\n<p> Obviously, since Pica is based on &pi;-calculus, the primary abstraction is going to be the process. Just about everything is ultimately going to reduce to process-based abstractions. What does this mean, in terms of some of the common programming language constructs?<\/p>\n<ul>\n<li> Procedure\/method\/function calls are <em>not<\/em> primitives. In almost every language that most of us are familiar with, the idea of the synchronous function call is a basic concept. But for Pica, it&#8217;s a derived abstraction. A function call with type (A&times;B)&rarr;C is going to become a process in Pica, which exports a channel of type (A&times;B&times;Channel[C]). To call the function, you&#8217;ll send a message to that exported channel, which will include the result channel. Instead of returning a result, the function will <em>send<\/em> the result to the final channel parameter. So function calls in Pica end up looking a lot like function calls in continuation passing style code in a functional language. This isn&#8217;t really changing anything about how function calls really work: normal function calls push the parameters plus a return address onto a stack. This is equivalent to that, expressed in terms of massages, and making the expected synchronization behavior around the call and return explicit. With calls expressed this way, we can still provide syntactic sugar to make it easy to do synchronous calls if we want to &#8211; but we can <em>also<\/em> make any call into an asynchronous operation, or separate the invoker of a call from the receiver of the result. <\/li>\n<li> Data types\/classes aren&#8217;t really primitive. Most modern languages have a concept of <em>object<\/em>, which is basically a chunk of data (the object state) with associated code for accessing and manipulating the data (the object methods). In Pica, an object is just a process. The object state is the process state; the object methods will be defined in terms of the messages that can be sent to the process.<\/li>\n<li> Basic computational primitives are relatively unaffected. Things like conditionals, comparisons, and arithmetic are just below the level where the message-passing semantics has a huge impact.<\/li>\n<li> Control structure have an interesting dual-nature in a language like Pica. There&#8217;s obviously a need for basic controls like conditionals, loops, etc., which exist below the level of message passing &#8211; but there&#8217;s also obviously a need for controls to interact with message passing. The way I&#8217;m going to work around that is by separating the low-level in-process controls from the higher level inter-process controls. <\/li>\n<\/ul>\n<p> That dual-level control structure is an interesting thing. On the low level, we want to be able to do things like simple conditionals and iteration without getting too involved in communication semantics. So we definitely want things like a basic &#8220;in\/then\/else&#8221; construct, and probably something like a &#8220;for&#8221; loop.<\/p>\n<p> And there&#8217;s <em>also<\/em> an analogue of the basic control structures at the process level. But they need to fit into the basic concept and patterns of the process and messaging system. There are two basic constructs we need to capture at the process level: conditionals, and iteration.<\/p>\n<p> What&#8217;s a conditional in terms of a process calculus like &pi;? Suppose I&#8217;ve got a process, which has a port where it can receive a message. A conditional is something that allows the process to take <em>different<\/em> actions depending on the contents of the message. The natural way to do that given the structure we&#8217;ve been building is to steal another idea from functional languages: <em>pattern matching<\/em>. So we&#8217;ll allow message receive clauses to specify a <em>pattern<\/em> for the values to be received: a message receive clause can only receive a message whose payload matches the clause&#8217;s pattern.<\/p>\n<p> Iteration is even easier. We&#8217;ve already seen the solution there: recursion, exactly the way that I demonstrated in some of the examples in earlier articles.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Before diving off into real content, the name of my little &pi;-calculus monstrosity has been chosen. As several people recommended in the comments, I&#8217;m going to go with Pica. So, today, we&#8217;re going to take the dive, and start looking at some interesting semantics of the language. The goal of this is still to work [&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-405","post","type-post","status-publish","format-standard","hentry","category-pi-calculus"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4lzZS-6x","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/405","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=405"}],"version-history":[{"count":2,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions"}],"predecessor-version":[{"id":2993,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/posts\/405\/revisions\/2993"}],"wp:attachment":[{"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/media?parent=405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/categories?post=405"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.goodmath.org\/blog\/wp-json\/wp\/v2\/tags?post=405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}