Select and select

    • How about “axiom_of_choice[1]” ? That’s really what you’re
      implementing. You could use “zermelo” or “zerm” for
      short. Nobody but a mathematical logican will have any prior
      meaning attached to that. Just think of the possiblities:

Actually it’s more like the axiom of restriction (the one that got
Russel out of trouble).

http://burks.brighton.ac.uk/burks/foldoc/80/130.htm

I had considered “restrict”, but the intuitive meaning is all over the
map. Even mathematicians will think of things like restricting a
function to a domain (which is a bit different from what select/pick does).

···

bbense+comp.lang.ruby.Sep.20.02@telemark.stanford.edu wrote:

GOTO Kentaro gotoken@notwork.org wrote in message news:200209231328.g8NDSsND040379@miso.k.notwork.org

Has anyone suggested ‘values’? array.values(1,2,3) sounds reasonably
natural, as does hash.values(key1, key2, key3).

See http://ruby-talk.org/50932

oops - yes, anything with a plural noun would fail requirement 2,
since you’d expect the entire list when no argument was given.

How about getval (and, for symmetry, setval)? A bonus would be that
there might be cases where

a.each_index {|i| a.setval(i,f(i))}

looks nicer than

a.each_index {|i| a[i]=f(i)}

The drawback is that using ‘getval’ rather than ‘getvals’ doesn’t
suggest that multiple arguments are accepted.

The problem I have with ‘pick’ (and friends like ‘sift’ and ‘glean’)
is that it seems to call for a criterion rather than an index list,
and therefore be more a synonym of ‘select’ than of ‘indices’

Another option I like is ‘extract’, especially since it seems to fit
the four cited common cases (array, hash, matchdata and struct).
Though perhaps that suggest something more along the lines of
{k1 => v1, k2 => v2, k3 => v3}.extract(k1,k3) = {k1 => v1, k3 => v3}

martin

···

At Mon, 23 Sep 2002 21:33:05 +0900, > Martin DeMello wrote:

I really like the feel of ‘pick’ with arrays.

What about a ‘pick_as’ option for the hash?

It would be nice though - with hashes - to say whether or not I’m ‘picking’
responses based on the key or the value…

h = {“one” => 1, “two” => 2, “different” => 2}
integerResponse = h.pick_as_key(“two”) # => 2
arrayResponse = h.pick_as_value(2) # => “two”, “different”

If there was some way to ‘refine’ how the selection was made, the ‘pick’
method could more easily extend to other structures… objects (select
[methods | properties | parent | child] ) ?

Looking at it again - maybe
‘pick’
‘pickKey’
‘pickValue’
‘pickParent’
‘pickMethod’
… and then apply regExp to the ‘pick’ allowing me even greater freedom
and selection…

… but that could also get out of hand easier.

Synonyms for ‘select’::

chosen, elect, exclusive, pick, picked, selected, culled, screened, weeded
(out), winnowed (out); favored, preferred; best, elite, choice, dainty,
delicate, elegant, exquisite, rare, recherché, superior

… out of those… pick still looks good…

My vote’s on ‘pick’. Good call.

-Richard Lyman

···

----- Original Message -----
From: dblack@candle.superlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, September 21, 2002 8:47 AM
Subject: Re: select and select

Hi –

On Sat, 21 Sep 2002, Yukihiro Matsumoto wrote:

Hi,

In message “Re: select and select” > > on 02/09/20, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes:

What about these?

at_indices (too long, ugly)

sample (not very clear)

pick (too close to select)

I like “pick”. How do others feel (especially English speaking ones)?

Just so I can see it in action:

ar = %w{ one two three four }

ar.pick(0,3) # => [“one”, “four”]
ar.select {|e| e.size == 3} # => [“one”, “two”]
ar.pick() # => (or ArgumentError?)

h = {“one” => 1, “two” => 2}
h.pick(“one”, “two”) # => [1,2]

