From: rtoy <rt...@us...> - 2024-09-30 21:46:17
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Maxima CAS". The branch, rtoy-defmvar-add-string-decl has been created at 7d8490458cd4c0192a9d3f1135bb297b3557ac4d (commit) - Log ----------------------------------------------------------------- commit 7d8490458cd4c0192a9d3f1135bb297b3557ac4d Author: Raymond Toy <toy...@gm...> Date: Mon Sep 30 14:45:17 2024 -0700 Add comments, fix docstring for defmvar We also update the docstring for BOOLEAN because we do support this declaration. diff --git a/src/globals.lisp b/src/globals.lisp index 1144a63cc..107628de4 100644 --- a/src/globals.lisp +++ b/src/globals.lisp @@ -40,8 +40,15 @@ NO-RESET - If given, the variable will not be reset. - FIXNUM, BOOLEAN, STRING, FLONUM + FIXNUM, FLONUM - The type of variable. Currently ignored. + BOOLEAN, STRING + - Declares the variable to have this type and adds a property + so that this variable can only be assigned an appropriate type. + This takes precedence over other options so :SETTING-PREDICATE, + and :SETTING-LIST cannot also be specified. In addition, + :PROPERTIES can be specified, but it cannot contain an + ASSIGN property. :PROPERTIES - A list of properties to be applied for this variable. It is a list of lists. Each sublist is a list of the property and @@ -129,6 +136,9 @@ ;; Ignore this ) (string + ;; Declares the variable to be a string and adds a predicate + ;; to verify that only strings can be assigned to the + ;; variable. (let ((assign-func `#'(lambda (var val) (unless (stringp val) @@ -256,12 +266,14 @@ (warn "Ignoring unknown defmvar option for ~S: ~S" var (car opts))))) (flet ((validate-type-predicate (type-predicate type-name) + "If TYPE-PREDICATE is non-NIL, verify that the other options like + :SETTING-PREDICATE, :SETTING-LIST, and :PROPERTIES option + has an ASSIGN property are not also given. The type + declaration takes precedence." (when type-predicate (if (or setting-predicate-p setting-list-p assign-property-p) (error "Do not use ~A option when :SETTING-PREDICATE, :SETTING-LIST, or :PROPERTIES is used." type-name) - ;; Check that boolean predicate isn't used with any other - ;; predicate. The other predicates supersede boolean. (setf maybe-predicate type-predicate))))) (validate-type-predicate maybe-boolean-predicate "BOOLEAN") (validate-type-predicate maybe-string-predicate "STRING")) commit baf1b505937a0054ff29166addbbf116def093a5 Author: Raymond Toy <toy...@gm...> Date: Mon Sep 30 14:36:23 2024 -0700 Support STRING declaration in DEFMVAR If `defmvar` includes the `string` declaration, actually declare the variable to be a string and also provide an `assign` property so that only strings can be assigned to the variable. Updated stringproc.lisp to use this string declaration instead of a `:setting-predicate`. diff --git a/share/stringproc/stringproc.lisp b/share/stringproc/stringproc.lisp index 42f0028cf..b80f67a74 100644 --- a/share/stringproc/stringproc.lisp +++ b/share/stringproc/stringproc.lisp @@ -728,21 +728,15 @@ Please use `unicode' for code points larger than 127." ))) ;; (defmvar $newline (string #\newline) "Maxima newline character" - :setting-predicate #'(lambda (x) - (values (stringp x) - "must be a string"))) + string) (defmvar $tab (string #\tab) "Maxima tab character" - :setting-predicate #'(lambda (x) - (values (stringp x) - "must be a string"))) + string) (defmvar $space (string #\space) "Maxima space character" - :setting-predicate #'(lambda (x) - (values (stringp x) - "must be a string"))) + string) (defun $tab () $tab) ;; returns Maxima tab character; can be autoloaded diff --git a/src/globals.lisp b/src/globals.lisp index f6b139c04..1144a63cc 100644 --- a/src/globals.lisp +++ b/src/globals.lisp @@ -92,6 +92,7 @@ maybe-set-props maybe-predicate maybe-boolean-predicate + maybe-string-predicate setting-predicate-p setting-list-p assign-property-p @@ -106,7 +107,7 @@ (unless deprecated-p ;; Don't reset the value (setf maybe-reset nil))) - ((fixnum string flonum) + ((fixnum flonum) ;; Don't declare the types yet. There are testsuite failures ;; with sbcl that some things declared fixnum aren't assigned ;; fixnum values. Some are clearly bugs in the code where we @@ -127,6 +128,15 @@ (in-core ;; Ignore this ) + (string + (let ((assign-func + `#'(lambda (var val) + (unless (stringp val) + (mseterr var val "must be a string"))))) + (setf maybe-declare-type + `((declaim (string ,var)))) + (setf maybe-string-predicate + `((putprop ',var ,assign-func 'assign))))) (boolean ;; Vars declared as boolean create a setting-list so that ;; only true and false can be assigned to the variable. @@ -245,13 +255,17 @@ (t (warn "Ignoring unknown defmvar option for ~S: ~S" var (car opts))))) - (when maybe-boolean-predicate - (if (or setting-predicate-p setting-list-p assign-property-p) - (error "Do not use BOOLEAN option when :SETTING-PREDICATE, :SETTING-LIST, or :PROPERTIES is used") - ;; Check that boolean predicate isn't used with any other - ;; predicate. The other predicates supersede boolean. - (setf maybe-predicate maybe-boolean-predicate))) - + (flet ((validate-type-predicate (type-predicate type-name) + (when type-predicate + (if (or setting-predicate-p setting-list-p assign-property-p) + (error "Do not use ~A option when :SETTING-PREDICATE, :SETTING-LIST, or :PROPERTIES is used." + type-name) + ;; Check that boolean predicate isn't used with any other + ;; predicate. The other predicates supersede boolean. + (setf maybe-predicate type-predicate))))) + (validate-type-predicate maybe-boolean-predicate "BOOLEAN") + (validate-type-predicate maybe-string-predicate "STRING")) + `(progn ,@maybe-reset ,@maybe-declare-type ----------------------------------------------------------------------- hooks/post-receive -- Maxima CAS |