1 Oct 2008 01:02

### Re: Mode method for Array

```On Sep 30, 2008, at 6:30 PM, Glenn wrote:
> Hi,
>
> I wrote 2 ways.  I don't know if either way is good or not.  Any
> feedback is welcome.
>
> The first way makes a hash of the array, with the unique values in
> the array as the keys, and the number of times the keys occur as the
> values.  Then I create a new hash out of that first hash with the
> frequencies as the keys of the hash and the elements that had that
> frequency as the values.  Then I pick out the value of the highest
> key.
>
> The second way creates that frequency hash, then iterates over the
> hash and creates an array with the elements that have the highest
> frequency.
>
> class Array
>  def hash_of_frequency
>    h = Hash.new(0)
>    each_with_index do |e, i|
>      e = e.to_f if e != nil
>      h[e] = h[e] += 1
>    end
>    h
>  end

You never use i, so just use each (and loose the second block parameter)

h[e] = h[e] += 1 ???
```

1 Oct 2008 01:19

### Re: Mode method for Array

```On Tue, Sep 30, 2008 at 6:02 PM, Rob Biedenharn
<Rob <at> agileconsultingllc.com> wrote:
> On Sep 30, 2008, at 6:30 PM, Glenn wrote:
>>
>> Hi,
>>
>> I wrote 2 ways.  I don't know if either way is good or not.  Any feedback
>> is welcome.
>>
>> The first way makes a hash of the array, with the unique values in the
>> array as the keys, and the number of times the keys occur as the values.
>>  Then I create a new hash out of that first hash with the frequencies as the
>> keys of the hash and the elements that had that frequency as the values.
>>  Then I pick out the value of the highest key.
>>
>> The second way creates that frequency hash, then iterates over the hash
>> and creates an array with the elements that have the highest frequency.
>>
>> class Array
>>  def hash_of_frequency
>>   h = Hash.new(0)
>>   each_with_index do |e, i|
>>     e = e.to_f if e != nil
>>     h[e] = h[e] += 1
>>   end
>>   h
>>  end
>
> You never use i, so just use each (and loose the second block parameter)
>
```

1 Oct 2008 01:33

### Re: Mode method for Array

```
On Sep 30, 5:56 pm, Glenn <glenn_r... <at> yahoo.com> wrote:
> Hi,
>
> I'd like to write a get_mode method for the Array class.  The method would return an array of the most
frequently occurring element or elements.
>
> So [3, 1, 1, 55, 55].get_mode would return [1, 55].
>
> I have a way to do this but I don't know if it's the best way.  I was wondering if anyone had any suggestions?

Facets has:

module Enumerable

# In Statistics mode is the value that occurs most
# frequently in a given set of data.

def mode
count = Hash.new(0)
each {|x| count[x] += 1 }
count.sort_by{|k,v| v}.last[0]
end

end

Hmm.. but that thwarts ties. I'll have to consider how to fix.

T.

```

1 Oct 2008 02:49

### RubyScript2Exe and fxruby

```Hi

I have a simple "hello world" fxruby application. When I try to create
an exe using RubyScript2Exe I get the following error message

"no such file to load -- Fox16"

How can I solve this error?

I am doing this on a windows xp computer with the one click installer
(1.8.6) installed

Cheers David

```
1 Oct 2008 03:11

### Re: Mode method for Array

```Using Enumerable#cluster_by (already defined in Facets):

module Enumerable
def mode
cluster_by do |element|
element
end.cluster_by do |cluster|
cluster.length
end.last.ergo do |clusters|
clusters.transpose.first
end # || []
end
end

gegroet,
Erik V.

```
1 Oct 2008 04:12

### Re: Mode method for Array

```
There's one more problem with your code: [].mode doesn't work.

gegroet,
Erik V.

```
1 Oct 2008 05:03

### Re: my ears are burning... ;)

```parrt <at> antlr.org wrote:
> Well, I wasn't talking about packets; more protocols and things like
> that.

Protocols are just a two-directional sequences of packets. They
always require parsing, though sometimes the hardware does some
of that (like Ethernet frames)
.
> Oh, right. Grimm/Rats! guy told me about that trick.  Nice, though I'm
> guessing you're going to have trouble with recovery. ;) Bolting on the
> first error is something most people don't want to happen.

Agree - but recovery isn't so hard. Just use a catch-all alternative
that gets activated when nothing else matches, and get it to skip to
a recovery point. The problem is you lose the error context from the
failure though. Perhaps the current "best guess" error list should be
available to the recovery rule... thanks for inspiring that idea, I
might be able to make it work.

> You bet. Incremental parsing with recursive descent parsers has to be
> done with a mechanism strikingly similar to memoization.  That's the
> easy part once you figure out the trick. the part that I have not
> figured out is the lexer.  Since PEGs are scannerless usually, perhaps
> the same mechanism just plain works; let me know how that goes. I
> would be interested in the results.

It should just work, though AIUI the invalidation rule are rather subtle.

> Actually, my experience is that people like ANTLR because they can put
> actions anywhere. Over 24 years  observing parser building, It seems
```

1 Oct 2008 05:23

### Re: Shoes: problem with http proxy

```On Wed, Oct 01, 2008 at 04:21:54AM +0900, Raffaele Tesi wrote:
> mmm, i think http_proxy env var would be preferable:
> - uniformity (i see ruby uses this env variable all around);
> - avoid NTLM hell (demanding tools like cntlm the frucking
> proto-normalization stuff)

Okay, I just committed this.  A new build for Windows should be out
soon, keep your eyes on the shoes blog. <http://newwws.shoooes.net>

_why

```
1 Oct 2008 05:25

### Project Announcement: Ruby and Rails binary packages for Solaris.

```Hello Rubyists,

I'm happy to announce a project/release that delivers Ruby/Rubygems
Solaris packages.  Also bundled are DTrace support, extensions,
performance fixes for Solaris.  We plan to add the Rails ecosystem in
our next release.

So if you're in need of a installable packages( or code to create

http://rubyforge.org/projects/rubyopensolaris/
http://rubyopensolaris.rubyforge.org/

There are, of course, at least a couple of other ways to get your
pre-built copy on Solaris, and the RubyOpenSolaris project does not
overlap with those.

Feel free to add yourself to the below mailing lists to track /
influence the contents / delivery of these packages  <at>

rubyopensolaris-discuss <at> rubyforge.org for general discussions / feature
requests etc.,
rubyopensolaris-announce <at> rubyforge.org for new release announcements.
rubyopensolaris-development <at> rubyforge.org for development discussions.

Best Regards,
-ps

--

--
Prashant Srinivasan
```

1 Oct 2008 05:57

### Re: ruby1.9 block scope

```Hi,

At Wed, 1 Oct 2008 03:53:26 +0900,
Yukihiro Matsumoto wrote in [ruby-talk:316501]:
> Thank you for your valuable input.  And don't worry I have not decided
> to put this in the language, even after 2.0.

How about making all local variables other than block arguments
method/class/toplevel?

--

--