#662 fansh improvements

liamstask Fri 10 Jul 2009

I've just been getting started with Fan, and the first place I wanted to experiment a bit was in the shell with fansh. I pretty immediately came upon a few stumbling blocks however:

* It does not appear to be possible to import pods to the scope of the shell via using - I get output that looks like

fansh> using web
ERROR(1): Expected expression, not 'using'

This means I need to use the full qname to get at things like WebClient:

c := web::WebClient

which is ok, but definitely a pain.

* I came across a bug trying to assign a reference to a method to a local var

fansh> e := &echo
fan.sys.Method$MethodFunc@3f0ba812
fansh> e("test")
ERROR(9): Expected expression, not '|'
fansh> echo("test")
ERROR(9): Expected expression, not '|'

Not only does e not work properly, but echo no longer works properly either.

* A couple usability enhancements (less pressing) would be:

  • support for multi-line expressions - allowing for copy and paste from the web or some other doc straight into fansh would be a big help
  • readline-style history for navigating through a fansh session. not being able to retrieve previous commands or even control the cursor makes things pretty slow

That's all for now!

brian Fri 10 Jul 2009

It does not appear to be possible to import pods to the scope of the shell via using

I pushed a fix for using so you can now use any of the three using statement forms in the fansh tool:

using pod
using pod::Type
using pod::Type as Rename

support for multi-line expressions - allowing for copy and paste from the web or some other doc straight into fansh would be a big help

We don't have a real REPL, so we only really support statements/expressions (and even those not perfectly as your previous error attests). So two questions:

  1. is multi-line useful without actually being able to declare classes/methods?
  2. how to detect a multi-line entry? We can do hacks like look for trailing { or \ lacking full AST support, or potentially have a mode like start/end

readline-style history for navigating through a fansh session. not being able to retrieve previous commands or even control the cursor makes things pretty slow

This works on Windows, but not on Linux/Mac - so I am not sure how to do readline in a Java app. I believe there is some JReadLine library maybe? I'd rather not have to ship with that but maybe something we can drop in? Another option is to just have nice fansh support within an IDE.

liamstask Sat 11 Jul 2009

Thanks for the quick fix.

is multi-line useful without actually being able to declare classes/methods?

I think it's useful for being able to copy in some example code, even if classes are not declared, and being able to define closures locally would be very handy. Although I also noticed that this did not seem to work at the moment:

fansh> f := |,| { echo("hi there") }
ERROR(9): Expected expression, not '|'

how to detect a multi-line entry?

Not sure on this one. I was playing with the scala repl recently and it has nice support for this...not sure what the trick is, though. Might be somewhere to look for at least one possible solution, I suppose.

For shell history, I believe http://jline.sourceforge.net is the most common solution. I agree it would be a little bit of a pain to add this, but might be worthwhile in the end?

liamstask Sat 11 Jul 2009

Just a quick note - the local closure def does work. There was something else funky going on in my env. Please ignore!

liamstask Mon 13 Jul 2009

One other inconsistency in fansh:

for( i := 0; i < 3; ++i ) { echo(i) }

doesn't compile. Works fine in code.

Dubhead Mon 13 Jul 2009

Another symptom:

% rlwrap fansh
Fan Shell v1.0.44 ('?' for help)
fansh> for (i := 0; i < 3; i++) echo(i)
0
1
2
fansh> for (j := 0; j < 3; j++) echo(j)
ERROR(6): Expected ')', not ':='
fansh>

brian Mon 13 Jul 2009

I pushed a hacked fix for it.

The fundamental problem is that we don't have a true REPL, and are just hacking stuff up to create a class file we can pass to the compiler. So the whole thing is a bit ugly.

So the whole thing really needs to be redesigned and probably won't work with my existing Fan parser very well.

liamstask Mon 13 Jul 2009

Thanks for the fix. Please let me know if it's easier to just stop updating this thread in the meantime.

tompalmer Mon 13 Jul 2009

From what I remember seeing about JLine, it's totally t3h awesome. It uses JNI and native code, but it includes that in the jar which it auto-unpacks into the temp dir. You can double-check, but I think this is what JRuby uses, and I remember it serving them well from when I was following it.

Login or Signup to reply.