RCR: Stack, Queue alias methods in Array

Ah, then it looks that I indeed can get the function pointer from a method
name/string by following the same logic as in function “rb_alias”. So it
seems that the answer to my original function pointer question is yes,
although it is not straightforward.

Regards,

Bill

···

ts decoux@moulon.inra.fr wrote:

When you call rb_define_method(), ruby create a node NODE_CFUNC. The
function pointer is stored in this node.

Hi,

Yes, but only the first time.

Not for me. I probably have to answer to the question “why top is
last?” thousand times in the future. :wink:

:slight_smile: What if we signed a contract to answer that particular
question for you?

Actually, I like top. To me, it is clear that an array
has a top ONLY when you are using it as a stack.

As for me, my limited intellect makes it necessary to
look up shift/unshift/push/pop any time I need the
real details of how they work.

The matz’s first principle of method names.

If you have a “right” name for the method, implement it.
If you have any doubt in a name, just wait.

Maybe patience is one of your great secrets.

I wonder: Would there be any value in Stack and
Queue classes that inherited from Array?

Perhaps this would introduce more problems than
it would solve.

Hal

···

----- Original Message -----
From: “Yukihiro Matsumoto” matz@ruby-lang.org
To: “ruby-talk ML” ruby-talk@ruby-lang.org
Sent: Wednesday, November 27, 2002 10:10 AM
Subject: Re: RCR: Stack, Queue alias methods in Array

In message “Re: RCR: Stack, Queue alias methods in Array” > on 02/11/27, Martin DeMello martindemello@yahoo.com writes:

Hi,

Yes, but only the first time.

Not for me. I probably have to answer to the question “why top is
last?” thousand times in the future. :wink:

I just realised that the whole reason I wanted this was that it doesn’t
mater which end it is :slight_smile: It’s just “the same end as push and pop”.

The matz’s first principle of method names.

If you have a “right” name for the method, implement it.
If you have any doubt in a name, just wait.

Principle of least annoyance :slight_smile: I agree that it’s very irritating to be
forced to use a method name that doesn’t feel right.

Speaking of which, what do you think of ‘lambda’ being renamed ‘fn’ in
Arc? Ever since the first time I had to pass several anonymous procs to
a function I’ve been wondering whether adding f as an alias for proc was
a good idea - it looks much neater, but making f a reserved word might
be bad.

martin

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

In message “Re: RCR: Stack, Queue alias methods in Array” > on 02/11/27, Martin DeMello martindemello@yahoo.com writes:

Ah, then it looks that I indeed can get the function pointer from a method
name/string by following the same logic as in function "rb_alias". So it
seems that the answer to my original function pointer question is *yes*,
although it is not straightforward.

Sorry to say this but re-read *carefully*

http://www.ruby-talk.org/47220

An user defined (at ruby level) method *don't* have a function pointer.

Guy Decoux

Hi,

···

In message “Re: RCR: Stack, Queue alias methods in Array” on 02/11/28, “Hal E. Fulton” hal9000@hypermetrics.com writes:

I wonder: Would there be any value in Stack and
Queue classes that inherited from Array?

Perhaps this would introduce more problems than
it would solve.

I think Array is too big, and has too much methods unnecessary to
Stack and Queue.

						matz.

If anything, Stack and Queue classes should encapsulate an array.

Even better, there should be different Stack and Queue classes that have
the same API and are implemented using different data structures:
arrays, linked lists, heaps, etc. etc.

Cheers,
Nat.

···

On Wed, 2002-11-27 at 16:20, Hal E. Fulton wrote:

I wonder: Would there be any value in Stack and
Queue classes that inherited from Array?


Nat Pryce nat.pryce@b13media.com
B13media

Hi,

Not for me. I probably have to answer to the question “why top is
last?” thousand times in the future. :wink:

I just realised that the whole reason I wanted this was that it doesn’t
mater which end it is :slight_smile: It’s just “the same end as push and pop”.

