guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparison operators for strings /and/ numbers?


From: Christopher Howard
Subject: Re: Comparison operators for strings /and/ numbers?
Date: Mon, 18 Sep 2017 20:27:15 -0800

On Thu, 2017-08-24 at 10:05 +0200, David Kastrup wrote:
> Christopher Howard <address@hidden> writes:
> 
> > Hi, in another lisp I have been working with, it has <, >, and ==
> > (structure equality) operators which can take string arguments,
> > number
> > arguments, or a mixture of both. But it seems in guile that there
> > are
> > separate comparison operators for strings and for numbers. This
> > makes
> > sense but is not very convenient for my present purpose. Is there
> > some
> > other guile operators or extension operators that will handle both?
> > I
> > could make some I'm sure, but I don't want to reinvent the wheel.
> 
> (use-modules (oop goops))
> 
> (define-method (< (a <string>) . rest)
>   (apply string<? a rest))
> 
> (< "g" "b") ;; => #f
> 

Forgive me for bring this thread back, but I just finished reading the
goops info manual...

My question, specifically: Suppose:

1) I use fn "<" in my module, as a goops generic, and then
2) somebody else "use"s my module in their module, and then
3) suppose they do a "define-method" to create another "<" for a new
datatype
4) they call a function in my module that uses "<"

Will that function call have access to the new method for that generic?

Background: This would obvious be very important in a module providing
a generic data structure (like a binary tree), where you would want to
compare keys using "<", but you wouldn't want to arbitrarily limit the
possible data types to what was defined in the module.

Or do I need to define an <ordered> class and expose that to my module
users? I'm thinking in terms like Data.Ord class from Haskell. (Java
folks would call it an "interface".)

-- 
https://qlfiles.net
https://emailselfdefense.fsf.org/en/

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]