From: Thomas Walker Lynch Date: Wed, 30 Oct 2024 10:06:01 +0000 (+0000) Subject: refactor Util quantifiers X-Git-Url: https://git.reasoningtechnology.com/usr/lib/python2.7/threading.py?a=commitdiff_plain;h=4717636150370f70e4589cafeab51b2f6881e140;p=Mosaic refactor Util quantifiers --- diff --git a/developer/document/nomenclature.txt b/developer/document/nomenclature.txt deleted file mode 100644 index 633dc4a..0000000 --- a/developer/document/nomenclature.txt +++ /dev/null @@ -1,3 +0,0 @@ - -wellformed is a single word. Its antonym is 'malformed'. Wellformed syntax -parses without errors. diff --git a/developer/document/unique_node_label_check.txt b/developer/document/unique_node_label_check.txt deleted file mode 100644 index b978a74..0000000 --- a/developer/document/unique_node_label_check.txt +++ /dev/null @@ -1,15 +0,0 @@ - -predicate == is_well_formed_q - -We can not check that the node labels are unique because the given value -is a single node, and the code is stateless. Besides there is no contract with -the programmer on how to use the predicated, so the programmer could call the -predicate multiple times on the same node. Now can we test this condition in -our do_markup_graph routine because of the way lookup works, it will always -return the same node for the same label. This would be a truly difficult check -to perform because the map does not given an error but just takes the second of -the duplicate key definitions (is this really true?) besides, it would require -a formal proof of the recognizer functions that they do not return different -definitions for different keys to match regexprs against. I've been mulling -this over. As we currently the programmer provides the map and function -definitions, we don't even know which nodes will be in the graph... diff --git a/developer/document/variable_suffix_conventions.txt b/developer/document/variable_suffix_conventions.txt index e5ef76e..e3ad587 100644 --- a/developer/document/variable_suffix_conventions.txt +++ b/developer/document/variable_suffix_conventions.txt @@ -15,9 +15,13 @@ Instead of making a variable name plural, add the interface qualifier. ## Always a good idea to use these when working with files - `_fp`: Refers to a file path. The part after the last slash is a file name. + +- `_afp`: Refers to an absolute file path. - `_dp`: Refers to a directory path. By convention, the value ends in a slash. +- `_adp`: Refers to an absolute directory path. + - `_fn`: Refers to a file name. Value has no slashes. - `_dn`: Refers to a directory name. Value has no slashes. diff --git a/developer/javac/Mosaic.java b/developer/javac/Mosaic.java index d20baae..8ab7fe7 100644 --- a/developer/javac/Mosaic.java +++ b/developer/javac/Mosaic.java @@ -14,13 +14,14 @@ public class Mosaic{ } public static int run(){ - System.out.println("Mosic currently does not have a shell user interface."); + System.out.println("Main function placeholder. Currently Mosaic is used by extending the TestBench class."); return 0; } - // Main function to provide a shell interface for running tests - public static int main(String[] args){ - // currently accepts no arguments or options - return run(); + public static void main(String[] args){ + int return_code = run(); + System.exit(return_code); + return; } + } diff --git a/developer/javac/Util.java b/developer/javac/Util.java index 45f2a53..1757275 100644 --- a/developer/javac/Util.java +++ b/developer/javac/Util.java @@ -9,17 +9,28 @@ import java.lang.reflect.Method; import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.util.function.Predicate; public class Util{ - // Typically used to gather conditions before returning a test result. - // As this is used for testing, and an empty conditions list is unusual, - // returns false for an empty conditions list. - public static boolean all(boolean[] conditions){ - if( conditions.length == 0 ) return false; - for(boolean condition : conditions) if(!condition) return false; - return true; + // Linear search with a predicate + public static T find( T[] elements ,Predicate predicate ){ + for( T element : elements ){ + if( predicate.test( element )) return element; // Return the first match + } + return null; // Return null if no element satisfies the predicate + } + + // True when it does a search and finds a true value; otherwise false. + public static boolean exists( Object[] elements ){ + return elements.length > 0 && find( elements ,element -> (element instanceof Boolean) && (Boolean) element ) != null; } + + // True when it does a search and does not find a false value; otherwise false. + public static boolean all( Object[] elements ){ + return elements.length > 0 && find( elements ,element -> !(element instanceof Boolean) || !(Boolean) element ) == null; + } + public static void all_set_false(boolean[] conditions){ for(boolean condition : conditions) condition = false; } diff --git a/developer/tool/clean_build_directories b/developer/tool/clean_build_directories index 8990e26..4e2d60e 100755 --- a/developer/tool/clean_build_directories +++ b/developer/tool/clean_build_directories @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # Removes all files found in the build directories. It asks no questions as to # how or why the files got there. Be especially careful with the 'shell' directory diff --git a/developer/tool/clean_javac_output b/developer/tool/clean_javac_output index 1f94c43..5ebeb51 100755 --- a/developer/tool/clean_javac_output +++ b/developer/tool/clean_javac_output @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # remove all files created by make's call to `javac` # input guards diff --git a/developer/tool/clean_make_output b/developer/tool/clean_make_output index af7c00a..a7c6ebf 100755 --- a/developer/tool/clean_make_output +++ b/developer/tool/clean_make_output @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # remove all files made by `make` # input guards diff --git a/developer/tool/clean_release b/developer/tool/clean_release index ec10d91..a33f19a 100755 --- a/developer/tool/clean_release +++ b/developer/tool/clean_release @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # remove files made by `make` and by `release` # input guards diff --git a/developer/tool/distribute_source b/developer/tool/distribute_source index 003dd3d..faf844d 100755 --- a/developer/tool/distribute_source +++ b/developer/tool/distribute_source @@ -1,4 +1,5 @@ #!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # This script links the sources into the directory tree in parallel to the package. diff --git a/developer/tool/make b/developer/tool/make index 16b477b..be84a0e 100755 --- a/developer/tool/make +++ b/developer/tool/make @@ -1,4 +1,5 @@ #!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # input guards diff --git a/developer/tool/release b/developer/tool/release index 9ca9125..bcf4686 100755 --- a/developer/tool/release +++ b/developer/tool/release @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # input guards diff --git a/developer/tool/shell_wrapper_list b/developer/tool/shell_wrapper_list index 67f7b2b..c95affe 100755 --- a/developer/tool/shell_wrapper_list +++ b/developer/tool/shell_wrapper_list @@ -1,4 +1,5 @@ #!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # input guards diff --git a/document/return_script_name.txt b/document/return_script_name.txt new file mode 100644 index 0000000..43738db --- /dev/null +++ b/document/return_script_name.txt @@ -0,0 +1,39 @@ + +I had a lot of problems in bash scripting language, while trying to export a +function that could report the name of the script it was called in. + +1. + +BASH_SOURCE[0] was used because $0 did not work with sourced scripts (a +fact that is leveraged for detecting when in a sourced script). + +2. + +Hence, this did not work in general: + + read -r -d '' script_afp_string <<'EOF' + realpath "${BASH_SOURCE[0]}" 2>/dev/null + EOF + + script_afp(){ + eval "$script_afp_string" + } + + export script_afp_string + export -f script_afp + +When `script_afp` was exported, used in another file, and used within a function +in that other file, it reported `environment` for the script name at +BASH_SOURCE[0]. In various call scenarios the actual script name appears at +BASH_SOURCE[1] or even at BASH_SOURCE[2]. + +3. + +As a stable alternative to having a script_afp function, place this line +at the top of scripts that use the `script_XX` functions, or at the top +of all scripts: + + script_afp=realpath "${BASH_SOURCE[0]}" + +Then use $script_afp as a string within other functions. It will have stable +value no matter the call structure. diff --git a/document/todo.txt b/document/todo.txt index 7f86390..6ff1508 100644 --- a/document/todo.txt +++ b/document/todo.txt @@ -24,6 +24,8 @@ Updates for Ariadne 5. make_source_tree also integrated into make -6. replacement for bespoke/env and all other env files +6. replacement for bespoke/env and all other env files, related document. + + diff --git a/release/Mosaic.jar b/release/Mosaic.jar deleted file mode 100644 index aa4a400..0000000 Binary files a/release/Mosaic.jar and /dev/null differ diff --git a/tester/alias/com/ReasoningTechnology/Mosaic/Test b/tester/alias/com/ReasoningTechnology/Mosaic/Test deleted file mode 120000 index 6af8f49..0000000 --- a/tester/alias/com/ReasoningTechnology/Mosaic/Test +++ /dev/null @@ -1 +0,0 @@ -/var/user_data/Thomas-developer/Mosaic//tester/javac \ No newline at end of file diff --git a/tester/document/emacs_jdb.txt b/tester/document/emacs_jdb.txt deleted file mode 100644 index ff124a4..0000000 --- a/tester/document/emacs_jdb.txt +++ /dev/null @@ -1,18 +0,0 @@ - -jdb will be in the third_party tools directory: - - 2024-10-27T09:34:37Z[Mosaic_tester] - Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§ - > which jdb - /var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin/jdb - -If Emacs has been run from outside of `env_developer` or `env_tester` then -emacs will not see the path to tool_shared/third_party. Emacs can be told -explicitly: - - (setenv "PATH" (concat (getenv "PATH") ":/var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin")) - (setq exec-path (append exec-path '("/var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin"))) - -but this probably won't work as other things will also be missing from the -environment.So either run emacs in the correct environment, or run jdb from a -shell after sourcing the environment. diff --git a/tester/document/jdb.txt b/tester/document/jdb.txt new file mode 100644 index 0000000..14cceb2 --- /dev/null +++ b/tester/document/jdb.txt @@ -0,0 +1,45 @@ + +1. location + + jdb will be in the third_party tools directory: + + 2024-10-27T09:34:37Z[Mosaic_tester] + Thomas-developer@Blossac§/var/user_data/Thomas-developer/Mosaic/tester§ + > which jdb + /var/user_data/Thomas-developer/Mosaic/tool_shared/third_party/jdk-11/bin/jdb + +2. IDE and the environment + + The environment must be set before running the IDE or the IDE will not + have access to it. + + For example Emacs will be following the PATH as it was when Emacs + was invoked, for file completion in the Emacs shell, etc. Even when + the environment is set in a shell running inside of emacs. + + FYI, the path can be fixed but other environment settings will still be missing. + (setenv "PATH" (concat (getenv "PATH") ":")) + (setq exec-path (append exec-path '(" + + currently, in emacs, e.g.: + jdb -sourcepathjavac Test_Util + + When invoked from Emacs M-x jdb, there is no space between the -sourcepath and + the $SOURCEPATH. + + In jdb run from gud-gdb, when packages are used, the SOURCEPATH is the path + to the directory that holds a directory tree, where said directory tree + parallels the package name. Otherwise it is the directory path to the source + directory. Note the `distribute_sources` script. + + When using packages, the is fully qualified. + + + diff --git a/tester/jvm/Test_Mosaic.jar b/tester/jvm/Test_Mosaic.jar new file mode 100644 index 0000000..5e80583 Binary files /dev/null and b/tester/jvm/Test_Mosaic.jar differ diff --git a/tester/shell/Test0 b/tester/shell/Test0 new file mode 100755 index 0000000..5b3584f --- /dev/null +++ b/tester/shell/Test0 @@ -0,0 +1,2 @@ +#!/bin/env bash +java Test0 diff --git a/tester/shell/Test_IO b/tester/shell/Test_IO new file mode 100755 index 0000000..72977e7 --- /dev/null +++ b/tester/shell/Test_IO @@ -0,0 +1,2 @@ +#!/bin/env bash +java Test_IO diff --git a/tester/shell/Test_Util b/tester/shell/Test_Util new file mode 100755 index 0000000..0e4ba3d --- /dev/null +++ b/tester/shell/Test_Util @@ -0,0 +1,2 @@ +#!/bin/env bash +java Test_Util diff --git a/tester/tool/#run_jdb# b/tester/tool/#run_jdb# new file mode 100755 index 0000000..9c472f4 --- /dev/null +++ b/tester/tool/#run_jdb# @@ -0,0 +1,12 @@ +#!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") + +# input guards +env_must_be="tester/tool/env" +if [ "$ENV" != "$env_must_be" ]; then + echo "$(script_fp):: error: must be run in the $env_must_be environment" + exit 1 +fi + +jdb -sourcepath "$SOURCEPATH" "$@" + diff --git a/tester/tool/env b/tester/tool/env index 322258e..e73741c 100644 --- a/tester/tool/env +++ b/tester/tool/env @@ -29,6 +29,11 @@ export CLASSPATH=\ :"$REPO_HOME"/tester/jvm/Test_"$PROJECT".jar\ :"$CLASSPATH" +export SOURCEPATH=\ +"$REPO_HOME"/tester/javac/\ +:"$REPO_HOME"/developer/scratchpad/\ + + # misc # make .githolder and .gitignore visible diff --git a/tester/tool/make b/tester/tool/make index e125d92..deae0a1 100755 --- a/tester/tool/make +++ b/tester/tool/make @@ -24,7 +24,7 @@ echo "Creating shell wrappers..." for file in $wrapper;do cat > shell/$file << EOL #!/bin/env bash -java com.ReasoningTechnology.$PROJECT.Test.$file +java $file EOL chmod +x shell/$file done diff --git a/tester/tool/run_jdb b/tester/tool/run_jdb new file mode 100755 index 0000000..65b05c4 --- /dev/null +++ b/tester/tool/run_jdb @@ -0,0 +1,11 @@ +#!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") + +# input guards +env_must_be="tester/tool/env" +if [ "$ENV" != "$env_must_be" ]; then + echo "$(script_fp):: error: must be run in the $env_must_be environment" + exit 1 +fi + +jdb -sourcepath "$SOURCEPATH" "$@" diff --git a/tester/tool/shell_wrapper_list b/tester/tool/shell_wrapper_list index 74933cb..aec2e97 100755 --- a/tester/tool/shell_wrapper_list +++ b/tester/tool/shell_wrapper_list @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/env bash script_afp=$(realpath "${BASH_SOURCE[0]}") # input guards diff --git a/tool_shared/bespoke/cat_w_fn b/tool_shared/bespoke/cat_w_fn index f8d02cd..89166b6 100755 --- a/tool_shared/bespoke/cat_w_fn +++ b/tool_shared/bespoke/cat_w_fn @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # Check if at least one file is provided if [ $# -eq 0 ]; then diff --git a/tool_shared/bespoke/deprecate b/tool_shared/bespoke/deprecate index 124ffed..4713db5 100755 --- a/tool_shared/bespoke/deprecate +++ b/tool_shared/bespoke/deprecate @@ -1,12 +1,12 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # cp subtree at under file path , and make all the copied # files read-only. The intended use case is for moving files to a `deprecated` # directory. This helps prevent subsequent accidental editing. -SCRIPT_NAME=$(basename "$0") if [ "$#" -lt 2 ]; then - echo "Usage: $SCRIPT_NAME " + echo "Usage: $script_afp " exit 1 fi SRC="$1" diff --git a/tool_shared/bespoke/env b/tool_shared/bespoke/env index 59f8f96..4fa561b 100644 --- a/tool_shared/bespoke/env +++ b/tool_shared/bespoke/env @@ -5,47 +5,37 @@ if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then exit 1 fi -# This is the base environment shared by all roles in the project. +# -------------------------------------------------------------------------------- +# project definition -# The project administrator sets up the following tools for all roles to use: -# - export JAVA_HOME="$REPO_HOME/tool_shared/third_party/jdk-11" - -# Absolute path to script file. The use of eval makes it suitable for exporting -# and use with other scripts -# -# IMHO it is not possible write a function in bash that reliably returns the -# script's path in all execution scenarios of direct execute, sourcing, and -# usage in other functions. So instead, define a variable script_afp at the top -# of each script: -# -# script_afp=realpath "${BASH_SOURCE[0]}" -# -# read -r -d '' script_afp_string <<'EOF' -# realpath "${BASH_SOURCE[0]}" 2>/dev/null -# EOF -# script_afp(){ -# eval "$script_afp_string" -# } +# actual absolute director path for this script file script_adp(){ dirname "$script_afp" } - -# This script assumes it is located at $REPO_HOME/tools_shared/bespoke and works -# backwards to recover $REPO_HOME, etc. +# assume this script is located $REPO_HOME/tools_shared/bespoke and work backwards +# to get $REPO_HOME, etc. REPO_HOME=$(dirname "$(dirname "$(script_adp)")") echo REPO_HOME "$REPO_HOME" PROJECT=$(basename "$REPO_HOME") echo PROJECT "$PROJECT" + + # set the prompt decoration to the name of the project PROMPT_DECOR=$PROJECT +# -------------------------------------------------------------------------------- +# The project administrator sets up the following tools for all roles to use: +# + export JAVA_HOME="$REPO_HOME/tool_shared/third_party/jdk-11" -# These functions are offered as a convenience to be run inside other scripts. -# These produce $REPO_HOME relative results, and thus preferred over script_adp. +# -------------------------------------------------------------------------------- +# the following functions are provided for other scripts to use. +# at the top of files that make use of these functions put the following line: +# script_afp=$(realpath "${BASH_SOURCE[0]}") +# ## script's filename script_fn(){ @@ -62,12 +52,12 @@ fi dirname "$(script_fp)" } -# Exports, and give the exported environment a name +# -------------------------------------------------------------------------------- +# Exports # Bash has no 'closure' hence when exporting a function, one must also export all the pieces. +# do not export script_afp export REPO_HOME PROJECT PROMPT_DECOR -# export script_afp_string -# export -f script_afp script_adp script_fn script_dp script_fp export -f script_adp script_fn script_dp script_fp export ENV=$(script_fp) diff --git a/tool_shared/bespoke/env4 b/tool_shared/bespoke/env4 deleted file mode 100644 index 39abce6..0000000 --- a/tool_shared/bespoke/env4 +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env bash -script_afp=$(realpath "${BASH_SOURCE[0]}") - -# This is the base environment shared by all roles in the project. - -# The project administrator sets up the following tools for all roles to use: -# - export JAVA_HOME="$REPO_HOME/tool_shared/third_party/jdk-11" - -# Absolute path to script file. The use of eval makes it suitable for exporting -# and use with other scripts -# -# IMHO it is not possible write a function in bash that reliably returns the -# script's path in all execution scenarios of direct execute, sourcing, and -# usage in other functions. So instead, define a variable script_afp at the top -# of each script: -# -# script_afp=realpath "${BASH_SOURCE[0]}" -# -# read -r -d '' script_afp_string <<'EOF' -# realpath "${BASH_SOURCE[0]}" 2>/dev/null -# EOF -# script_afp(){ -# eval "$script_afp_string" -# } - - script_adp(){ - dirname "$script_afp" - } - - -# This script assumes it is located at $REPO_HOME/tools_shared/bespoke and works -# backwards to recover $REPO_HOME, etc. - - REPO_HOME=$(dirname "$(dirname "$(script_adp)")") - echo REPO_HOME "$REPO_HOME" - - PROJECT=$(basename "$REPO_HOME") - echo PROJECT "$PROJECT" - PROMPT_DECOR=$PROJECT - - -# These functions are offered as a convenience to be run inside other scripts. -# These produce $REPO_HOME relative results, and thus preferred over script_adp. - - ## script's filename - script_fn(){ - basename "$script_afp" - } - - ## script's dirpath relative to $REPO_HOME - script_fp(){ - realpath --relative-to="${REPO_HOME}" "$script_afp" - } - - ## script's dirpath relative to $REPO_HOME - script_dp(){ - dirname "$(script_fp)" - } - -# Exports, and give the exported environment a name -# Bash has no 'closure' hence when exporting a function, one must also export all the pieces. - - export REPO_HOME PROJECT PROMPT_DECOR -# export script_afp_string -# export -f script_afp script_adp script_fn script_dp script_fp - export -f script_adp script_fn script_dp script_fp - - export ENV=$(script_fp) - echo ENV "$ENV" - -echo -echo "--------------------------------------------------------------------------------" -echo "from within, at the end, of test_shared/bespoke/env the script functions return the following." -echo -echo "REPO_HOME:" "$REPO_HOME" -echo "PROJECT:" "$PROJECT" -echo "script_afp:" "$script_afp" -echo "script_adp:" "$(script_adp)" -echo "script_fn:" "$(script_fn)" -echo "script_fp:" "$(script_fp)" -echo "script_dp:" "$(script_dp)" -echo "ENV:" "$ENV" -echo "---------" -echo "the stack" - top_index=$(( ${#BASH_SOURCE[@]} - 1 )) - for (( i=0; i<=top_index; i++ )); do - echo "$i: ${BASH_SOURCE[$i]}" - done - diff --git a/tool_shared/bespoke/version b/tool_shared/bespoke/version index 5b99cbb..3a9dd05 100755 --- a/tool_shared/bespoke/version +++ b/tool_shared/bespoke/version @@ -1,4 +1,5 @@ #!/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # 2024-10-24T14:56:09Z project skeleton and test bench files extracted from Ariadne echo v0.1 diff --git a/tool_shared/bespoke/vl b/tool_shared/bespoke/vl index 94fe14d..2c968d3 100755 --- a/tool_shared/bespoke/vl +++ b/tool_shared/bespoke/vl @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # vl 'vertical list' # Check if the command is provided diff --git a/tool_shared/bespoke/wipe_release b/tool_shared/bespoke/wipe_release index d92cc88..5bac0e7 100755 --- a/tool_shared/bespoke/wipe_release +++ b/tool_shared/bespoke/wipe_release @@ -1,4 +1,5 @@ #!/usr/bin/env bash +script_afp=$(realpath "${BASH_SOURCE[0]}") # remove all files in the release directory set -e