#1409 Online Fantom Playground

kaushik Sun 13 Feb 2011

I've been wanting to make this for sometime. Here's the website

http://www.fanzy.net

Let's you execute fantom code within your browser. Might have a few glitches. Doesn't work well in IE(but that's a feature :). Let me know how you like it or how can it be improved. I am pretty sure something better can be done in the take a tour part. Just registered the website, so if your country hasn't yet been updated, here's the appspot link

qualidafial Sun 13 Feb 2011

Very cool, Kaushik! This has been on my wishlist for a while. My first fanzy program:

class DrinkingSong
{
  Void main()
  {
    (99..1).each
    {
      echo ("$it bottles of beer on the wall")
      echo ("$it bottles of beer!")
      echo ("Take one down, pass it around")
      echo ("${it-1} bottles of beer on the wall!")
      echo
    }
  }
}

Yuri Strot Sun 13 Feb 2011

Wow, it's fantastic! I think it will be quite useful to be able to execute Fantom scripts both on the server and client sides. And it'll be amazing to see FWT examples in action ;-)

Thank you Kaushik for your work!

helium Sun 13 Feb 2011

I just want to mention that IE isn't the only browser that has problems with this. It currently doesn't work in Opera, either.

Yuri Strot Sun 13 Feb 2011

In fact it doesn't completely work even in Chrome: my browser crashed on editor right click...

kaushik Sun 13 Feb 2011

@Matthew: Thanks!

@Yuri: Thanks. Did you mean something like FWT to JS and displaying it on browser? If you have some examples in mind let me know(here or [email protected]). I'll see how to fit em up there.

@helium: Ah I see. The problem is in using the ACE Editor which only supports chrome and firefox as of now. In spite of that the coding experience with that is really awesome, that's why I choose that editor.Maybe I can change the editor to just a textarea if the browser is anything else? Will think about it. thanks and sorry for that.

qualidafial Sun 13 Feb 2011

Fyi, the editor is completely unusable on my android phone. So maybe the textarea is a good idea.

DanielFath Sun 13 Feb 2011

Actually I checked and the editor crashes only after the first program was executed. Before that it works fine on chrome.

Nice work kaushik. I wish all my exams weren't taking so much time to process.

PS: Also it works on IE8 but selection isn't displayed properly. Would FWT work on IE and android phones?

peter Sun 13 Feb 2011

Thanks Kaushik, this will be very useful.

However, I did find two things which wouldn't run. The following caused a Compiler Error: and no further information:

class A
{
    Int x
}

class Main
{
    public static Void main ()
    {
        a := A { x = 2 }  // <--
        echo ("Hi: " + a.x)
    }
}

It also complains about:

enum class Suit { clubs, diamonds, hearts, spades }

with

sys::ArgErr: Invalid type signature 'Suit[]'

tcolar Sun 13 Feb 2011

works well for me (Linux chrome) ... nice editor/highlighting too.

DanielFath Sun 13 Feb 2011

Speaking of highlighting can ACE be configured to the scheme used by the Fantom main page? I really enjoy the "Cobalt" theme.

brian Mon 14 Feb 2011

This is really awesome!

At some point soon, we need to figure out how to start organizing all these cool community sites/projects (first step is maybe just a community page with links, but I have some more sophisticated ideas too for later this year)

qualidafial Mon 14 Feb 2011

Peter,

I think your compiler error is because class A has a non-nullable field, and no constructor to initialize it. In order to be able to use an it-block with a class, you have to declare the it-block constructor yourself:

class A
{
  Int a

  new make(|This| f)
  {
    f(this)
  }
}

I tried putting this in fanzy.net and I either get redirected to http://www.fanzy.net/500 or I get a compiler error message with no explanation like you described. However that constructor should fix your problem in regular Fantom development.

peter Mon 14 Feb 2011

qualidafial: interesting. I don't find the problem in regular development.

$ cat >> test.fan
class A
{
    Int x
}

class Main
{
    public static Void main ()
    {
        a := A { x = 2 }  // <--
        echo ("Hi: " + a.x)
    }
}
$ fan test.fan
Hi: 2

I was aware of the it-block constructor syntax, but I thought defining classes like A would set up an empty constructor and use the default Obj.with method, and so allow a := A { x = 2 } to work. Perhaps I'm misunderstanding something, but the example works for me in 1.0.57.

brian Mon 14 Feb 2011

a := A { x = 2 } // <--

Since A doesn't actually have an it-block constructor, that code actually compiles into:

A.make.with { x = 2 }

qualidafial Mon 14 Feb 2011

Ah, I forgot that unitialized Int fields are defaulted to Int.defVal. Essentially the same as an uninitialized int field in Java defaults to 0.

