From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: From state table to state diagram Date: Fri, 24 Sep 2010 11:00:48 +0100 Message-ID: <874odfea0f.fsf@stats.ox.ac.uk> References: <4af92c2e-de26-4149-bd68-06fd6a0503f0@email.android.com> <878w3vedfz.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from [140.186.70.92] (port=39290 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oz55X-0006Vd-3A for emacs-orgmode@gnu.org; Fri, 24 Sep 2010 06:01:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oz55Q-00005L-VC for emacs-orgmode@gnu.org; Fri, 24 Sep 2010 06:01:06 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:62914) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oz55Q-00004y-OV for emacs-orgmode@gnu.org; Fri, 24 Sep 2010 06:01:00 -0400 In-Reply-To: (Gary's message of "Thu, 23 Sep 2010 17:02:13 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: emacs-orgmode@garydjones.name Gary writes: > Sorry, I've been rather lax on this :( I got dragged onto other stuff, > went on training courses, and all sorts of other things. > > Eric Schulte wrote: >> Babel does support generating diagrams with graphviz via "dot" code >> blocks. Babel is also capable of converting Org-mode tables to list >> objects in a number of languages, so I'd recommend writing a table->dot >> script in your favorite language, and then using babel to handle the >> coordination and Org-mode integration. > > That's all very easy for you to say :)) > >> I'm happy to help in this regard, the first step would be something like >> the following example which assumes python is your preferred scripting >> language (as you can see I have no idea what your state table may look >> like)... > > Well, wikipedia suggests the following[1] (and goes into further detail > as well[2]) > | Current State -> | State | State | State | > | Input v | A | B | C | > |------------------+-------+-------+-------| > | x | B | ... | ... | > | y | ... | C | ... | > which basically says that when the machine is in State A and receives > 'x' then it transitions to State B, and when it receives a 'y' in State > B it transitions to State C. > >> #+results: state-table >> | 1 | 2 | >> | 3 | 4 | >> >> #+source: table-to-dot >> #+begin_src python :var table=state-table >> python code here > > Okay. What should this python code here do? :) I know, it converts a > table to dot-script, but are there any examples I could look at which > take a table as input and output something (anything), just so I can see > how the python code should expect its input? Hi Gary, The answer is that python receives that as [[1, 2], [3, 4]]. There are a few ways to arrive at that answer. For your table-to-dot script I suspect it is going to be easiest to use the ":results output" header argument, which means that the result will be the printed output of the python block (as opposed to...[1]). So using that, one way to see how python receives its input is: #+source: table-to-dot #+begin_src python :var table=state-table :results output print str(table) #+end_src #+results: table-to-dot : [[1, 2], [3, 4]] Another way is to place point in the code block and use C-c C-v C-v `org-babel-expand-src-block'. Alternatively, you might want to use a session to play around with the input data structure interactively. In that case, add ":session", and use either C-u C-c C-v C-z or C-u C-c C-v z to bring up the emacs python session with the input variable pre-loaded. Dan > >> #+end_src >> >> #+begin_src dot :var text=table-to-dot(table=state-table) >> graph{ >> $text >> } >> #+end_src >> >> Once this is working I think it could make a great addition to the >> library of babel [1] (a collection of generally useful code blocks). > > Sure :) > > [1] http://en.wikipedia.org/wiki/Finite-state_machine#Concepts_and_vocabulary > [2] http://en.wikipedia.org/wiki/State_transition_table > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode Footnotes: [1] As opposed to the default mode in which the result of the block is the value of the last statement, turned into an Org-mode table if it is a list/vector type object.