This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Suggestion for strings.c


Jost Boekemeier <jostobfe@calvados.zrz.TU-Berlin.DE> writes:

> P.S.: Per's SRFI seems to suggest that we'll have to re-introduce
> first class locations after ... :)

[ ignore me if I have no sense of humour ]

Jost, you seem to be lost in thousand twisty little C statements, some
of them alike.

here is what Per is talking about (well, I assume so).  it needs *no*
C-level support at all.

;; -*- scheme -*-
;; locations.scm: lvalues, the Scheme way.

(define-module (locations)
  #:use-module (ice-9 and-let*))

(export-syntax location)

;; (location <form>) returns a procedure P.
;; calling (P) returns the value of <form>.
;; calling (set! (P) <new-value>) changes the value of <form>.
;; the above means that <form> can be either ordinary variable reference
;; or a call to some procedure with setter.

(defmacro location (place)
  (let* ((v (gensym 'location-value))
         (trans `(make-procedure-with-setter
                  (lambda () ,place)
                  (lambda (,v) (set! ,place ,v)))))
    (cond
     ((symbol? place)
      trans)
     ((pair? place)
      (if (not (and-let* ((proc (car place))
                          ((symbol? proc))
                          (proc (eval proc)))
                 (procedure-with-setter? proc)))
          (throw 'invalid-location place))
      trans)
     (else
      (throw 'invalid-location place)))))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]