Angel \”Java\” Lopez on Blog

October 17, 2013

RubySharp, Implementing Ruby In C# (2)

Filed under: C Sharp, Open Source Projects, Programming Languages, Ruby, RubySharp — ajlopez @ 7:11 pm

Previous Post
Next Post

I’m working on my Ruby implementation as interpreter written in C#

https://github.com/ajlopez/RubySharp

Today I would like to show that I have implemented many expressions that can be evaluated:

I have implemented commands, too. Initially they were separated:

But now, expressions and commands implement the same interface, to compy with Ruby moto “every is a value”

Evaluate method receives a Context:

I should review if I want or not that Context object has reference to self and other fields. But I wrote all with TDD, so, I could refactor it at any moment.

A code sample, NameExpression .Evaluate method:

public object Evaluate(Context context)
{
    var result = context.GetValue(this.name);

    if (result is IFunction)
        return ((IFunction)result).Apply(null, emptyvalues);

    return result;
}

Notice that I had to take into account the case: the name argument refers to a function. In Ruby, you can call a function simply using the name, the parenthesis are not mandatory.

Next steps: internal refactor, more commands and expressions.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

2 Comments »

  1. […] Next Post […]

    Pingback by RubySharp, implementing Ruby in C# (1) | Angel "Java" Lopez on Blog — October 17, 2013 @ 7:12 pm

  2. […] Previous Post […]

    Pingback by RubySharp, implementing Ruby in C# (3) | Angel "Java" Lopez on Blog — July 16, 2014 @ 4:44 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: