[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Developing cross-platform web/GUI applications

Jon Harrop

5/26/2007 8:43:00 PM


Hi!

I'd like to write cross-platform applications that either run in the browser
or run as standalone GUI applications in a functional programming language.

I understand that Ruby is a functional programming language and I was
wondering:

1. How widely is Ruby used on Linux, Mac OS X and Windows?

2. Are there compilers/interpreters targetting the JVM/.NET that make it
easy to develop GUI applications?

3. Has anyone done any significant work in this area using Ruby?

4. Are scientists and engineers using Ruby?

Many thanks,
--
Dr Jon D Harrop, Flying Frog Consultancy
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journ...
10 Answers

M. Edward (Ed) Borasky

5/26/2007 10:35:00 PM

0

Jon Harrop wrote:
> Hi!
>
> I'd like to write cross-platform applications that either run in the browser
> or run as standalone GUI applications in a functional programming language.
>
> I understand that Ruby is a functional programming language and I was
> wondering:
>
Well, I wouldn't call Ruby a "functional" programming language in the
same sense as Lisp/Scheme, Haskell and Erlang define themselves as
functional programming languages. Ruby is more an "object-oriented
programming language" in the same sense as Smalltalk and Java define
themselves as object-oriented programming languages.
> 1. How widely is Ruby used on Linux, Mac OS X and Windows?
>
It depends on what you mean by "widely used." It's installed by default
on Macs, but you have to download and install it on from an external
repository on Windows, and while it's freely distributed in all the
major Linux distro repositories, it isn't usually installed by default.
> 2. Are there compilers/interpreters targetting the JVM/.NET that make it
> easy to develop GUI applications?
>
Yes indeed! The JVM is supported by Sun's jRuby, Microsoft just
announced a "Dynamic Language Run-time" that supports Ruby on .NET, and
there are miscellaneous other implementations. I don't have any
experience with the .NET versions, but I highly recommend jRuby.
> 3. Has anyone done any significant work in this area using Ruby?
>
If by "this area" you mean web applications, you pretty much have to
have been living under a rock if you haven't heard about Ruby on Rails.
;). But general GUI applications are a bit more obscure in Ruby. Most of
the major GUI toolkits have Ruby bindings, but there's no clear "first
choice" among them.
> 4. Are scientists and engineers using Ruby?
>
Yes, but it isn't as popular among them as Python is. I'm a
scientist/engineer, and I use Ruby, along with Perl and R. But I've
never taken the time to learn Python.
> Many thanks,
>


Jon Harrop

5/27/2007 1:02:00 AM

0

M. Edward (Ed) Borasky wrote:
> Well, I wouldn't call Ruby a "functional" programming language in the
> same sense as Lisp/Scheme, Haskell and Erlang define themselves as
> functional programming languages.

Ok. I'm from an OCaml/F# background. May I just ask if anyone can translate
the following OCaml one-liner into Ruby:

let rec nest ?(n=2) f x = if n=0 then x else nest ~n:(n-1) f (f x)

it nests "n" applications of "f" to "x" with "n" defaulting to 2 if it isn't
specified, e.g. "nest ~n:3 f x" gives f(f(f(x))).

This trivial example encapsulates much of what I love about OCaml and it
doesn't translate well into any other language that I know.

> Ruby is more an "object-oriented
> programming language" in the same sense as Smalltalk and Java define
> themselves as object-oriented programming languages.

Hmm. I'm not an OO fan but I was under the impression that Ruby has much
better support for functions than Python.

>> 1. How widely is Ruby used on Linux, Mac OS X and Windows?
>>
> It depends on what you mean by "widely used." It's installed by default
> on Macs,

Really? It is bundled by Apple? That's incredible! =8-)

>> 2. Are there compilers/interpreters targetting the JVM/.NET that make it
>> easy to develop GUI applications?
>>
> Yes indeed! The JVM is supported by Sun's jRuby, Microsoft just
> announced a "Dynamic Language Run-time" that supports Ruby on .NET, and
> there are miscellaneous other implementations. I don't have any
> experience with the .NET versions, but I highly recommend jRuby.

Awesome!!! This is exactly the kind of thing I'm looking for.

>> 3. Has anyone done any significant work in this area using Ruby?
>>
> If by "this area" you mean web applications, you pretty much have to
> have been living under a rock if you haven't heard about Ruby on Rails.
> ;).

Oh yeah, I forgot. :-)

I had a look at Ruby on Rails a while ago and, although I can do scientific
computing with my eyes closed, web programming is like double Dutch to me.
Couldn't make head nor tail of it. I think I'm improving now though. :-)