kaushik Mon 14 Feb 2011

Sorry for the late reply guys

Fixed:

  • Works with opera ( and IE8 & above)
  • Better syntax highlighting (All fan keywords)
  • Should crash less
  • @DanielFath, cobalt mode is on top right :). Actually I din't get all the styles right though, Let me know if you find anything
  • @peter, thanks. I screwed up that part. Sorry about that. Fixed it.
  • @qualidafial - I don't know about how does it show in android now?

Make sure you refresh or clear cache to load new fanzy.

Those who cannot access fanzy.net should try http://fan-zy.appspot.com/

Thank you.

tcolar Mon 14 Feb 2011

The editor doesn't seem to allow pasting ... is that how it should work ? (Kinda limiting)

helium Mon 14 Feb 2011

I forgot that unitialized Int fields are defaulted to Int.defVal.

I didn't knew that. But it doesn't seem to work for my own classes. So defVal is only used for some build in types?

Back on topic: Works perfectly in Opera now. I actually just tested the defVal behavior there.

@tcolar: pasting works for me.

kaushik Mon 14 Feb 2011

@tcolar Can you clear your cache and try again? Could be old javascript screwing up with the new one. You're using linux + chrome right? Just tested on my unbuntu, seems to work fine.

tcolar Mon 14 Feb 2011

never mind works now ... not sure, maybe was caching.

brian Mon 14 Feb 2011

I didn't knew that. But it doesn't seem to work for my own classes. So defVal is only used for some build in types?

Well actually the special value types Bool, Int, and Float are really just Java boolean, long, and double. So they default to false, 0L, and 0.0. But those values also happen to be Bool.defVal, Int.defVal, and Float.defVal too.

http://fantom.org/doc/docLang/TypeSystem.html#valueTypes

go4 Tue 15 Feb 2011

Very cool kaushik!

I'm curious how you do. Override classloader is a good idea. Another approach is to compile on the server side, execute in the browser.

kaushik Tue 15 Feb 2011

Thanks go4!

If your question is regarding sandboxing, I just let appengine do it. Once I got it running on appengine, everything else was pretty straight forward. Wrote a custom Env to capture the standard "out" and standard "err" and mostly that's it except one small little irk: Uris seems to throw a NPE when literal syntax is used so I had to hack around it (actually now that I remembered it, I will file a bug).

tcolar Fri 18 Feb 2011

I tried some actor code and got some sort of thread protection error.

Is that a know issues(sandboxing maybe ?), or should it work ?

I can send you the details/trace tomorrow, if you want.

kaushik Fri 18 Feb 2011

It's most likely a sandboxing issue. Appengine does not allow us to start new threads. Certain things like Actor.locals[""]= has to work. This is actually kind of limiting. If any of you know of a way around this, I'd love to implement it even if it's a little bit of a hack. Trying out actors will be really cool. You can mail me the code and trace anyway. thanks.

vkuzkokov Fri 18 Feb 2011

I have this source:

using concurrent;
class HelloFantom{
  Void main(){
    Actor(ActorPool()) { it->size }.send("hi")
  }
}

And this error:

sys::Err: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
java.security.AccessControlContext.checkPermission (AccessControlContext.java:355)
java.security.AccessController.checkPermission (AccessController.java:567)
java.lang.SecurityManager.checkPermission (SecurityManager.java:549)
java.lang.ThreadGroup.checkAccess (ThreadGroup.java:304)
java.lang.Thread.init (Thread.java:349)
65 More...

Looks like you can't create new threads which seems reasonable for most kinds of sandboxes. Although it would be really nice to have ability to run at least limited number of threads.

kaushik Sat 5 Mar 2011

Updated to support Fantom 1.0.58.

kaushik Sun 5 Jun 2011

Updated to support Fantom 1.0.59

kaushik Thu 13 Oct 2011

Updated to support Fantom 1.0.60. Also has an api : http://www.fanzy.net/api/ if you want to execute fantom code from outside of fanzy (like in blogs). @DanielFath sorry about all the delay.

kaushik Thu 13 Oct 2011

Here's a sample form that uses fanzy api :

<form action="http://www.fanzy.net/exec" method="post">
    <textarea name="code" style="width:200px; height:200px"></textarea>
    <input type="submit" />
</form>

DanielFath Thu 13 Oct 2011

Wow, that's great kaushik. No need to be sorry. It's an awesome feature. I'll be looking into implementing it asap.

kaushik Tue 6 Dec 2011

SlimerDude Tue 3 Nov 2015

http://www.fanzy.net/ seems to be down, which is a real shame.

Does anyone know if kaushik is still around, or if the Fanzy website is held in a public repository somewhere?

go4 Tue 10 Nov 2015

Login or Signup to reply.