From 06ab5571079885b9c3d6cb780b0527e0a00092ec Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 6 Aug 2023 00:22:59 +0000 Subject: [PATCH 1/4] Change lowercase? and uppercase? for non-alphabetics This is a backwards-incompatible change and will be followed by a commit to increment the major version of the strings package. It's unintuitive for `lowercase?('8')` to return `#t` since being lowercase implies being alphabetic, and similarly for `uppercase?`. So this change makes both `lowercase?('8')` and `uppercase?('8')` return `#f`. What exactly `lowercase?("f8")` should mean is less clear, but as a member of the generic function it should match the method on `` which, I believe, implies that it should be equivalent to `every?(lowercase?, string)`. Because the implementation is trivial and because I can't think of a common use case for this method, I'm removing it entirely and making this a non-generic function. --- documentation/source/index.rst | 96 +++++----------------------------- strings.dylan | 34 +++--------- tests/strings-test-suite.dylan | 22 +++++--- 3 files changed, 35 insertions(+), 117 deletions(-) diff --git a/documentation/source/index.rst b/documentation/source/index.rst index 1e586ee..c5f492d 100644 --- a/documentation/source/index.rst +++ b/documentation/source/index.rst @@ -671,55 +671,20 @@ Case Conversion Functions lowercase!("Hack Dylan!") => error, attempt to modify a string constant -.. generic-function:: lowercase? - :sealed: +.. function:: lowercase? - Returns :drm:`#t` if the argument is entirely composed of - non-uppercase characters. - - :signature: lowercase? (string-or-character) => (is-lowercase?) - :parameter string-or-character: An instance of ``type-union(, )``. - :value is-lowercase?: An instance of :drm:``. - -.. method:: lowercase? - :specializer: - :sealed: - - Returns :drm:`#t` if the given character is not an uppercase alphabetic. - Otherwise :drm:`#f` is returned. + Returns :drm:`#t` if the argument is a lowercase alphabetic character. + Otherwise returns :drm:`#f`. :signature: lowercase? (character) => (is-lowercase?) :parameter character: An instance of :drm:``. :value is-lowercase?: An instance of :drm:``. - :example: - - .. code-block:: dylan - lowercase?('n') => #t - lowercase?('N') => #f - lowercase?('*') => #t - -.. method:: lowercase? - :specializer: - :sealed: - - Returns :drm:`#t` if the argument does not contain any uppercase - alphabetic characters. Otherwise :drm:`#f` is returned. - - :signature: lowercase? (string) => (is-lowercase?) - :parameter string: An instance of :drm:``. - :parameter #key start: An instance of :drm:``, default 0. The index - at which to start checking. - :parameter #key end: An instance of :drm:``, default - ``string.size``. The index before which to stop checking. - :value is-lowercase?: An instance of :drm:``. - :example: - - .. code-block:: dylan + .. code-block:: dylan - lowercase?("Why me?") => #f - lowercase?("Why me?", start: 1) => #t - lowercase?("e.e. cummings") => #t + lowercase?('n') => #t + lowercase?('N') => #f + lowercase?('*') => #f .. generic-function:: uppercase :sealed: @@ -820,54 +785,21 @@ Case Conversion Functions uppercase!("Hack Dylan!") => error, attempt to modify a string constant -.. generic-function:: uppercase? - :sealed: - - Returns :drm:`#t` if the argument is entirely composed of - non-lowercase characters. - - :signature: uppercase? (string-or-character) => (is-uppercase?) - :parameter string-or-character: An instance of ``type-union(, )``. - :value is-uppercase?: An instance of :drm:``. +.. function:: uppercase? -.. method:: uppercase? - :specializer: - :sealed: - - Returns :drm:`#t` if the given character is not a lowercase alphabetic. - Otherwise :drm:`#f` is returned. + Returns :drm:`#t` if the argument is an uppercase alphabetic character. + Otherwise returns :drm:`#f`. :signature: uppercase? (character) => (is-uppercase?) :parameter character: An instance of :drm:``. :value is-uppercase?: An instance of :drm:``. - :example: - - .. code-block:: dylan - - uppercase?('T') => #t - uppercase?('t') => #f - uppercase?('^') => #t - -.. method:: uppercase? - :specializer: - :sealed: - - Returns :drm:`#t` if the argument does not contain any lowercase - alphabetic characters. Otherwise :drm:`#f` is returned. - :signature: uppercase? (string) => (is-uppercase?) - :parameter string: An instance of :drm:``. - :parameter #key start: An instance of :drm:``, default 0. The index - at which to start checking. - :parameter #key end: An instance of :drm:``, default - ``string.size``. The index before which to stop checking. - :value is-uppercase?: An instance of :drm:``. - :example: + .. code-block:: dylan - .. code-block:: dylan + uppercase?('T') => #t + uppercase?('t') => #f + uppercase?('^') => #f - uppercase?("AbC") => #f - uppercase?("ABC") => #t Comparison Functions -------------------- diff --git a/strings.dylan b/strings.dylan index 1e2c00f..59d0b40 100644 --- a/strings.dylan +++ b/strings.dylan @@ -129,43 +129,21 @@ define method whitespace? end; -// Returns #t if the required argument could be a value returned from -// 'as-uppercase'. In other words, if the argument does NOT contain -// any lowercase characters. define sealed generic uppercase? - (string-or-character :: , #key) => (uppercase? :: ); + (char :: ) => (uppercase? :: ); define inline method uppercase? - (char :: , #key) => (b :: ) - ~lowercase-code?(as(, char)) -end; - -define method uppercase? - (string :: , - #key start :: = 0, - end: epos :: = string.size) - => (b :: ) - %every?(uppercase?, string, start, epos) + (char :: ) => (b :: ) + uppercase-code?(as(, char)) end; -// Returns #t if the required argument could be a value returned from -// 'as-lowercase'. In other words, if the argument does NOT contain -// any uppercase characters. define sealed generic lowercase? - (string-or-character :: , #key) => (lowercase? :: ); + (char :: ) => (lowercase? :: ); define inline method lowercase? - (char :: , #key) => (b :: ) - ~uppercase-code?(as(, char)) -end; - -define method lowercase? - (string :: , - #key start :: = 0, - end: epos :: = string.size) - => (b :: ) - %every?(lowercase?, string, start, epos) + (char :: ) => (b :: ) + lowercase-code?(as(, char)) end; diff --git a/tests/strings-test-suite.dylan b/tests/strings-test-suite.dylan index 064f76b..e28c634 100644 --- a/tests/strings-test-suite.dylan +++ b/tests/strings-test-suite.dylan @@ -405,16 +405,24 @@ end test; define test test-lowercase? () check-true("a", lowercase?('a')); - check-true("b", lowercase?("abc-$#^^10")); - check-false("c", lowercase?('A')); - check-false("d", lowercase?("aBc-$#^^10")); + check-true("z", lowercase?('z')); + check-false("A", lowercase?('A')); + check-false("Z", lowercase?('Z')); + check-false("@", lowercase?('@')); + check-false("[", lowercase?('[')); + check-false("`", lowercase?('`')); + check-false("{", lowercase?('{')); end test; define test test-uppercase? () - check-true("a", uppercase?('X')); - check-true("b", uppercase?("ABC-$#^^10")); - check-false("c", uppercase?('b')); - check-false("d", uppercase?("aBc-$#^^10")); + check-true("A", uppercase?('A')); + check-true("Z", uppercase?('Z')); + check-false("a", uppercase?('a')); + check-false("z", uppercase?('z')); + check-false("@", uppercase?('@')); + check-false("[", uppercase?('[')); + check-false("`", uppercase?('`')); + check-false("{", uppercase?('{')); end test; From f2fe29dc4ae0d7c2b2ed8261da46ffbd200e95f0 Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 6 Aug 2023 00:29:53 +0000 Subject: [PATCH 2/4] docs: Remove broken use of dylan.themes in conf.py and simplify --- documentation/source/conf.py | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/documentation/source/conf.py b/documentation/source/conf.py index c77aa86..5065f4f 100644 --- a/documentation/source/conf.py +++ b/documentation/source/conf.py @@ -1,22 +1,12 @@ # Configuration file for the Sphinx documentation builder. -# -# This file only contains a selection of the most common options. For a full -# list see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html -# -- Path setup -------------------------------------------------------------- - -# If extensions (or modules to document with autodoc) are in another directory, -# add these directories to sys.path here. If the directory is relative to the -# documentation root, use os.path.abspath to make it absolute, like shown here. - import os import sys sys.path.insert(0, os.path.abspath('../../_packages/sphinx-extensions/current/src/sphinxcontrib')) import dylan.domain -import dylan.themes as dylan_themes # -- Project information ----------------------------------------------------- @@ -38,9 +28,6 @@ 'sphinx.ext.intersphinx' ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] - # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. @@ -52,22 +39,5 @@ # without depending on this top-level config file. primary_domain = 'dylan' - -# -- Options for HTML output ------------------------------------------------- - -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = dylan_themes.get_html_theme_default() - -# Theme options are theme-specific and customize the look and feel of a theme -# further. For a list of options available for each theme, see the -# documentation. -html_theme_options = dylan_themes.get_html_theme_options_default() - -# Add any paths that contain custom themes here, relative to this directory. -html_theme_path = [dylan_themes.get_html_theme_path()] - -# Add any paths that contain custom static files (such as style sheets) here, -# relative to this directory. They are copied after the builtin static files, -# so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +# sudo pip install -U furo +html_theme = 'furo' From 89a80948905973f12d078c2ce2c6b7729b656d6e Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 6 Aug 2023 00:34:33 +0000 Subject: [PATCH 3/4] docs: contents:: -> toctree:: This works better with the Furo theme. --- documentation/source/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/source/index.rst b/documentation/source/index.rst index c5f492d..581e4a2 100644 --- a/documentation/source/index.rst +++ b/documentation/source/index.rst @@ -11,8 +11,8 @@ The *strings* library was originally defined in `DEP-0004 `_. Some additional background material can be found there. -.. contents:: Contents - :local: +.. toctree:: + :hidden: .. note:: From b5f5d15ebc7800f69cc4edeb0c7fc6fe7ca9db2b Mon Sep 17 00:00:00 2001 From: Carl Gay Date: Sun, 6 Aug 2023 00:38:55 +0000 Subject: [PATCH 4/4] Update package version to 2.0.0 due to incompatible change --- documentation/source/conf.py | 2 +- dylan-package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/source/conf.py b/documentation/source/conf.py index 5065f4f..404e579 100644 --- a/documentation/source/conf.py +++ b/documentation/source/conf.py @@ -15,7 +15,7 @@ author = 'Carl Gay' # The full version, including alpha/beta/rc tags -release = 'v1.2.0' +release = 'v2.0.0' # -- General configuration --------------------------------------------------- diff --git a/dylan-package.json b/dylan-package.json index 87a369c..2c1d4fb 100644 --- a/dylan-package.json +++ b/dylan-package.json @@ -7,6 +7,6 @@ ], "description": "String manipulation functions", "name": "strings", - "version": "1.2.0", + "version": "2.0.0", "url": "https://github.com/dylan-lang/strings" }