> But general GUI applications are a bit more obscure in Ruby. Most of
> the major GUI toolkits have Ruby bindings, but there's no clear "first
> choice" among them.

Ok, thanks.

>> 4. Are scientists and engineers using Ruby?
>>
> Yes, but it isn't as popular among them as Python is. I'm a
> scientist/engineer, and I use Ruby, along with Perl and R. But I've
> never taken the time to learn Python.

Are there many tools for scientists and engineers written in Ruby? What sort
of stuff do you write in Ruby?

Thanks very much!
--
Dr Jon D Harrop, Flying Frog Consultancy
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journ...

Bil Kleb

5/27/2007 1:37:00 AM

0

Jon Harrop wrote:
>
> I had a look at Ruby on Rails a while ago and, although I can do scientific
> computing with my eyes closed, web programming is like double Dutch to me.
> Couldn't make head nor tail of it. I think I'm improving now though. :-)

I'd recommend you start with Camping,

http://camping.rub...

instead then migrate to Rails if need more amenities.

Regards,
--
Bil Kleb
http://fun3d.lar...

James Tucker

5/27/2007 7:09:00 AM

0

Jon Harrop wrote:
> M. Edward (Ed) Borasky wrote:
>> Well, I wouldn't call Ruby a "functional" programming language in the
>> same sense as Lisp/Scheme, Haskell and Erlang define themselves as
>> functional programming languages.
>
> Ok. I'm from an OCaml/F# background. May I just ask if anyone can translate
> the following OCaml one-liner into Ruby:
>
> let rec nest ?(n=2) f x = if n=0 then x else nest ~n:(n-1) f (f x)
>
> it nests "n" applications of "f" to "x" with "n" defaulting to 2 if it isn't
> specified, e.g. "nest ~n:3 f x" gives f(f(f(x))).
>
> This trivial example encapsulates much of what I love about OCaml and it
> doesn't translate well into any other language that I know.
>
If I understood your description, and the code correctly, this should work:

n ||=2; if n == 0; x else n.times do x = f x; end end

or should that be:

n ||=2; f ( x = if n == 0; x; else; n.times do x = f x; end; x; end )

of course, you could recurse using a temporary value rather than x, if
you wanted to.

initialize an example with:

def f x; 2 * x; end; x = 2

I'm sure there's probably a more 'functional' way also.

If I do have your example correct, I should think a generic recursor
function would not be hard to implement in ruby.

In fact:

def recurse func, depth, *initials
working = initials
depth.times do
working = func.call *working
end
working
end

Initialize like so:

def f x, y
[2 * x, 1 * y]
end

x,y=2,10

Use like so:

recurse method(:f), 2, x, y

n.b. this should work for arbitrary argument lengths provided the called
function returns an array of arguments for itself.

Does this satisfy?

Oh, I thought I'd add a block version too, just for all those people
that love blocks (and because it may be useful in this context):

def recurse_blk depth, *initials, &blk
working = initials
depth.times do
working = yield(*working)
end
working
end

example: recurse_blk(2, x, y) do |a,b| f(a,b) end

Enjoy.


Logan Capaldo

5/27/2007 2:25:00 PM

0

On Sun, May 27, 2007 at 10:15:06AM +0900, Jon Harrop wrote:
> M. Edward (Ed) Borasky wrote:
> > Well, I wouldn't call Ruby a "functional" programming language in the
> > same sense as Lisp/Scheme, Haskell and Erlang define themselves as
> > functional programming languages.
>
> Ok. I'm from an OCaml/F# background. May I just ask if anyone can translate
> the following OCaml one-liner into Ruby:
>
> let rec nest ?(n=2) f x = if n=0 then x else nest ~n:(n-1) f (f x)
>
> it nests "n" applications of "f" to "x" with "n" defaulting to 2 if it isn't
> specified, e.g. "nest ~n:3 f x" gives f(f(f(x))).
The closest to the OCaml would look like:

def nest(x, n = 2, &f)
if n == 0 then x else nest(f[x], n - 1, &f) end
end

nest(-3) { |a| a + 1 } #=> -1

However, I'd probably write it like:
def nest(x, n = 2)
(1..n).inject(x) { |acc, _| yield(acc) }
end

nest("a", 3) { |a| a + a } #=> "aaaaaaaa"

>
> This trivial example encapsulates much of what I love about OCaml and it
> doesn't translate well into any other language that I know.
>

Jon Harrop

5/27/2007 10:55:00 PM

