[#377882] remove array bracket — Kamarulnizam Rahim <niezam54@...>

Hi when i run my script, the output is as followed:

18 messages 2011/02/02

[#378046] Setter method for Hash value — Rolf Pedersen <rolfhsp@...>

Hi

20 messages 2011/02/03
[#378052] Re: Setter method for Hash value — Brian Candler <b.candler@...> 2011/02/03

Rolf Pedersen wrote in post #979431:

[#378056] Re: Setter method for Hash value — Rolf Pedersen <rolfhsp@...> 2011/02/03

Hi Brian (and others who have contributed with suggestions along the same

[#378144] C extension: How to check if a VALUE is still alive (not being GC'ed)? — Iñaki Baz Castillo <ibc@...>

Hi, I'm coding an async DNS resolver for EventMachine based on udns (a

13 messages 2011/02/05
[#378171] Re: C extension: How to check if a VALUE is still alive (not being GC'ed)? — Tony Arcieri <tony.arcieri@...> 2011/02/06

On Sat, Feb 5, 2011 at 4:02 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrote:

[#378179] Re: C extension: How to check if a VALUE is still alive (not being GC'ed)? — Iñaki Baz Castillo <ibc@...> 2011/02/06

2011/2/6 Tony Arcieri <tony.arcieri@medioh.com>:

[#378199] Choosing an office suite — Hilary Bailey <my77elephants@...>

I am trying to decide which office suite to choose from. The only

30 messages 2011/02/07
[#378229] Re: Choosing an office suite — Phillip Gawlowski <cmdjackryan@...> 2011/02/07

On Mon, Feb 7, 2011 at 11:15 AM, Hilary Bailey <my77elephants@gmail.com> wrote:

[#378202] making hash key from arrays — Arihan Sinha <arihan_sinha@...>

Hi All,

11 messages 2011/02/07

[#378254] "permission denied" happening too often — Peter Bailey <pbailey@...>

Hello,

15 messages 2011/02/08
[#378256] Re: "permission denied" happening too often — Anurag Priyam <anurag08priyam@...> 2011/02/08

> I've got Ruby scripts that have been working fine for years now. But,

[#378257] Re: "permission denied" happening too often — Markus Schirp <mbj@...> 2011/02/08

You can also try to strace your script. In the logs you'll find the system

[#378259] Re: "permission denied" happening too often — Peter Bailey <pbailey@...> 2011/02/08

Markus Schirp wrote in post #980289:

[#378307] undefined class/module YAML::PrivateType - Error — "Priya D." <dharsininitt@...>

Hi,

11 messages 2011/02/09

[#378341] System calls with ` in parameters — "Gerad S." <geradstemke@...>

Hi All,

12 messages 2011/02/09

[#378618] Defining class methods — Tony Arcieri <tony.arcieri@...>

It seems there are 3 ways of defining class methods (at least in common

12 messages 2011/02/16

[#378685] LiveAST: a pure Ruby 1.9.2 library obtaining live abstract syntax trees — "James M. Lawrence" <quixoticsycophant@...>

= LiveAST

13 messages 2011/02/18

[#378753] posix_mq : Problem installing on HPUX — Tadeusz Bochan <tad.bochan@...>

Hello,

13 messages 2011/02/20

[#378890] a, b = Array.new(2).map!{|x| data.dup} — Stefan Salewski <mail@...>

I think I can replace this code

19 messages 2011/02/23
[#378892] Re: a, b = Array.new(2).map!{|x| data.dup} — niklas | brueckenschlaeger <niklas@...> 2011/02/23

Are you sure you can't rework your code to *not* copy data 5x? I assume

[#378899] Re: a, b = Array.new(2).map!{|x| data.dup} — Stefan Salewski <mail@...> 2011/02/23

On Thu, 2011-02-24 at 07:00 +0900, niklas | brueckenschlaeger wrote:

[#378941] Automatic question generator libs in Ruby Language — Sniper Abandon <sathish.salem.1984@...>

is there any Automatic question generator libraries in Ruby Language ?

20 messages 2011/02/24
[#379058] Re: Automatic question generator libs in Ruby Language — Sniper Abandon <sathish.salem.1984@...> 2011/02/27

suppose if i have a paragraph (arround 250 words)

[#379172] Re: Automatic question generator libs in Ruby Language — Shadowfirebird <shadowfirebird@...> 2011/03/01

> i want to get all the possible question from that paragraph

[#379174] Re: Automatic question generator libs in Ruby Language — Peter Zotov <whitequark@...> 2011/03/01

On Tue, 1 Mar 2011 19:31:36 +0900, Shadowfirebird wrote:

[#379175] Re: Automatic question generator libs in Ruby Language — Adam Prescott <mentionuse@...> 2011/03/01

On Tue, Mar 1, 2011 at 10:55 AM, Peter Zotov <whitequark@whitequark.org>wrote:

[#379177] Re: Automatic question generator libs in Ruby Language — Peter Zotov <whitequark@...> 2011/03/01

On Tue, 1 Mar 2011 20:02:13 +0900, Adam Prescott wrote:

[#379179] Re: Automatic question generator libs in Ruby Language — Adam Prescott <mentionuse@...> 2011/03/01

On Tue, Mar 1, 2011 at 12:28 PM, Peter Zotov <whitequark@whitequark.org>wrote:

[#378949] why is $1 in a grep() equal to nil? — 7stud -- <bbxx789_05ss@...>

class DataSource

16 messages 2011/02/24
[#378953] Re: why is $1 in a grep() equal to nil? — Eric Christopherson <echristopherson@...> 2011/02/25

On Thu, Feb 24, 2011 at 2:59 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:

[#378958] parsing rule for this code? — 7stud -- <bbxx789_05ss@...>

1)

11 messages 2011/02/25

[#379000] Symbol#to_proc helping out with #select to beat Scala-s solution — Jarmo Pertman <jarmo.p@...>

Hey!

9 messages 2011/02/25

[#379074] finding a tag in a binary file — rob stanton <tnotnats@...>

I have a binary file in which I'd like to find multiple strings of 10

12 messages 2011/02/27

Re: why is overloading invalid in ruby.

From: Thomas E Enebo <tom.enebo@...>
Date: 2011-02-01 15:34:44 UTC
List: ruby-talk #377845
On Mon, Jan 31, 2011 at 9:10 PM, Gary Wright <gwtmp01@mac.com> wrote:
>
> On Jan 31, 2011, at 2:47 PM, Charles Oliver Nutter wrote:
>
>> On Mon, Jan 31, 2011 at 1:27 PM, Thomas E Enebo <tom.enebo@gmail.com> wr=
ote:
>>> On Mon, Jan 31, 2011 at 9:00 AM, Gary Wright <gwtmp01@mac.com> wrote:
>>>> I think the original poster provided an example of overloading based o=
n the number of parameters but not their type.
>>>> Even restricting yourself to overloading by arity is a bit problematic=
 in Ruby because the arity still has to be determined (in some cases) dynam=
ically:
>>> Actually, arity of callsite is always calculated =A0in Ruby to know if
>>> you should throw an ArgumentError (3 for 0 specified sort of errors)
>
> Maybe I'm overlooking something but I wasn't suggesting that you don't ne=
ed to calculate arity but instead was pointing out that you can't just calc=
ulate it at parse time but sometimes need to calculate it at call time.
>
> foo(1,2) =A0 =A0 # the call arity can be computed at parse time
> foo(*a) =A0 =A0 =A0# the call arity must be computed at call time
>
> So in an 'overload-based-on-arity' scheme there might be some optimizatio=
n opportunities for some call sites but not for every call site.

Yeah, that is certainly true in the general sense even in existing
Ruby semantics.  In your first example, we know that it is always a
two-arg call (at parse time) so we can go through a two-arity call
path and not 'box' the call parameters into an array.  In the second
case we might be able to know arity at parse time if we know 'a' is a
literal array.    If we don't then the optimizations we can do get
more limited.

You are correct that adding arity to the mix would make the
optimizations more complex, but I think it depends on the case and
what you get by supporting it.  For example, in the second case if we
made our callsite cache lookup the methods foo and cache all of them
at the site, then dispatch to the appropriate one, we would have quite
a bit more complicated callsite cache (since we would need to
invalidate it if any arity version changed), but this would dispatch
much faster than doing things like you are showing in the example
later in your email (actually much faster than any pure-Ruby logic for
arity resolution).  In the case where there was only one arity it
would behave more or less like it does currently.  The main change
would be on any same-named method we would need to invalidate.  [Note:
This is just one way this could be done and callsite invalidation
would be about the same as what it is now since it would invalidate
based on name.   We could do it name+arity.  We could do it both ways
even (perhaps name+arity for first case and only name for second).

With all this said, it seems like a good idea to me, but OTOH no
feature is without its caveats.  I am more worried about Ruby
programming style than performance and though it seems to pass a smell
test for me...I don't think I am in the 'yeah let's do it camp' yet.
I am probably in the 'someone should play with this' camp.

>
> Seems like you can get pretty far though with just a little meta-programm=
ing with no special language support:
>
> module Arity
> =A0def overload(base)
> =A0 =A0define_method(base) do |*args|
> =A0 =A0 =A0argc =3D args.size
> =A0 =A0 =A0method_name =3D "#{base}_#{argc}"
> =A0 =A0 =A0if respond_to?(method_name)
> =A0 =A0 =A0 =A0send(method_name, *args)
> =A0 =A0 =A0else
> =A0 =A0 =A0 =A0raise ArgumentError, "wrong number of arguments (no method=
 for #{argc} arguments)"
> =A0 =A0 =A0end
> =A0 =A0end
> =A0end
> end
>
> class A
> =A0extend Arity
>
> =A0overload :foo
>
> =A0def foo_0
> =A0 =A0puts "foo with no arguments"
> =A0end
>
> =A0def foo_1(arg1)
> =A0 =A0puts "foo with 1 argument: #{arg1.inspect}"
> =A0end
>
> end
>
> A.new.foo =A0 =A0 =A0 =A0 =A0 # dispatches to A#foo_0
> A.new.foo(1) =A0 =A0 =A0 =A0# dispatches to A#foo_1
> A.new.foo(1,2) =A0 =A0 =A0# ArgumentError
>
>
> Gary Wright
>
>



--=20
blog: http://blog.enebo.com=A0 =A0 =A0=A0 twitter: tom_enebo
mail: tom.enebo@gmail.com

In This Thread

Prev Next