I agree with Joel that it’s close in meaning to select, but for some
reason it doesn’t bother me. I find it pretty clear, possibly a
little better suited to arrays than hashes but still OK.

Just to throw in something else, I was thinking about “find_at”,
which I like as a complement to #find_all:

ar.find_all { condition }
ar.find_at(1,3)

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi,

···

In message “Re: select and select” on 02/09/22, “Hal E. Fulton” hal9000@hypermetrics.com writes:

I would do the reverse: Change “index” to “find_index”
(which is clearer anyway).

But there is probably some good reason not to do this.

Yeah, UNIX tradition (see index(3)) which I and Ruby have been
infected for long time.

						matz.

Hi,

It’s okay. But why not overload “values”?

It sounds nice but it doesn’t satisfy the second requirement in
[ruby-talk:50750]:

A new method (say “quux” for example) should satisfy

  • obj.quux(a,b,c) returns [obj[a],obj[b],obj[c]] for all indexable
    collections (i.e. Array, Hash, MatchData and Struct), perhaps
    except for String, which is mere string of characters rather than
    indexable collection. So preferably it should sound natural both
    for arrays, hashes and others.

  • obj.quux() either returns an empty array or causes exception, due
    to the case like obj.quux(*ary) where ary is an empty array.

						matz.
···

In message “Re: select and select” on 02/09/22, Tom Gilbert tom@linuxbrit.co.uk writes:

No, there isn’t as far as I know.

Tosh’s rdtool and Dave’s RDoc are popular tools and I think that RDoc
is better for the purpose to write class documents.

But I prefer RD because rdtool’s rd2 command dumps html to stdout and
allows me to do

% rd2 something.rb | w3m

with a text html browser w3m, which is similar to lynx or links.

I’ll be converted to RDoc if I get known how to do same thing with rdoc.

– Gotoken

···

At Sat, 21 Sep 2002 22:15:09 +0900, Mark Volkmann wrote:

Is there a general concensus as to the best tool/format for documenting Ruby
classes?

In article 05aa01c26190$08727960$0300a8c0@austin.rr.com,

From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, September 21, 2002 9:25 AM
Subject: Re: select and select

Hi,

What about these?

at_indices (too long, ugly)
sample (not very clear)
pick (too close to select)

I like “pick”. How do others feel (especially English speaking ones)?

It’s OK, but I think not ideal…

    • I like it as well as anything I’ve seen so far, I like
      “choose” a bit better.

“choose” and “pick” are synonyms of “select”. What else
can we get from thesaurus.com?

select; pick and choose; pick out, single out; cull, glean,
winnow; sift the chaff from the wheat, separate the chaff from
the wheat, winnow the chaff from the wheat; pick up, pitch upon;
pick one’s way; indulge one’s fancy.

    • I kind of like “winnow”, “cull” and “glean”.
    • Maybe this should be a rubygarden poll?
    • Booker C. Bense
···

Hal E. Fulton hal9000@hypermetrics.com wrote:

----- Original Message -----

In message “Re: select and select” >> on 02/09/20, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes:

“Richard Lyman” rich@lithinos.com writes:

What about a ‘pick_as’ option for the hash?

Perhaps pick_using_xxxx, with straight ‘pick’ as an alias for
pick_using_key

Dave

Don’t forget ‘pickAxe’.

Hal

···

----- Original Message -----
From: “Richard Lyman” rich@lithinos.com
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, September 21, 2002 10:18 AM
Subject: Re: select and select

Looking at it again - maybe
‘pick’
‘pickKey’
‘pickValue’
‘pickParent’
‘pickMethod’

GOTO Kentaro gotoken@notwork.org writes:

But I prefer RD because rdtool’s rd2 command dumps html to stdout and
allows me to do

% rd2 something.rb | w3m

with a text html browser w3m, which is similar to lynx or links.

I’ll be converted to RDoc if I get known how to do same thing with rdoc.

Your post shamed me into action, so…

In the latest CVS, you can say

