Monday, January 16, 2012

Not named?

So as my previous post mentioned I now have the dart VM compiled and running. However, now I'm running into something new I didn't expect. Apparently the dartVM (from trunk) doesn't recognize the named function parameters as expected, or at all. Seth Ladd's blog post about Learning Functions for Dart explicitly states that optional function parameters can be named. Regardless of how I format the function and calling functions, I am receiving the error:
...unexpected token ':'

This is a little confusing as, while I realize I'm not using the bleeding_edge version of the VM, but it shouldn't be that old. Here's a link to the code I'm using http://try.dartlang.org/s/cgIo (it does work as expected in dartboard).
hello(msg, to, [from, rate]) => '${from} sent ${msg} to ${to} via ${rate}';

main() => print(hello('world', 'Seth', from:'Bob', rate:'First Class'));

Results on Dartboard:
Bob sent world to Seth via First Class

And the results in the VM (from both the dart editor console and from command line):
/home/mememe/dart/Test/Test.dart': Error: line 3 pos 44: unexpected token ':'
main() => print(hello('world', 'Seth', from:'Bob', rate:'First Class'));

Additionally. For some reason in the Dart Editor, if I highlight all my code and copy it and paste it else-where, when I come back to the Dart Editor and unselect the code (but make no changes to it), I can no longer click on "Launch in Dart Server" the icon becomes greyed out and I can't run the code from within the editor again until I close out of the editor and re-launch it. Again this is using Dart editor build: 3331.

I'll take some more time tomorrow to play around with the Dart editor and see if I can verify specifically what causes me to no longer be able to run the code in the server. (No amount of saving, or editing the code will restore the functionality that I've seen so far, short of closing out entirely).

3 comments:

  1. You are correct. This is a bug in the VM (I filed issue 1205).
    As an easy work-around simply use curly braces instead of => for functions that use named-argument calls:
    main() { print(hello('world', 'Seth', from:'Bob', rate:'First Class')); }

    ReplyDelete
    Replies
    1. Florian, I had already submitted a bug (Issue 1199). I didn't realize however that the => shortcut is what was causing it to fail. May want to update my bug instead of the new one?

      Delete