0

Logan Capaldo wrote:
> The closest to the OCaml would look like:
>
> def nest(x, n = 2, &f)
> if n == 0 then x else nest(f[x], n - 1, &f) end
> end

Ok, that's easily the best I've seen in any other language.

> nest(-3) { |a| a + 1 } #=> -1

So nest(-3) defaults to nest(-3, 2) and returns a closure that accepts the
anonymous function { |a| a + 1 } and applies it to -3 twice, is that right?

Back in OCaml, that is:

nest ((+) 1) (-3)

> However, I'd probably write it like:
> def nest(x, n = 2)
> (1..n).inject(x) { |acc, _| yield(acc) }
> end

I don't understand this one. I think "inject" is a fold and "yield" returns
a value and a continuation. Looks like the continuation is ignored the next
time it is accumulated, but won't the result have a continuation in it?

> nest("a", 3) { |a| a + a } #=> "aaaaaaaa"

I think this is:

nest ~n:3 (fun a -> a^a) "a"

Thanks!

--
Dr Jon D Harrop, Flying Frog Consultancy
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journ...

Logan Capaldo

5/28/2007 11:00:00 PM

0

On Mon, May 28, 2007 at 08:10:11AM +0900, Jon Harrop wrote:
> Logan Capaldo wrote:
> > The closest to the OCaml would look like:
> >
> > def nest(x, n = 2, &f)
> > if n == 0 then x else nest(f[x], n - 1, &f) end
> > end
>
> Ok, that's easily the best I've seen in any other language.
>
> > nest(-3) { |a| a + 1 } #=> -1
>
> So nest(-3) defaults to nest(-3, 2) and returns a closure that accepts the
> anonymous function { |a| a + 1 } and applies it to -3 twice, is that right?
>
> Back in OCaml, that is:
>
> nest ((+) 1) (-3)
>
> > However, I'd probably write it like:
> > def nest(x, n = 2)
> > (1..n).inject(x) { |acc, _| yield(acc) }
> > end
>
> I don't understand this one. I think "inject" is a fold and "yield" returns
> a value and a continuation. Looks like the continuation is ignored the next
> time it is accumulated, but won't the result have a continuation in it?
inject is a fold. yield is not a continuation, but rather a way of
accessing the passed in function (block) anonymously.

def f
yield
end

def f1(&b)
b.call
end

f { puts "Does the same thing" }
f1 { puts "Does the same thing" }

>
> > nest("a", 3) { |a| a + a } #=> "aaaaaaaa"
>
> I think this is:
>
> nest ~n:3 (fun a -> a^a) "a"
>
> Thanks!
>
> --
> Dr Jon D Harrop, Flying Frog Consultancy
> The F#.NET Journal
> http://www.ffconsultancy.com/products/fsharp_journ...

ara.t.howard

5/29/2007 10:54:00 PM

0


On May 26, 2007, at 2:55 PM, Jon Harrop wrote:

>
> Hi!
>
> I'd like to write cross-platform applications that either run in
> the browser
> or run as standalone GUI applications in a functional programming
> language.
>
> I understand that Ruby is a functional programming language and I was
> wondering:
>
> 1. How widely is Ruby used on Linux, Mac OS X and Windows?
>
> 2. Are there compilers/interpreters targetting the JVM/.NET that
> make it
> easy to develop GUI applications?
>
> 3. Has anyone done any significant work in this area using Ruby?
>
> 4. Are scientists and engineers using Ruby?

http://sciruby.codefor...

we use it heavily here

http://www.ngdc.noaa.gov/dmsp/...

these were made with ruby

http://www.ngdc.noaa.gov/dmsp/interest/ka...

as were these

http://www.ngdc.noaa.gov/dmsp/interest/...

regards.

-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Bil Kleb

5/29/2007 11:04:00 PM

0

ara.t.howard wrote:
> we use it heavily here
>
> http://www.ngdc.noaa.gov/dmsp/...

I also saw your stuff in Al Gore's /Inconvenient Truth/ movie, no?

Later,
--
Bil Kleb
http://fun3d.lar...

ara.t.howard

5/29/2007 11:39:00 PM

0


On May 29, 2007, at 5:05 PM, Bil Kleb wrote:

> ara.t.howard wrote:
>> we use it heavily here
>> http://www.ngdc.noaa.gov/dmsp/...
>
> I also saw your stuff in Al Gore's /Inconvenient Truth/ movie, no?

you did!

forgot about that. ruby and al gore - what a combo!

cheers.

-a
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama