[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No gh_set_x()?
From: |
Dirk Esser |
Subject: |
Re: No gh_set_x()? |
Date: |
Fri, 13 Jul 2001 11:17:24 +0200 (MEST) |
On Tue, 10 Jul 2001, Sam Tregar <address@hidden> wrote:
> Hey guys. I'm working on a Perl binding for Guile
> and I've run into a problem - I need a gh_set_x() but
> it doesn't seem to exist. I'm working on overloading
> the special "+=" type arithmetic on the Perl side and I
> need to set the left-hand SCM to the value produced by
> the addition.
Well, the others did get your point, I did not. Are you writing an
interface, which allows Perl code to use the Guile library (in the
way one would say: "...the Gtk library"), or is it just the other
way around? (Did I mention that english is not my first language --
must I mention, that english is not my first language... B-)?
Anyway, not having understood the problem won´t stop me from
providing a solution...
I am not really sure, what you are going to do, but why do
you insist on doing it in C -- implementing "+=" as a Scheme
macro is straightforward and simple:
(defmacro += (var . forms)
(quasiquote(set! ,var (+ ,var ,@forms))))
If you prefer to have full C-style += semantics, including
the return value, try this instead:
(defmacro += (var . forms)
(quasiquote (begin (set! ,var (+ ,var ,@forms))
,var)))
This can then be used from Scheme code like
(let ((x 10) (y 0))
(+= x y)
(+= y 1)
(display x)
(newline)
(display y))
Should print 10 for x and 1 for y (did not test it -- bug reports
wellcome... B-). C´s ++/-- operators can be implemented just as
easily (and by reusing the 2nd definition above):
(defmacro ++ (var)
(quasiquote (+= ,var 1))) ;; similar for --
The only thing, which cannot be implemented this way is the different
behvaiour of ++/-- depending on whether they are used in pre- or
postfix position.
BTW: When Guile supports the SFRI generalized set! implementation,
the macros above would also work in places like:
(define a-vector (vector 0 1 2 3 4 5 6))
(++ (vector-ref a-vector 4))
which would be somehting like a_vector[4]++; in C.
mfg
dirk
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net
GMX Tipp:
Machen Sie Ihr Hobby zu Geld bei unserem Partner 1&1!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, (continued)
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Sam Tregar, 2001/07/13
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Klaus Schilling, 2001/07/13
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Alex Shinn, 2001/07/13
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, rm, 2001/07/14
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Alex Shinn, 2001/07/14
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Thomas Bushnell, BSG, 2001/07/13
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Thien-Thi Nguyen, 2001/07/14
- Re: Gurus? Care to re-explain the absense of gh_set_x() for me?, Martin Grabmueller, 2001/07/14
- Guile At Work (was Re: Gurus? Care to re-explain the absense of gh_set_x() for me?), Evan Prodromou, 2001/07/14
- Re: Guile At Work (was Re: Gurus? Care to re-explain the absense of gh_set_x() for me?), Thien-Thi Nguyen, 2001/07/14
Re: No gh_set_x()?,
Dirk Esser <=
Re: No gh_set_x()?, Steven G. Johnson, 2001/07/16