Android and mirah and arrays and lists and so on

104 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Tim Bray

ungelesen,
28.05.2011, 14:01:2728.05.11
an The Mirah Programming Language
tl;dr - N00b suggests: maybe need a Mirah array data type that
supports the interesting Ruby primitives & is smart about presenting
as appropriate to java methods that want various kind of collections?

I'm working on porting a small-but-nontrivial Android app to
Mirah/Pindah, and my #1 pain point is lists and arrays and so on.  For
the Android-specific part of the app, Mirah doesn't actually buy me
that much over Java, I mean consider this very androidy little squib

  def number_from_clipboard:String
    cm = ClipboardManager(@context.getSystemService(Context.CLIPBOARD_SERVICE))
    s = cm.getText.toString
    if s && PhoneNumberUtils.isGlobalPhoneNumber(s)
      PhoneNumberUtils.formatNumber(s)
    else
      nil
    end
  end

It's cool that it works, but compared to java, it's got, uh, less
semicolons and parentheses. Whoopee.

For me, the first-level big win ought to be in Ruby's elegance in
dealing with lists and blocks and loops.  But this just ain't there at
the moment.  To start with, consider this array declared in Java like
so:

private static int[] mBarImages = {
R.drawable.b0, com.R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4
};

It's really pretty hard in Mirah to create this thing. In another
case, I want to build up a list of phone numbers by appending
selectively, then give it to an Android API that wants a
CharSequence[]. Once again, the obvious ways to do this don't work.

So, on the first, most obvious level, there's clearly a missing piece:

../~/ 501> mirah -e "a=[1,2]; puts a[0]"
DashE:1: Cannot find instance method [](int) on java.util.List

So maybe a basic change would be to make a []-literal denote an array,
and use casting to turn it into a List on request.

But what i think I really want is something Ruby-like that can do <<
and and [a .. b] and be an Enumerable and so on, but I can still use
to give to java methods without thinking too much about it. That is
to say, when a java method wants any flavor of List or array, the
Mirah thing acts like that. And whenever a java method returns such a
thing, we make it into a Mirah array.

I've only been doing Mirah for a day, so no idea if this is possible
or reasonable. But I really want to say something along the lines of:

findPreference('candidate_numbers').setEntries(calls.select {|x|
PhoneNumberUtils.isGlobalPhoneNumber(x)})

(setEntries wants a CharSequence[])

rogerdpack

ungelesen,
30.05.2011, 09:08:2630.05.11
an The Mirah Programming Language

> So, on the first, most obvious level, there's clearly a missing piece:
>
> ../~/ 501> mirah -e "a=[1,2]; puts a[0]"
> DashE:1: Cannot find instance method [](int) on java.util.List

Agree.
I kinda started working on a more user friendly array list for a
different project:
https://github.com/rdp/stevia/blob/4060cd3e25f85b3620dc1f4cf501194df15a2016/lib/go2.mir
"RubyArray"

Maybe we should start a side project "mirah stdlib" or something, if
it won't get accepted into core :P

This might influence its current desing.

http://code.google.com/p/mirah/issues/detail?id=50

Currently arrays appear to default to this:

[1,2,3] becomes
java.util.Collections.unmodifiableList(java.util.Arrays.asList(1, 2,
3));

anyone know the justification for such? Why the unmodifiable? Why not
just use an arraylist, for example?

> But what i think I really want is something Ruby-like that can do <<
> and and [a .. b] and be an Enumerable and so on, but I can still use
> to give to java methods without thinking too much about it.  That is
> to say, when a java method wants any flavor of List or array, the
> Mirah thing acts like that.  And whenever a java method returns such a
> thing, we make it into a Mirah array.

Sounds like you want a standard lib :)

Also when I looked into it, it appeared that the operator "<<" was
invalid...like java wouldn't take it at all. Anybody know if this is
true? If so maybe we some munger to auto-convert it to something java
likes more?

Thanks!
-roger-

Michal Hantl

ungelesen,
30.05.2011, 09:17:2530.05.11
an mi...@googlegroups.com
If we only could extend classes, Mirah could be much more expressive.

Also, things like "5.minutes" would require that primitives could be
automagically boxed when a method is called on them.

