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: Ralf Mattes
Subject: Re: Comparison operators for strings /and/ numbers?
Date: Thu, 24 Aug 2017 12:17:14 +0200
User-agent: NeoMutt/20170609 (1.8.3)

On Thu, Aug 24, 2017 at 10:29:41AM +0200, Arne Babenhauserheide wrote:
> Hi Christopher,
> 
> You can use GOOPS to make them generic:
> 
> > (import (oop goops))
> > (< "a" "b")

That's not what David suggested. Of course you still need to define the
method specialized on strings.

> <unnamed port>:3:0: <unnamed port>:3:0: In procedure <: Wrong type argument 
> in position 1: "a"
> 
> Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> [1]> (define-method (< (a <string>) (b <string>)) (string<? a b))
> [1]> (< "a" "b")
> $1 = #t
> 
> For some functions you might need to call (define-generic <function>)
> before this (you’ll notice because define-method will signal an error).

Is that still the case? IIRC this was true for Guile 1 where you needed
to "redeclare" build-in functions as generic, but from what I see Guile2
automatically generates the appropriate generic functions. This is
pretty much how Common Lisp handles defmethod without a matching
defgeneric (but in CL you aren't allowed to transform a function from CL 
into a generic).

Cheers, Ralf Mattes

> Best wishes,
> Arne
> 
> 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.
> 
> -- 
> Unpolitisch sein
> heißt politisch sein
> ohne es zu merken





reply via email to

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