I’m not that optimistic.

Speaking of which, what do you think of ‘lambda’ being renamed ‘fn’ in
Arc? Ever since the first time I had to pass several anonymous procs to
a function I’ve been wondering whether adding f as an alias for proc was
a good idea - it looks much neater, but making f a reserved word might
be bad.

“fn” is not conservative enough, I feel.

						matz.
···

In message “Re: RCR: Stack, Queue alias methods in Array” on 02/11/28, Martin DeMello martindemello@yahoo.com writes:

Martin DeMello wrote:

Not for me. I probably have to answer to the question “why top is
last?” thousand times in the future. :wink:

I just realised that the whole reason I wanted this was that it doesn’t
mater which end it is :slight_smile: It’s just “the same end as push and pop”.

Then you really don’t want ‘top’, you want ‘peek’, as in “get value pop
would return, but don’t pop it off”.

Having too many free braincycles doing the dishes, I started wondering why the blazes what is the top or bottom of a stack should have anything to do with anything. I can put the next clean plate on top the other clean ones, but that doesn't look like a push to me. Now, when I get the (crazy) idea of putting them at the _bottom_ of the stack of plates, to be sure to rotate and distribute the wear and tear on the plates, that, by any definition, is one big push. Just ask my weak, geeky arms.
···

Yukihiro Matsumoto matz@ruby-lang.org wrote:


([ 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)

Oh yes, I knew about that based on your original explanation (47220),
because standard Ruby simply does not create a C function from a Ruby
method. I don’t know what happens when rb2c is involved, though…

Regards,

Bill

···

ts decoux@moulon.inra.fr wrote:

Sorry to say this but re-read carefully

http://www.ruby-talk.org/47220

An user defined (at ruby level) method don’t have a function pointer.

How about a standard library of data structures which include Stack and
Queue, just like STL in C++? I don’t care how they are implemented
(either inheriting from Array or not), but I think it is useful for
everyone not to reinvent this library by creating his/her own model of
Stack and Queue. (When I used a queue by using an array, I have to
remember each time whether the “head” is arr.first or arr.last. Worse,
sometimes I reverse the order accidentally :frowning: )

Regards,

Bill

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

I think Array is too big, and has too much methods unnecessary to
Stack and Queue.

  					matz.

I wonder: Would there be any value in Stack and
Queue classes that inherited from Array?

If anything, Stack and Queue classes should encapsulate an array.

Even better, there should be different Stack and Queue classes that have
the same API and are implemented using different data structures:
arrays, linked lists, heaps, etc. etc.

And matz wrote

I think Array is too big, and has too much methods unnecessary to
Stack and Queue.

The following quote from Paul Graham made quite an impression on me - I
wonder what other people think about it:

In Common Lisp I have often wanted to iterate through the fields of a
struct-- to comb out references to a deleted object, for example, or
find fields that are uninitialized. I know the structs are just vectors
underneath. And yet I can’t write a general purpose function that I can
call on any struct. I can only access the fields by name, because that’s
what a struct is supposed to mean.

A hacker may only want to subvert the intended model of things once or
twice in a big program. But what a difference it makes to be able to.

martin

···

On Wed, 2002-11-27 at 16:20, Hal E. Fulton wrote:
Nat Pryce nat.pryce@b13media.com wrote:

Martin DeMello wrote:

Not for me. I probably have to answer to the question “why top is
last?” thousand times in the future. :wink:

I just realised that the whole reason I wanted this was that it doesn’t
mater which end it is :slight_smile: It’s just “the same end as push and pop”.

Then you really don’t want ‘top’, you want ‘peek’, as in “get value pop
would return, but don’t pop it off”.

But ‘peek’ really is too generic - it could also mean ‘get value shift
would return’, ‘expose the internal data structure’ and probably a
couple of other things (remember BASIC’s ‘peek’?)

Having too many free braincycles doing the dishes, I started wondering why the blazes what is the top or bottom of a stack should have anything to do with anything. I can put the next clean plate on top the other clean ones, but that doesn't look like a push to me. Now, when I get the (crazy) idea of putting them at the _bottom_ of the stack of plates, to be sure to rotate and distribute the wear and tear on the plates, that, by any definition, is one big push. Just ask my weak, geeky arms.

Cafeterias, for example, use push-down stacks of plates. The plates sit
in a vertical cage, with a spring at the bottom, so that the top plate
is always at the same height. You literally push in a plate - the others
get pushed downwards and teh spring compresses, and likewise you can
only remove the top plate.

martin

···

Kent Dahl kentda@stud.ntnu.no wrote:

Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

···

In message “Re: RCR: Stack, Queue alias methods in Array” on 02/11/28, William Djaja Tjokroaminata billtj@y.glue.umd.edu writes:

How about a standard library of data structures which include Stack and
Queue, just like STL in C++?

Great idea. No one prevent you (or others) from doing it. But don’t
ask me (either implicitly or explicitly) to do it for you. :wink:

						matz.

Martin DeMello wrote:

Then you really don’t want ‘top’, you want ‘peek’, as in “get value pop
would return, but don’t pop it off”.

But ‘peek’ really is too generic -

No more than ‘top’, and it is less confusing, IMHO.

it could also mean ‘get value shift
would return’,

Could, yes, but is that what it traditionally is used for? I’ve never
seen peek in combination with shift and unshift, but often seen it with
push and pop. For shift and unshift, the mental image I use, is items
horizontally aligned on a table. Shifting it means moving it to give
space at the front for a new element, and unshift means pushing it the
other way, making the first element fall off the table. I.e. the ‘first’
or ‘front’ element is the one unshift would return.

As for stacks, the mental image is naturally vertical. Either bend down
and take a peek at the one at the bottom (me doing dishes) or stand on
toes to peek at the one at the top (cafeterias doing dishes).

If you’re still not convinced, there’s a little something that stuck to
my mind all day:

Push, pop and peek,
on their own were rather meek.
But their combined whack,
made quite a stack,
with an interface that sounds quite sleek.

‘expose the internal data structure’
and probably a
couple of other things (remember BASIC’s ‘peek’?)

Yes, I remember. But how many come to Ruby from a Basic that uses peek
these days? :stuck_out_tongue:

Cafeterias, for example, use push-down stacks of plates. The plates sit
in a vertical cage, with a spring at the bottom, so that the top plate
is always at the same height. You literally push in a plate - the others
get pushed downwards and teh spring compresses, and likewise you can
only remove the top plate.

Can’t argue with that. Or can I? A more frequented stack-like structure
encountered IRL by programmers, I would assume to be the coffee machine
and (somewhat) the water cooler. Usually, in my experience, they have a
stack of cups where you remove at the bottom, from a cylindrical plastic
encasing, to avoid the cup being full of dust. :slight_smile:

···

Kent Dahl kentda@stud.ntnu.no wrote:


([ 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)

Hi Matz,

So you are not aware of any person who has a library of common data
structures (such as those included in STL) which is available for the Ruby
community?

Bill

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

Hi,

In message “Re: RCR: Stack, Queue alias methods in Array” > on 02/11/28, William Djaja Tjokroaminata billtj@y.glue.umd.edu writes:

How about a standard library of data structures which include Stack and
Queue, just like STL in C++?

Great idea. No one prevent you (or others) from doing it. But don’t
ask me (either implicitly or explicitly) to do it for you. :wink:

  					matz.

… also, so who has the authority to make a certain library be part of
the “standard library” that comes with the “standard” Ruby
distribution? Maybe Nobu?

Bill

···

Yukihiro Matsumoto matz@ruby-lang.org wrote:

on 02/11/28, William Djaja Tjokroaminata <billtj@y.glue.umd.edu> writes:

How about a standard library of data structures which include Stack and
Queue, just like STL in C++?

Great idea. No one prevent you (or others) from doing it. But don’t
ask me (either implicitly or explicitly) to do it for you. :wink:

  					matz.

Okay … let’s say that I get this sort of thing created. How would
I go about getting it in as part of “standard” Ruby?

(Note: I’m not volunteering to do it; I’m going to be starting a new
job on Monday.)

-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.27 at 16.49.01

···

On Thu, 28 Nov 2002 03:18:55 +0900, Yukihiro Matsumoto wrote:

In message “Re: RCR: Stack, Queue alias methods in Array” > on 02/11/28, William Djaja Tjokroaminata billtj@y.glue.umd.edu > writes:

How about a standard library of data structures which include
Stack and Queue, just like STL in C++?
Great idea. No one prevent you (or others) from doing it. But
don’t ask me (either implicitly or explicitly) to do it for you.
:wink:

Martin DeMello wrote:

If you’re still not convinced, there’s a little something that stuck to
my mind all day:

Push, pop and peek,
on their own were rather meek.
But their combined whack,
made quite a stack,
with an interface that sounds quite sleek.

There is really no reason to stop
With defining a ‘push’ and a ‘pop’
But a function called ‘peek’
Isn’t all that unique
I would much rather see it called ‘top’

And a plausible use of ‘peek’ paired with ‘shift’ rather than ‘pop’
would be looking at the first argument to a function without shifting
that argument out.

‘expose the internal data structure’
and probably a
couple of other things (remember BASIC’s ‘peek’?)

Yes, I remember. But how many come to Ruby from a Basic that uses peek
these days? :stuck_out_tongue:

Can you even get a Basic that uses peek these days? I think C is the
last bastion of pointer arithmetic :slight_smile:

Cafeterias, for example, use push-down stacks of plates. The plates sit
in a vertical cage, with a spring at the bottom, so that the top plate
is always at the same height. You literally push in a plate - the others
get pushed downwards and teh spring compresses, and likewise you can
only remove the top plate.

Can’t argue with that. Or can I? A more frequented stack-like structure
encountered IRL by programmers, I would assume to be the coffee machine
and (somewhat) the water cooler. Usually, in my experience, they have a
stack of cups where you remove at the bottom, from a cylindrical plastic
encasing, to avoid the cup being full of dust. :slight_smile:

But don’t you put in new cups from the top? Which would make it a queue
rather than a stack.

martin

···

Kent Dahl kentda@stud.ntnu.no wrote:

I have a hunch that the best way to get code into the standard
distribution is to:
a) Write it
b) Get it at least somewhat widely used