Headius, RibRdb, what do you think? :)

I would pay for these features :)

--
S pozdravem, Regards
Michal Hantl

tel: +420 777 812 167
gtalk: michal...@gmail.com
skype: michal.hantl

Robert Fischer

ungelesen,
30.05.2011, 09:41:2430.05.11
an mi...@googlegroups.com
My $0.02.

One of the big advantages of Mirah is the lack of a runtime library.
If you're looking for Ruby features that require a runtime library,
you might as well go use JRuby — I really don't see what Mirah is
gaining you at that point. Can someone tell me what the case is for
Mirah + runtime over JRuby?

My primary use case for Mirah is writing code that will go into my
programming language, so I can have a much nicer programming interface
than Java while not having to ship another language's runtime with my
runtime. I foresee the argument "But stdlib will be small compared to
a runtime!", but I don't really believe it. Especially not with the
kind of features people are clamoring for.

~~ Robert.

rogerdpack

ungelesen,
30.05.2011, 09:42:2630.05.11
an The Mirah Programming Language
> Also, things like "5.minutes" would require that primitives could be
> automagically boxed when a method is called on them.

Or that we have a mirah stdlib "IntegerCarrier" class that (numerics
become and) we can extend locally or what not...

Michal Hantl

ungelesen,
30.05.2011, 09:51:0230.05.11
an mi...@googlegroups.com
What I said doesn't imply having any runtime library.

When you write 5.times { ... } now in mirah, is that a runtime library?

No, its just an extension of the Integer object.

Though it might be hardcoded syntactic sugar now, you can look at it
as if it was your own code saying:

class Integer
def times(&block)
[0..i-1].each(block)
end
end

This is very handy to be able to do because it creatly improves
readability of your code as well as expressiveness.

We don't need to ship Mirah with loads of extensions like this but we
should be able to extend Mirah to suit our needs (android, web
frameworks, test framework DSL...) and thats exactly what Mirah is
capable of.

rogerdpack

ungelesen,
30.05.2011, 09:59:5330.05.11
an The Mirah Programming Language
> One of the big advantages of Mirah is the lack of a runtime library.
> If you're looking for Ruby features that require a runtime library,
> you might as well go use JRuby — I really don't see what Mirah is
> gaining you at that point. Can someone tell me what the case is for
> Mirah + runtime over JRuby?

For me:

Speed + expressiveness instead of one or the other. But that's just
me :)

-roger-

Robert Fischer

ungelesen,
30.05.2011, 10:36:2630.05.11
an mi...@googlegroups.com

Have you *timed* JRuby recently? It's crazy fast.

~~ Robert.

Robert Fischer

ungelesen,
30.05.2011, 10:38:5230.05.11
an mi...@googlegroups.com
>
> Have you *timed* JRuby recently? It's crazy fast.
>

Okay, slight caveat: my timing of JRuby has only been done on a JDK7
machine, so it may just be that invokedynamic makes it crazy fast. But
I bet even on JDK6, it's within a stone's throw of the speed of Mirah
generated code, since Mirah does create overhead.

~~ Robert.

Tim Bray

ungelesen,
30.05.2011, 11:24:4630.05.11
an mi...@googlegroups.com
Ruboto is a wonderful piece of work, but completely unusable for your
typical Android app because it has a startup latency of ~8 seconds.
This is because the horrid performance of Reflection on Dalvik (which
is not much like a JVM inside) and the huge size of the Activity
class. Charlie tells me that the majority of that latency is
reflection on Activity.

For giving Android app developers a taste of Ruby, Mirah currently
seems the best bet.

-Tim

Tim Bray

ungelesen,
30.05.2011, 11:27:1530.05.11
an mi...@googlegroups.com
Anyhow, I'd like to try out some of my ideas; several hours into
spelunking around inside mirah trying to figure out how it fits
together. Eeek, it's complicated! -T

rogerdpack

ungelesen,
30.05.2011, 12:30:1030.05.11
an The Mirah Programming Language
> Have you *timed* JRuby recently? It's crazy fast.

Hmm. Do you have any numbers here, in comparison with mirah?

> Okay, slight caveat: my timing of JRuby has only been done on a JDK7 machine,

