unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Marius Vollmer <mvo@zagadka.ping.de>
Cc: tomas@fabula.de, guile-devel@gnu.org
Subject: Re: Smart variables, dumb variables
Date: 15 Aug 2002 18:34:28 +0200	[thread overview]
Message-ID: <87hehwqdwr.fsf@zagadka.ping.de> (raw)
In-Reply-To: <20020815080643.GA8225@www>

rm@fabula.de 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.

Actually, the builtin '+' function is already a generic; you can add
methods to it.  The compiler can not go ahead and inline all of '+',
but it might inline the first type dispatch for fixnums, which should
be by far the most frequent type to occur.

Guile-lightning can do a bit in this direction:

    (define-asm-macro (scm-add res a b)
      (let ((l0 (gensym "ll"))
            (l1 (gensym "ll")))
        `(  (bmc ,l0 ,a (scm 0))
            (bmc ,l0 ,b (scm 0))
            (sub ,res ,a (scm 0))
            (boadd ,l0 ,res ,b)
            (b ,l1)
          ,l0
            (prepare 2)
            (pusharg ,b)
            (pusharg ,a)
            (finish (subr "scm_sum"))
            (retval ,res)
          ,l1)))

This code will check whether the arguments are fixnums , and when both
are, perform the addition inline, checking for overflow.  When one is
not a fixnum, or the addition overflows, we call scm_sum to do it
right.  scm_sum does also include the Goops method dispatch.

This is way faster than having to fetch a value from a variable and
invoke the machinery to call arbitrary functions.

> 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 my next proposal is to add declarations to variables... :-)
> 
> And a type system ;-)

No, that would be fun, sure, but not in this life...

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


_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel


  parent reply	other threads:[~2002-08-15 16:34 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-13 20:06 Smart variables, dumb variables Marius Vollmer
2002-08-14  8:07 ` tomas
2002-08-14 19:35   ` Marius Vollmer
2002-08-14 20:28     ` tomas
2002-08-14 20:48       ` Marius Vollmer
2002-08-14 21:06         ` rm
2002-08-14 21:09           ` Marius Vollmer
2002-08-15  8:06             ` rm
2002-08-15  8:01               ` Lynn Winebarger
2002-08-15  9:51                 ` rm
2002-08-15 14:44               ` Rob Browning
2002-08-15 16:34               ` Marius Vollmer [this message]
2002-08-15 17:27                 ` rm
2002-08-15 19:43                   ` Marius Vollmer
2002-08-15 20:02                     ` rm
2002-08-15 20:02                       ` Marius Vollmer
2002-08-15 20:25                         ` rm
2002-08-17 11:59                         ` Neil Jerram
2002-08-19 23:29                         ` Marius Vollmer
2002-08-20 12:01                           ` rm
2002-08-26 22:06                             ` Marius Vollmer
2002-08-15 10:52         ` tomas
2002-08-15 16:36           ` Marius Vollmer
2002-08-14 21:31 ` Rob Browning
2002-08-14 21:45   ` Marius Vollmer
2002-08-15  2:43 ` Rob Browning
2002-08-15  6:29   ` Marius Vollmer
2002-08-15 14:38     ` Rob Browning

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87hehwqdwr.fsf@zagadka.ping.de \
    --to=mvo@zagadka.ping.de \
    --cc=guile-devel@gnu.org \
    --cc=tomas@fabula.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).