1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-02 02:10:19 +02:00

Move make-object-property out to a module

This will allow for weak tables to be implemented partly in Scheme.

* module/ice-9/object-properties.scm: New file.

* am/bootstrap.am (SOURCES): Add new file.

* module/ice-9/boot-9.scm:
* module/ice-9/deprecated.scm (make-object-property*): Deprecate
make-object-property in default env and add a shim.

* module/ice-9/buffered-input.scm (ice-9):
* module/language/elisp/boot.el (plist-function):
* module/scripts/frisk.scm (scripts):
* module/web/http.scm (web): Adapt users to import the new module.
This commit is contained in:
Andy Wingo 2025-05-06 11:35:40 +02:00
parent 1f96d1bf4b
commit 3a9c0939a0
8 changed files with 67 additions and 35 deletions

View file

@ -160,6 +160,7 @@ SOURCES = \
ice-9/match.scm \
ice-9/networking.scm \
ice-9/null.scm \
ice-9/object-properties.scm \
ice-9/occam-channel.scm \
ice-9/optargs.scm \
ice-9/peg.scm \

View file

@ -823,30 +823,6 @@ VALUE."
(define call/cc call-with-current-continuation)
;;; {General Properties}
;;;
;; Properties are a lispy way to associate random info with random objects.
;; Traditionally properties are implemented as an alist or a plist actually
;; pertaining to the object in question.
;;
;; These "object properties" have the advantage that they can be associated with
;; any object, even if the object has no plist. Object properties are good when
;; you are extending pre-existing objects in unexpected ways. They also present
;; a pleasing, uniform procedure-with-setter interface. But if you have a data
;; type that always has properties, it's often still best to store those
;; properties within the object itself.
(define (make-object-property)
;; Weak tables are thread-safe.
(let ((prop (make-weak-key-hash-table)))
(make-procedure-with-setter
(lambda (obj) (hashq-ref prop obj))
(lambda (obj val) (hashq-set! prop obj val)))))
;;; {Arrays}

View file

@ -1,6 +1,6 @@
;;;; buffered-input.scm --- construct a port from a buffered input reader
;;;;
;;;; Copyright (C) 2001, 2006, 2010 Free Software Foundation, Inc.
;;;; Copyright (C) 2001, 2006, 2010, 2025 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
@ -17,6 +17,7 @@
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
(define-module (ice-9 buffered-input)
#:use-module (ice-9 object-properties)
#:export (make-buffered-input-port
make-line-buffered-input-port
set-buffered-input-continuation?!))

View file

@ -17,8 +17,10 @@
(define-module (ice-9 deprecated)
#:use-module (ice-9 guardians)
#:use-module (ice-9 object-properties)
#:export ((make-guardian* . make-guardian)
module-observe-weak))
module-observe-weak
(make-object-property* . make-object-property)))
#;
(define-syntax-rule (define-deprecated name message exp)
@ -40,3 +42,9 @@ from (ice-9 guardians) instead.")
(issue-deprecation-warning
"module-observe-weak is deprecated. Use module-observe instead.")
(module-observe module proc))
(define (make-object-property*)
(issue-deprecation-warning
"make-object-property in the default environment is deprecated. Import
it from (ice-9 object-properties) instead.")
(make-object-property))

View file

@ -0,0 +1,43 @@
;;; Copyright (C) 2025 Free Software Foundation, Inc.
;;;
;;; This library is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
;;; published by the Free Software Foundation, either version 3 of the
;;; License, or (at your option) any later version.
;;;
;;; This library is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;; Lesser General Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;;;
;;; Properties are a lispy way to associate random info with random
;;; objects. Traditionally properties are implemented as an alist or a
;;; plist actually pertaining to the object in question.
;;;
;;; These "object properties" have the advantage that they can be
;;; associated with any object, even if the object has no plist. Object
;;; properties are good when you are extending pre-existing objects in
;;; unexpected ways. They also present a pleasing, uniform
;;; procedure-with-setter interface. But if you have a data type that
;;; always has properties, it's often still best to store those
;;; properties within the object itself.
;;;
;;; Code:
(define-module (ice-9 object-properties)
;; FIXME: Change to #:export when deprecated bindings removed.
#:replace (make-object-property))
(define (make-object-property)
;; Weak tables are thread-safe.
(let ((prop (make-weak-key-hash-table)))
(make-procedure-with-setter
(lambda (obj) (hashq-ref prop obj))
(lambda (obj val) (hashq-set! prop obj val)))))

View file

@ -1,6 +1,6 @@
;;; Guile Emacs Lisp -*- lexical-binding: t -*-
;;; Copyright (C) 2011 Free Software Foundation, Inc.
;;; Copyright (C) 2011, 2025 Free Software Foundation, Inc.
;;; This library is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU Lesser General Public License as
@ -505,7 +505,8 @@
(defun lax-plist-put (plist property value)
(%plist-put plist property value #'equal))
(defvar plist-function (funcall (@ (guile) make-object-property)))
(defvar plist-function
(funcall (@ (ice-9 object-properties) make-object-property)))
(defun symbol-plist (symbol)
(funcall plist-function symbol))

View file

@ -1,6 +1,6 @@
;;; frisk --- Grok the module interfaces of a body of files
;; Copyright (C) 2002, 2006, 2010, 2011, 2020 Free Software Foundation, Inc.
;; Copyright (C) 2002, 2006, 2010, 2011, 2020, 2025 Free Software Foundation, Inc.
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public License
@ -97,6 +97,7 @@
(define-module (scripts frisk)
#:use-module (ice-9 getopt-long)
#:use-module (ice-9 object-properties)
#:use-module ((srfi srfi-1) :select (filter remove))
#:export (frisk
make-frisker

View file

@ -1,6 +1,6 @@
;;; HTTP messages
;; Copyright (C) 2010-2017, 2023 Free Software Foundation, Inc.
;; Copyright (C) 2010-2017, 2023, 2025 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@ -30,13 +30,14 @@
;;; Code:
(define-module (web http)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-19)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 match)
#:use-module (ice-9 binary-ports)
#:use-module (ice-9 textual-ports)
#:use-module (ice-9 exceptions)
#:use-module (ice-9 match)
#:use-module (ice-9 object-properties)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 textual-ports)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-9)
#:use-module (web uri)
#:export (string->header
header->string