<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>The Vose Way: Tag rulang</title>
    <link>http://www.chuckvose.com/articles/tag/rulang</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A Blog about Butter, Cheese, and Ruby on Rails</description>
    <item>
      <title>Concurrent code in Ruby 1.8.6 through inlining</title>
      <description>&lt;p&gt;&lt;strong&gt;Slight typo in the code fixed: 2008-01-08&lt;/strong&gt;&lt;/p&gt;


	&lt;p&gt;Toshiyuki and I have released a new gem called rbridge which allows us to execute functional, side-effect free, concurrent code directly in Ruby regardless of the version by using Erlang as a processor. This includes using the Mnesia distributed database and &lt;span class="caps"&gt;ETS&lt;/span&gt;/DETS.&lt;/p&gt;


	&lt;p&gt;To try it out please follow these steps:&lt;/p&gt;


	&lt;p&gt;1. Download Erlang for your os. Windows has binaries and &lt;span class="caps"&gt;OS X&lt;/span&gt; can be configured with `./configure&amp;#8212;prefix=/opt/local` to make MacParts happy. I haven&amp;#8217;t yet tried it with Linux but the default configure options should be okay.&lt;/p&gt;


	&lt;p&gt;2. Download the rbridge gem. `sudo gem install rbridge`&lt;/p&gt;


	&lt;p&gt;3. Start the rulang server in Erlang on port 9900. Change dir to the gem directory which is usually /usr/local/lib/ruby/gems/1.8/gems/rbridge-0.1/lib and run &lt;strong&gt;sudo erlc rulang.erl&lt;/strong&gt;. Enter the Erlang shell by typing &lt;strong&gt;erl&lt;/strong&gt;. Finally, start the server with &lt;strong&gt;rulang:start_server(9900).&lt;/strong&gt; (There&amp;#8217;s a dot at the end of the command).&lt;/p&gt;


	&lt;p&gt;4. Require rubygems and rbridge in your code and create a new connection to the rulang server. This is the simplest bit of inline code I can think of but there is a lot more we can do: asynchronous access and ruby-style syntax specifically.&lt;/p&gt;


&lt;pre&gt;
require 'rubygems'
require 'rbridge'

@r = RBridge.new(nil, 'localhost', 9900)

puts @r.erl('10*10.')
&lt;/pre&gt;

	&lt;p&gt;To read more check out the documentation on &lt;a href="http://ruby-mnesia.rubyforge.org"&gt;ruby-mnesia.rubyforge.org&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;&lt;strong&gt;Aside:&lt;/strong&gt; Toshiyuki Hirooka found me. Thank you to everyone that helped search and offered to translate for us. I&amp;#8217;m constantly impressed by the support from the Ruby community.&lt;/p&gt;</description>
      <pubDate>Mon, 07 Jan 2008 13:11:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:dd7dc46a-8bfa-4828-bcc9-2136ee24bd1b</guid>
      <author>vosechu@create-on.com (Chuck Vose)</author>
      <link>http://www.chuckvose.com/articles/2008/01/07/concurrent-code-in-ruby-1-8-6-through-inlining</link>
      <category>Ruby</category>
      <category>Erlang</category>
      <category>Ruby</category>
      <category>Erlang</category>
      <category>rbridge</category>
      <category>rulang</category>
      <category>gems</category>
    </item>
    <item>
      <title>rbridge 0.1 Released</title>
      <description>&lt;by Chuck Vose (adapted from Toshi Hirooka's RulangBridge)&gt;
&lt;ruby-mnesia.rubyforge.org (originally http://code.google.com/p/rulangbridge/)&gt;

	&lt;h2&gt;&lt;span class="caps"&gt;FEATURES&lt;/span&gt;:&lt;/h2&gt;


	&lt;p&gt;Allows use of Erlang code within Ruby&lt;/p&gt;


	&lt;h2&gt;Changes:&lt;/h2&gt;


	&lt;p&gt;v0.1 / 2008-01-04 (vosechu)&lt;/p&gt;


	&lt;p&gt;1 major enhancement&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Allows many-lined Erlang commands when using the Erlang class for direct
  access.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;3 minor enhancements&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Revised error checking to allow custom resolution&lt;/li&gt;
		&lt;li&gt;stop_server/0 now shuts down any servers running in an erl shell&lt;/li&gt;
		&lt;li&gt;created tests to run with RSpec and autotest (erl server must be running 
  on port 9900).&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;3 other changes&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Forked onto rubyforge complete with rdocs, gem, etc.&lt;/li&gt;
		&lt;li&gt;Translated some comments into english as well as the &lt;span class="caps"&gt;README&lt;/span&gt;&lt;/li&gt;
		&lt;li&gt;Packaged explicitly with gpl documentation&lt;/li&gt;
	&lt;/ul&gt;</description>
      <pubDate>Fri, 04 Jan 2008 19:54:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:ab0f9ea2-e2fd-4b28-b073-6e4d661aa946</guid>
      <author>vosechu@create-on.com (Chuck Vose)</author>
      <link>http://www.chuckvose.com/articles/2008/01/04/ann-rbridge-0-1-released</link>
      <category>Ruby</category>
      <category>Mnesia</category>
      <category>Erlang</category>
      <category>Ruby</category>
      <category>Erlang</category>
      <category>rulang</category>
      <category>bridge</category>
    </item>
    <item>
      <title>Complex commands with Rulang</title>
      <description>&lt;p&gt;Rulang was giving me a lot of trouble with regards to multi-line commands and complex commands in general. After hacking on it for a while I&amp;#8217;ve developed a patch that will allow ruby code such as the following:&lt;/p&gt;


&lt;pre&gt;
require 'rulang'

@mnesia = RulangBridge::Erlang.new("localhost", 9900)

def find
  @mnesia.eval(&amp;lt;&amp;lt;-EOF
    QH = qlc:q([X || X &amp;lt;- mnesia:table(shop)]),
    F = fun() -&amp;gt; qlc:eval(QH) end,
    {atomic, Val} = mnesia:transaction(F),
    Val.
  EOF
  )
end

puts find
&lt;/pre&gt;

	&lt;p&gt;&lt;span class="caps"&gt;PATCH&lt;/span&gt;&lt;/p&gt;


&lt;pre&gt;
diff -u Desktop/rulangbridge/rulang.erl Current Schoolwork/Project/mnesia/rulang_test/rulang.erl
--- Desktop/rulangbridge/rulang.erl     2007-05-17 20:25:50.000000000 -0700
+++ Current Schoolwork/Project/mnesia/rulang_test/rulang.erl    2008-01-03 10:12:05.000000000 -0800
@@ -30,11 +30,15 @@
 handle_connection(Socket) -&amp;gt;
-       Reason = (catch communication(Socket)),
-       gen_tcp:send(Socket, io_lib:format("Error: ~w~n", [Reason])),
+       try communication(Socket)
+  catch
+    error:Reason -&amp;gt;
+         {gen_tcp:send(Socket, io_lib:format("Error: ~p~n", [Reason]))}
+  end,
        ok = gen_tcp:close(Socket).

+% Try to evaluate the code submitted throwing an exception if the evaluation
+% doesn't work. Return the code submitted.
 communication(Socket) -&amp;gt;
        {ok, Binary} = gen_tcp:recv(Socket, 0),
        {ok, Result} = eval(binary_to_list(Binary)),
@@ -43,9 +47,9 @@

 eval(Expression) -&amp;gt;
-       {ok, Scanned, _} = erl_scan:string(Expression),
-       {ok, [Parsed]} = erl_parse:parse_exprs(Scanned),
-       {value, Result, _} = erl_eval:expr(Parsed, []),
+       {done, {ok, Scanned, _}, _} = erl_scan:tokens([], Expression, 0),
+       {ok, Parsed} = erl_parse:parse_exprs(Scanned),
+       {value, Result, _} = erl_eval:exprs(Parsed, []),
        {ok, Result}.

diff -u Desktop/rulangbridge/rulang.rb Current Schoolwork/Project/mnesia/rulang_test/rulang.rb
--- Desktop/rulangbridge/rulang.rb      2007-05-24 10:42:22.000000000 -0700
+++ Current Schoolwork/Project/mnesia/rulang_test/rulang.rb     2008-01-03 10:02:19.000000000 -0800
@@ -79,7 +79,7 @@
                def eval(command)
                        socket = TCPSocket.new(@host, @port)
                        socket.write(command)
-                       socket.gets # ...?
+                       socket.read # ...?
                end
&lt;/pre&gt;</description>
      <pubDate>Thu, 03 Jan 2008 12:17:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:effba11d-9820-471e-8e22-476292ddacae</guid>
      <author>vosechu@create-on.com (Chuck Vose)</author>
      <link>http://www.chuckvose.com/articles/2008/01/03/complex-commands-with-rulang</link>
      <category>Ruby</category>
      <category>Mnesia</category>
      <category>Erlang</category>
      <category>Ruby</category>
      <category>Erlang</category>
      <category>Mnesia</category>
      <category>rulang</category>
    </item>
  </channel>
</rss>