The worst that would happen then is that we would have such a library
easily available through the upcoming Ruby-PAN.

The best, if that is the desire, it gets included in the standard
library. The likelyhood if this will be greater I’m sure if it is proven
to work, and proven useful too.

I’ll certainly be downloading it - particularly if it contains a
Set.

-Tom

···

On Thu, 28 Nov 2002, William Djaja Tjokroaminata wrote:

Yukihiro Matsumoto matz@ruby-lang.org wrote:

on 02/11/28, William Djaja Tjokroaminata <billtj@y.glue.umd.edu> writes:

How about a standard library of data structures which include Stack and
Queue, just like STL in C++?

Great idea. No one prevent you (or others) from doing it. But don’t
ask me (either implicitly or explicitly) to do it for you. :wink:

  					matz.

… also, so who has the authority to make a certain library be part of
the “standard library” that comes with the “standard” Ruby
distribution? Maybe Nobu?

Bill

Hi,

···

In message “Re: RCR: Stack, Queue alias methods in Array” on 02/11/28, Austin Ziegler austin@halostatue.ca writes:

Okay … let’s say that I get this sort of thing created. How would
I go about getting it in as part of “standard” Ruby?

  1. you publish your work on RAA and such.
  2. you contact me, with peer reviews
  3. we grant you CVS account
  4. you check them in to the repository

REXML and Test::Unit are in state 3.

						matz.