rdoc -1 something.rb | w3m -T text/html

and you get some of the ugliest output I’ve ever produced (including
bad links, I’m afraid). I just wanted to see how easy it would be to
add.

To be fair, it actually looks pretty good when formatting the README
file, but give it a load of .rb files and the overall structure seems
to get lost. I’d welcome any contributions to make it look nicer.

Cheers

Dave

“cull” reminds me of “culling”, which makes me think of 3D backface
culling and such, i.e. removing polygons. But as far as I understand the
thread, pick/winnow/glean should not remove the elements return, or
should it?

Other than that, I fear future archeologist will mistake Ruby code for
an 18th century english play with such fanciful words in the built-in
classes. require “YeOldeEnglish.rb” :slight_smile:

···

bbense+comp.lang.ruby.Sep.21.02@telemark.stanford.edu wrote:

    • I kind of like “winnow”, “cull” and “glean”.


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

Hashes and arrays map keys to values. The method we are looking for returns
several values based on several keys.

Finding the keys that map to a set of values is out of scope for this method, I
feel.

Gavin

···

----- Original Message -----
From: “Richard Lyman” rich@lithinos.com

I really like the feel of ‘pick’ with arrays.

What about a ‘pick_as’ option for the hash?

It would be nice though - with hashes - to say whether or not I’m ‘picking’
responses based on the key or the value…

Hi –

···

On Sun, 22 Sep 2002, Dave Thomas wrote:

“Richard Lyman” rich@lithinos.com writes:

What about a ‘pick_as’ option for the hash?

Perhaps pick_using_xxxx, with straight ‘pick’ as an alias for
pick_using_key

Or maybe by instead of using ? (for brevity, also to my ear it’s
a slightly better fit).

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi,

···

In message “Re: select and select” on 02/09/22, Dave Thomas Dave@PragmaticProgrammer.com writes:

What about a ‘pick_as’ option for the hash?

Perhaps pick_using_xxxx, with straight ‘pick’ as an alias for
pick_using_key

pick_by_key(s)?

						matz.

I’ll be converted to RDoc if I get known how to do same thing with rdoc.

Your post shamed me into action, so…

In the latest CVS, you can say

rdoc -1 something.rb | w3m -T text/html

and you get some of the ugliest output I’ve ever produced (including
bad links, I’m afraid). I just wanted to see how easy it would be to
add.

Thank you very much! It works.

By the way, does there exist any way to help me input comment?
To write comment for RDoc I must put “#” at beginning of each line.
It is boresome a little when I write a long documentation.

For example, in indented-text-mode of Emacsen, M-q (fill-paragraph)
completes “#” if "#"s occur at each beginning of first two lines of
the paragraph where cursor point presents. Can something like this be
introduced in ruby-mode?

To be fair, it actually looks pretty good when formatting the README
file, but give it a load of .rb files and the overall structure seems
to get lost. I’d welcome any contributions to make it look nicer.

I should use rdoc more and more before diving into rdoc internal.

Thanks,

– Gotoken

···

At Mon, 23 Sep 2002 13:13:56 +0900, Dave Thomas wrote:

Hi –

Hashes and arrays map keys to values. The method we are looking for
returns several values based on several keys.

I think I mentioned the following idea before, but I don’t remember
any response to it (and I’m kind of warming to it :-).

Namely: Enumerable#find_at

It has the following going for it, in my opinion:

  1. it has “at” in it (see my last post for why I like “at” more than
    verbs)

  2. it makes a nice set with #find and #find_all:

    a = %w{one two three four}
    a.find {|e| e[0] == ?t} # “two”
    a.find_all {|e| e.size > 3} # [“three”, “four”]
    a.find_at(0,2) # [“one”, “three”]

  3. it doesn’t already exist :slight_smile:

David

···

On Tue, 24 Sep 2002, Gavin Sinclair wrote:


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi –

···

On Sun, 22 Sep 2002, Yukihiro Matsumoto wrote:

