guile-devel
[Top][All Lists]
Advanced

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

Re: Smart variables, dumb variables


From: rm
Subject: Re: Smart variables, dumb variables
Date: Thu, 15 Aug 2002 19:27:09 +0200
User-agent: Mutt/1.3.24i

On Thu, Aug 15, 2002 at 06:34:28PM +0200, Marius Vollmer wrote:
> address@hidden writes:
> 
> > oops, i forgot to mention goops. I was thinking of GOOPS generic 
> > metods:
> > |  
> > |  (define-generic +)
> > |  (define-method (+ (a <string>) (b <string>))
> > |    (string-append a b))
> > |  
> > |  (+ 41 1)
> > |  => 42
> > |  
> > |  (+ "Foo" "bar")
> > |  => "Foobar"
> > |  
> 
> In this example you are creating a new variable with the name "+" and
> store a new generic in it.  That variable would not carry the
> declarations that the variable named "+" in the guile-core module
> carries.  So the compiler would treat your variable "+" like any other
> and wont perform wrong optimizations on it.

Symbolic code, so to say -- i wasn't shure about whether '+' was all-
ready a "generic". Couldn't test my code due to guile segfaulting (see
my bugreport :)
BTW, i'm not really happy with guiles current behavior regarding declaring
a generic that's allready existing. I'd expect that a (define-generic foo)
on a function that's allready will be a no-opt.  The call (and syntax)
of define-generic "feels" like a compiler makro and not like something
that creates a new binding for its only parameter. I just tried my own
code and was astonished to see that after my declaration the primitive
'+' wasn't  reachable anymore :-/ Now, i could (perhaps, i'm an inpatient
person) live with that iff there was an easy way to test whether something
is allready declared generic, but:

 (use-modules (oop goops))
 +
 =>  #<primitive-procedure +>
 (define-method (+ (a <string>) (b <string>)) (string-append a b))
 +
 => #<primitive-generic +>

Humpf! I know, this is actually a nice optimisation in this code, but
it shouldn't be so visible.


[...]
> 
> > In the presence of a generic method system (i.e. function dispatch
> > on the type signature of the arguments) this seems to be rather
> > non-trivial, or do you want to propose to make guile a [statically]
> > typed language ?
> 
> No, no, no. :-) As you can see above, types are still checked at
> run-time, but without having to call out-of-line functions all the
> time.

So, if i understand you right, the compiler would generate code
that contains _two_ branches, one for the fast numeric code 
(inlined) and one for the normal generic  method dispatch?

> > > So my next proposal is to add declarations to variables... :-)
> > 
> > And a type system ;-)
> 
> No, that would be fun, sure, but not in this life...

As long as guile1.6 get's out in time ;-)

 Ralf


> -- 
> GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405




reply via email to

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