Inspired by your post, I re-ran my jruby [admittedly trivial]
benchmark with openjdk7 [1] (both windows, server VM) and got

openjdk6 best time: 25.14
openjdk7 best time: 25.23

Though I could be running it poorly. So I doubt that's where the
speedup is. Of course, I'm running windows so maybe anything I do
will feel slow :)

That same benchmark with pure java [3]: 3.7s
mirah [4]: 4.01s

Then again this is only a microbenchmark...but for me I love writing
ruby but then you start running your unit tests and it's like...why
does rubygems' 137 unit tests take like 90s to run? The runtime feels
slow to me. But that's just me, and also something that mirah might
help with :)

Cheers!
-roger-

[1] https://github.com/rdp/stevia/blob/master/comparison/go.rb
[2] alioth seems to imply jruby is slower than java 6 server :P
http://shootout.alioth.debian.org/u64q/ruby.php
[3] https://github.com/rdp/stevia/blob/master/comparison/go.java
[4] https://github.com/rdp/stevia/blob/master/comparison/go.mr

John Woodell

ungelesen,
30.05.2011, 12:48:5430.05.11
an mi...@googlegroups.com
Literal arrays should be mutable. I hope headius will look into this soon.  :-)
I created a helper class in Dubious to make Arrays easier to work with.

Array.of_ints [3,6,2,9,5,7,4,8]
https://gist.github.com/465160

Array.of_strings ["these" ,"are", "the", "strings", "we", "will", "test"]

Martin Mazur

ungelesen,
30.05.2011, 13:27:2530.05.11
an mi...@googlegroups.com
I just want to chime in and say that I agree with Robert on this.

One of the reasons I'm looking into Mirah is that the front-end is detached (or somewhat) from the back-end. I eventually want to see it output code for the CLR/DLR and hope to contribute to this ones I'm comfortable with the language and up to date on my compiler theory.

Given this if you want a library you would have to write it completely in Mirah which kind-of breaks the whole purpose in my opinion.

Of course I've only been fooling around with it for a short while but the whole reason for me doing so is the dream of a CLR/DLR version.

//M

--
phone: +46 (0)709 78 40 03
e-mail: m...@upplopp.se
twitter: http://twitter.com/m_mazur

rogerdpack

ungelesen,
30.05.2011, 15:19:3930.05.11
an The Mirah Programming Language
> One of the reasons I'm looking into Mirah is that the front-end is detached (or somewhat) from the back-end. I eventually want to see it output code for the CLR/DLR and hope to contribute to this ones I'm comfortable with the language and up to date on my compiler theory.

A stdlib written mostly in mirah would work wouldn't it?

-roger-

Martin Mazur

ungelesen,
31.05.2011, 03:48:3131.05.11
an mi...@googlegroups.com

>> One of the reasons I'm looking into Mirah is that the front-end is detached (or somewhat) from the back-end. I eventually want to see it output code for the CLR/DLR and hope to contribute to this ones I'm comfortable with the language and up to date on my compiler theory.
>
> A stdlib written mostly in mirah would work wouldn't it?

Sure, but then you have the whole scala "issue". You need to ship the stdlib with your application which increases the size of your application and doesn't take advantage of the underlaying environment.

//M

rogerdpack

ungelesen,
01.06.2011, 14:13:5901.06.11
an The Mirah Programming Language
> [1,2,3] is interpreted as
> java.util.Collections.unmodifiableList(java.util.Arrays.asList(1, 2,
> 3));
>
> anyone know the justification for such? Why the unmodifiable? Why not
> just use an arraylist, for example?

I think it is converted to a Collection so that you can more easily do

ArrayList.new [1,2,3]

(ArrayList et al have no constructor that takes an array, oddly, so
forcing our hand).

I'm not sure why it's cast as an unmodifiableList, and also why not
to just use ArrayList, as one can build an unmodifiable list manually,
if desired.

-roger-

Rib Rdb

ungelesen,
01.06.2011, 14:59:0101.06.11
an mi...@googlegroups.com
It was originally an unmodifiableList to match the list literals from java 7.  I think we agreed later they should just be ArrayLists, but no one's made the change yet.
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten