diff --git a/.gitignore b/.gitignore index 2249be9..8d948cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -cpp/hello-world/.exercism/metadata.json +*/*/.exercism/metadata.json + diff --git a/cpp/hello-world/.gitignore b/cpp/.gitignore similarity index 100% rename from cpp/hello-world/.gitignore rename to cpp/.gitignore diff --git a/yamlscript/.gitignore b/yamlscript/.gitignore new file mode 100644 index 0000000..1f59062 --- /dev/null +++ b/yamlscript/.gitignore @@ -0,0 +1 @@ +/.local/ diff --git a/yamlscript/hello-world/.exercism/config.json b/yamlscript/hello-world/.exercism/config.json new file mode 100644 index 0000000..84f96be --- /dev/null +++ b/yamlscript/hello-world/.exercism/config.json @@ -0,0 +1,23 @@ +{ + "authors": [ + "ingydotnet" + ], + "contributors": [ + "m-dango" + ], + "files": { + "solution": [ + "hello-world.ys" + ], + "test": [ + "hello-world-test.ys", + "Makefile" + ], + "example": [ + ".meta/hello-world.ys" + ] + }, + "blurb": "Exercism's classic introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/yamlscript/hello-world/.yamlscript/exercism-ys-installer b/yamlscript/hello-world/.yamlscript/exercism-ys-installer new file mode 100644 index 0000000..ae3fa01 --- /dev/null +++ b/yamlscript/hello-world/.yamlscript/exercism-ys-installer @@ -0,0 +1,127 @@ +#!/env/bin/env bash + +set -euo pipefail + +intro-prompt() ( + cat <<... +-------------------------------------------------------------------------------- + +This YAMLScript Exercism exercise requires the YAMLScript version $version +interpreter command file to be installed here: + + $prefix/bin/ys + +You can install it by pressing Enter now, or by running this command: + + $make install-ys + +This should only take a few seconds and you only need to do this once. +Other exercises will use the same file. + +See https://yamlscript.org/doc/install/ for more YAMLScript installation info. + +-------------------------------------------------------------------------------- + +Would you like to install the 'ys' file now? + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r +) + +main() { + setup "$@" + + install-from-local + + $auto && intro-prompt + + installed || install-from-release || true + installed || install-from-build || true + installed || + die "Installing '$installed' failed. Giving up." \ + "Consider filing an issue at: $gh_issue_url" + + echo + echo 'Success!' + echo "$installed is now installed." + echo +} + +installed() { + [[ -f $installed ]] +} + +install-from-local() { + local path + path=$(command -v "$ysfq") || true + if [[ -f $path ]]; then + mkdir -p "$bin" + cp "$path" "$bin"/ + ln -fs "$ysfq" "$bin/ys-0" + ln -fs "$ysfq" "$bin/ys" + (installed && $auto) && exit + true + fi +} + +install-from-release() ( + set -x + curl -s https://yamlscript.org/install | + BIN=1 VERSION="$version" PREFIX="$prefix" bash +) + +install-from-build() ( + cat <<... + +The binary release installation failed. +We can attempt to build and install $ysfq now. +This can take from 1 to 5 minutes to complete. + +... + + printf "Press Enter to install. Ctl-C to Quit."; read -r + + [[ -d /tmp && -w /tmp ]] || + die "Can't write to /tmp" \ + 'Giving up.' + + set -x + + rm -fr "$yamlscript_clone" + + git clone --branch="$version" "$yamlscript_repo" "$yamlscript_clone" + + "$make" -C "$yamlscript_clone/ys" install PREFIX="$prefix" +) + +setup() { + version=$1 + prefix=$2 + make=$3 + auto=false + [[ ${4-} ]] && auto=true + + [[ $version =~ ^0\.1\.[0-9]+$ ]] || + die "Invalid YS_VERSION '$version'" + + bin=$prefix/bin + ysfq=ys-$version + installed=$bin/$ysfq + + if installed; then + echo "'$installed' is already installed." + exit + fi + + yamlscript_repo=https://github.com/yaml/yamlscript + yamlscript_clone=/tmp/yamlscript-exercism + gh_issue_url=https://github.com/exercism/yamlscript/issues +} + +die() { + printf '%s\n' "$@" >&2 + exit 1 +} + +main "$@" diff --git a/yamlscript/hello-world/GNUmakefile b/yamlscript/hello-world/GNUmakefile new file mode 100644 index 0000000..5446a82 --- /dev/null +++ b/yamlscript/hello-world/GNUmakefile @@ -0,0 +1,49 @@ +SHELL := bash + +BASE := $(shell pwd) + +export YS_VERSION := 0.1.96 + +YS_LOCAL_PREFIX := ../../../.local/v$(YS_VERSION) +ifeq (,$(shell [[ -d "$(YS_LOCAL_PREFIX)" ]] && echo ok)) +YS_LOCAL_PREFIX := $(shell cd .. && pwd -P)/.local/v$(YS_VERSION) +endif + +YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin +YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION) + +YS_INSTALLER := .yamlscript/exercism-ys-installer +YS_INSTALLER_CMD := \ + bash $(YS_INSTALLER) $(YS_VERSION) $(YS_LOCAL_PREFIX) $(MAKE) + +TEST_FILE ?= $(wildcard *-test.ys) + +export PATH := $(YS_LOCAL_BIN):$(PATH) +export YSPATH := $(BASE) + + +#------------------------------------------------------------------------------- +default: + @echo " No default make rule. Try 'make test'." + +test: $(YS_BIN) + prove -v $(TEST_FILE) + +install-ys: + @$(YS_INSTALLER_CMD) + +uninstall-ys: + rm -fr $(YS_LOCAL_PREFIX) + + +#------------------------------------------------------------------------------- +ifdef EXERCISM_YAMLSCRIPT_GHA +$(YS_BIN): + +else ifeq (/mnt/,$(dir $(BASE))) +$(YS_BIN): + +else +$(YS_BIN): + @$(YS_INSTALLER_CMD) auto +endif diff --git a/yamlscript/hello-world/HELP.md b/yamlscript/hello-world/HELP.md new file mode 100644 index 0000000..6712528 --- /dev/null +++ b/yamlscript/hello-world/HELP.md @@ -0,0 +1,87 @@ +# Help + +## Running the tests + +To test your solution simply run: + +```bash +make test +``` + +This will run the test file `-test.ys` which contains all of the +tests that you will need to pass for your solution to be correct. +You should study the test file to understand exactly what your solution needs +to do. + +> Note: The first time you run `make test` it will also make sure that the +> correct version of the `ys` YAMLScript interpreter is installed in the +> correct place. + +If you run `make test` before changing any files, all the tests will fail. +This is the proper and expected behavior. +The normal exercise development process is to iteratively improve your +solution, running `make test` after each change, until all the tests pass. + +If you want to only run a specific test (while concentrating on that part of the +solution), you can add this key/value pair to that test: + +```yaml + ONLY: true +``` + +If you want to skip particular tests (while working on other parts of the +solution), you can add this key/value pair to those tests: + +```yaml + SKIP: true +``` + + +## Testing Prerequisites + +YAMLScript currently runs on MacOS and Linux. + +Your computer will need to have the following very common commands installed: + +* `bash` - You can run the tests under any shell, but `bash` must be available. +* `make` - You must use GNU `make` to run the tests. + In some environments tt might have a different name than `make`. + Possibly `gmake`. +* `prove` - This program is part of any normal Perl installation. +* `curl` - Used to install ys if it is not already installed. + +It is extremely likely that you already have all of these programs installed. + +## Submitting your solution + +You can submit your solution using the `exercism submit hello-world.ys` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [YAMLScript track's documentation](https://exercism.org/docs/tracks/yamlscript) +- The [YAMLScript track's programming category on the forum](https://forum.exercism.org/c/programming/yamlscript) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +If you need help with this YAMLScript exercise, try the following resources: + +* [YAMLScript Documentation](https://yamlscript.org/doc/) +* [YAMLScript Examples - Rosetta Code]( + https://rosettacode.org/wiki/Category:YAMLScript#mw-pages) +* [YAMLScript Matrix Chat](https://matrix.to/#/#chat-yamlscript:yaml.io) +* [YAMLScript Slack Chat](https://clojurians.slack.com/messages/C05HQFMTURF) +* [YAMLScript IRC Chat](https://web.libera.chat/?channel=yamlscript) +* [YAMLScript GitHub Discussions]( + https://github.com/yaml/yamlscript/discussions) +* [YAMLScript on Stack Overflow]( + https://stackoverflow.com/questions/tagged/yamlscript) \ No newline at end of file diff --git a/yamlscript/hello-world/Makefile b/yamlscript/hello-world/Makefile new file mode 100644 index 0000000..06b6f00 --- /dev/null +++ b/yamlscript/hello-world/Makefile @@ -0,0 +1,8 @@ +# This Makefile is a decoy to attempt to detect when a non-GNU make is being +# used and alert the user. + +test: + @echo "You appear to be using a non-GNU version of the 'make' program." + @echo "The YAMLScript Exercism track requires you to use GNU make." + @echo "Please try 'make $@' again using GNU make." + @exit 1 diff --git a/yamlscript/hello-world/README.md b/yamlscript/hello-world/README.md new file mode 100644 index 0000000..f669dc5 --- /dev/null +++ b/yamlscript/hello-world/README.md @@ -0,0 +1,35 @@ +# Hello World + +Welcome to Hello World on Exercism's YAMLScript Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @ingydotnet + +### Contributed to by + +- @m-dango + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program \ No newline at end of file diff --git a/yamlscript/hello-world/hello-world-test.ys b/yamlscript/hello-world/hello-world-test.ys new file mode 100644 index 0000000..9d1cc64 --- /dev/null +++ b/yamlscript/hello-world/hello-world-test.ys @@ -0,0 +1,11 @@ +#!/usr/bin/env ys-0 + +use ys::taptest: :all +load: 'hello-world.ys' + +test:: +- name: Say Hi! + code: hello() + want: Hello, World! + +done: 1 diff --git a/yamlscript/hello-world/hello-world.ys b/yamlscript/hello-world/hello-world.ys new file mode 100644 index 0000000..5db53f7 --- /dev/null +++ b/yamlscript/hello-world/hello-world.ys @@ -0,0 +1,4 @@ +!YS-v0 + +defn hello(): + 'Hello, World!'