[Q]Ruby LISP-ish stuff

I was wondering if there are plans to add some of the more useful LISP
functions to the array class. What I have in mind is something more or
less like this…

class Array
def rest
self[1,-1] end
def pushnew(x)
push x unless member? x end
end #class Array

I’m not at all fond of LISP but I use it a lot at work and these functions
in particular have proven extremely useful when I use them in Ruby.
Certainly these would be more efficient if included in the core language.

If no one says “that is an idiotic idea” then perhaps I shall file an RCR.

//\oses
"zbfrf@oyhtf.pbz".rot13
www.blugs.com

Saluton!

  • Moses Hall; 2003-07-11, 23:45 UTC:

def rest
self[1,-1] end

This usually is called ‘tail’ while self[0] is called ‘head’.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

Ah, these are the “car/cdr” or “first/rest” synonyms from Haskell?

def rest
self[1,-1] end

This usually is called ‘tail’ while self[0] is called ‘head’.

//\oses

Saluton!

  • Moses Hall; 2003-07-14, 12:23 UTC:

Ah, these are the “car/cdr” or “first/rest” synonyms from Haskell?

def rest
self[1,-1] end

This usually is called ‘tail’ while self[0] is called ‘head’.

‘head’ and ‘tail’ seems to be quite generic terms - they occur in a
large number of texts that describe dealing with lists.

The only notable issue is that ‘tail’ seems to have different
meanings depending on the lanugage in common. As far as languages
that do not have native list support are concerned it means ‘the last
element’ while in those languages that have a list data type it means
‘anything but the last element’.

The former version e.g. can be found in ‘Introduction to Algorithms’
by Cormen, Leiserson and Rivest or ‘Algorithms in ’
by Sedgwick.

Anyway. In my opinion ‘list[1,-1]’ is much more telling than ‘rest’
because ‘rest’ means ‘remainder after doing something’ whereas
‘list[1,-1]’ specifies that ‘doing something’.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon

Er, that’s anything but the first element, right?

Ben

···

On Mon July 14 2003 3:11 pm, Josef ‘Jupp’ Schugt wrote:

The only notable issue is that ‘tail’ seems to have different
meanings depending on the lanugage in common. As far as languages
that do not have native list support are concerned it means ‘the last
element’ while in those languages that have a list data type it means
‘anything but the last element’.

Saluton!

  • Ben Giddings; 2003-07-14, 21:07 UTC:

meanings depending on the lanugage in common. As far as languages
that do not have native list support are concerned it means ‘the last
element’ while in those languages that have a list data type it means
‘anything but the last element’.

Er, that’s anything but the first element, right?

Right you are.

Gis,

Josef ‘Jupp’ Schugt

···


N’attribuez jamais à la malice ce que l’incompétence explique !
– Napoléon