Hi,

In message “Re: select and select” > on 02/09/22, Dave Thomas Dave@PragmaticProgrammer.com writes:

What about a ‘pick_as’ option for the hash?

Perhaps pick_using_xxxx, with straight ‘pick’ as an alias for
pick_using_key

pick_by_key(s)?

I would put it in the plural. Presumably h.pick_by_keys(:akey) would
be quite rare (just a long way of saying h[:akey]). And if it’s in
a variable (pick_by_keys(*some_keys)) it looks and feels plural, even
if the array happens to have only one element.

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

What if the ‘pick’ method took an array as the first parameter, and a string
as the second parameter ?

The second parameter being optional that defaulted to the ‘logical’
choice… index for arrays, key for hashes…

The second parameter being a definition of how the value supplied would
match the object where the method was applied?
(wow - that almost rhymed! :slight_smile: )

So::

h = {
“one” => 1,
“two” => 2,
“different” => 2,
“three” => 3,
“theKeyForTwo” => “two”,
“anotherKeyForTwo” => “two”,
3 => “three”
}
a = [1,2,2,3,2,4,5]

valuesToPick = [ 2 ]
a.pick(valuesToPick) # => 2
a.pick(valuesToPick) # => 2

valuesToPick = [ “two” ]
h.pick(valuesToPick) # => 2
h.pick(valuesToPick, “value”) # => “theKeyForTwo”, “anotherKeyForTwo”

valuesToPick= [ “two”, 3 ]
h.pick(valuesToPick) # => 2, “three”

valuesToPick= [ 2, “three” ]
h.pick(valuesToPick, “value”) # => “two”, “different”

-Rich

···

----- Original Message -----
From: dblack@candle.superlink.net
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Saturday, September 21, 2002 9:43 AM
Subject: Re: select and select

Hi –

On Sun, 22 Sep 2002, Dave Thomas wrote:

“Richard Lyman” rich@lithinos.com writes:

What about a ‘pick_as’ option for the hash?

Perhaps pick_using_xxxx, with straight ‘pick’ as an alias for
pick_using_key

Or maybe by instead of using ? (for brevity, also to my ear it’s
a slightly better fit).

David


David Alan Black | Register for RubyConf 2002!
home: dblack@candle.superlink.net | November 1-3
work: blackdav@shu.edu | Seattle, WA, USA
Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com

Hi,

···

At Mon, 23 Sep 2002 15:28:17 +0900, GOTO Kentaro wrote:

For example, in indented-text-mode of Emacsen, M-q (fill-paragraph)
completes “#” if "#"s occur at each beginning of first two lines of
the paragraph where cursor point presents. Can something like this be
introduced in ruby-mode?

Also in ruby-mode, fill-paragrah works so at a paragraph starts
with "# " (note that blank is necessary after “#”).


Nobu Nakada

Your reasons are good, but I don’t like it :->

Reason: given an index into a data structure, you don’t “find” something, you
get it directly. That’s what indices are all about. That’s why I like “grab”:
it connotes directness.

I would prefer #values_of to #find_at, because #values is a great choice which
can’t be used for technical reasons.

Gavin

···

----- Original Message -----
From: dblack@candle.superlink.net

Hi –

On Tue, 24 Sep 2002, Gavin Sinclair wrote:

Hashes and arrays map keys to values. The method we are looking for
returns several values based on several keys.

I think I mentioned the following idea before, but I don’t remember
any response to it (and I’m kind of warming to it :-).

Namely: Enumerable#find_at

It has the following going for it, in my opinion:

  1. it has “at” in it (see my last post for why I like “at” more than
    verbs)

  2. it makes a nice set with #find and #find_all:

    a = %w{one two three four}
    a.find {|e| e[0] == ?t} # “two”
    a.find_all {|e| e.size > 3} # [“three”, “four”]
    a.find_at(0,2) # [“one”, “three”]

  3. it doesn’t already exist :slight_smile:

David