Giter Site home page Giter Site logo

exercism / pyret Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 8.0 461 KB

Exercism exercises in Pyret.

Home Page: https://exercism.org/tracks/pyret

License: MIT License

Shell 2.11% PowerShell 0.78% Pyret 97.11%
exercism-track community-contributions-accepted pyret

pyret's Introduction

Exercism Pyret Track

Configlet .github/workflows/test.yml

Exercism exercises in Pyret.

Setup

If you're solving Exercism exercises offline, you'll need a recent copy of pyret-npm (0.0.27+). Currently, pyret-npm works on Linux and MacOS platforms although Windows users can run it via the WSL. However, you can also use Pyret's online IDE. In that case, you'll need to switch from the IDE's default essentials2021 namespace to the older essentials2020 supported by pyret-npm.

Support

For support with Pyret in Exercism, please visit the Pyret subcategory on the official Exercism forum.

Coding Style

Please consult the official Pyret style guide.

Testing

To test the exercises, run ./bin/verify-exercises on a Linux or MacOS platform. This command will iterate over all exercises and check to see if their exemplar/example implementation passes all the tests.

Contributing Guide

Please see Exercism's contributing guide.

At the moment, there's not a generator for Pyret exercises.

Here's the basic template for an exercise-slug-test.arr. Each check block corresponds to a single test case, and the string label is reported to the student. Each check block is wrapped inside a no-parameter function which is then stored inside the run field of a test value of the TestRun datatype. This test value also contains an active field which indicates whether a test should be run (true) or not (false). All test values go inside a list that Pyret iterates over at runtime, executing the functions within each test value marked as active.

A contributor is responsible for copying this template, adding the appropriate functions and check blocks, and populating the list at the bottom.

use context essentials2020

include file("exercise-slug.arr")

#|
  When working offline, all tests except the first one are skipped by default.
  Once you get the first test running, unskip the next one until all tests pass locally.
  Check the block comment below for further details.
|#

fun foo-returns-1():
  check "foo returns 1":
    foo() is 1
  end
end

fun bar-returns-2():
  check "bar returns 2":
    bar() is 2
  end
end

#|
  Code to run each test. Each line corresponds to a test above and whether it should be run.
  To mark a test to be run, replace `false` with `true` on that same line after the comma.
  test(test-a, true) will be run. test(test-a, false) will be skipped.
|#

data TestRun: test(run, active) end

[list: 
  test(foo-returns-1, true),
  test(bar-returns-2, false),
].each(lam(t): when t.active: t.run() end end)

Track linting

configlet is an Exercism-wide tool for working with tracks. You can download it by running:

./bin/fetch-configlet

Run its lint command to verify if all exercises have all the necessary files and if config files are correct:

$ ./bin/configlet lint

The lint command is under development.
Please re-run this command regularly to see if your track passes the latest linting rules.

Basic linting finished successfully:
- config.json exists and is valid JSON
- config.json has these valid fields:
    language, slug, active, blurb, version, status, online_editor, key_features, tags
- Every concept has the required .md files
- Every concept has a valid links.json file
- Every concept has a valid .meta/config.json file
- Every concept exercise has the required .md files
- Every concept exercise has a valid .meta/config.json file
- Every practice exercise has the required .md files
- Every practice exercise has a valid .meta/config.json file
- Required track docs are present
- Required shared exercise docs are present

pyret's People

Contributors

bnandras avatar dependabot[bot] avatar erikschierboom avatar exercism-bot avatar glennj avatar ihid avatar isaacg avatar kytrinyx avatar meatball133 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyret's Issues

Update docs/RESOURCES.md

docs/RESOURCES.md has a broken invite link to the Pyret Discord (only recently expired). I'm waiting on an updated invite link, but it probably makes more sense to change the link to a note that a Discord server exists and the current link can be found on Twitter. That's how I found it originally, and if the invite expires, that becomes a Pyret maintainers' issue, not an us issue.

Implement bin/verify-exercises

Per #42, bin/verify-exercises needs to be implemented. This will need to be written in another language that iterates through the exercises, moves the necessary files, passes their relative locations to the Pyret CLI, and then cleans up afterwards. Pyret is built on top of JavaScript so Node.js is an option, but bash would just work as well since the Pyret CLI runs on MacOS, Linux, and WSL.

Implement Two Fer?

Pyret doesn't have default argument values. We could pass in an Option, using the none variant to represent a name not being passed.

some("hello").or-else("you") # "hello"
none.or-else("you") # "you"

but not

some(none).or-else("you") # none

Check exercises for shadowed declarations

fun translate(bar):
  bar
end

This is something I noticed trying ETL out this morning, but this snippet returns an error when using code.pyret.org (CPO) but not pyret-npm. The error is The declaration of translate shadows the declaration of a built-in of the same name.. A quick search of the language docs didn't show a translate, but it seems to be something exposed in the CPO setup but not pyret-npm.

Therefore, I'm proposing we check exercises to see if they prompt any shadowing errors on CPO. It can be as simple as the snippet above.

Someone working with Pyret would likely be familiar with CPO and not necessarily pyret-npm so they might try to copy and paste Exercism code into there. If they troubleshoot the error, they'll have to rename the function names in exercise stubs to run in CPO and then rename them again to make the Exercism tests. That sounds tedious.

I'll update the docs for contributors to make this more clear. I'll ping the Pyret team if I can get a list of these built-ins so we can add a CI check for exercise files that contain those names.

ETL output dict container type should match input dict container type

@meatball133, would it be a bother for you to switch the tests to expect that a string-dict is returned? You can use the freeze() method on mutable-string-dict so example.arr wouldn't need to change much. Since string-dicts and mutable-dicts work the same here for our purposes, I think we should keep the input and output types the same for simplicity.

Update ETL function name to avoid shadowing

Related to #75, but ETL uses a function named translate. That causes a shadowing error when the stub is pasted into CPO because that editor uses essentials2021 by default while pyret-npm implicitly uses essentials2020. Translate is imported explicitly by the user from the images library into the current namespace under essentials2020, but in essentials 2021, it and other names from that library are imported automatically into the global namespace. Therefore, we should name translate something else or my-translate.

Add list-ops

I won't get to it for a few days, but I'd like to port list-ops.

Add repo labels

@ErikSchierboom, I'd like to accept community contributions for this track. Can you add the 'community-contributions-accepted' label? There's no pause contributions GitHub action to disable here. I'd also like to add the pyret label while you're in there. Thanks in advance.

Continuous Integration

Update .github/workflows/test.yml and bin/verify-exercises according to documentation. This would likely use the pyret-npm package. pyret returns exit code 0 for not just a successful run but also when it can't compile. Instead, the indication of a successful run would be the returned message "Looks shipshape, all n tests passed, mate!" where n is the number of tests.

Proposal for pending tests

@ErikSchierboom, Pyret doesn't have a way to mark tests pending. My thought was I could use a multiline comment (block comment in Pyret) to hide a test from Pyret. The student needs to remove the surrounding #| and |# lines so Pyret can see and run a given test. These would be the only multiline comments in the test files so it's easy to account for in the test runner setup as well. The only problem is that since Pyret won't know there's a commented-out test, it can't alert the student to the presence of pending tests like some other tracks' testing frameworks might.

fun foo():
  true
end

check "this test will run every time":
  foo() is true
end

#|
   # This test is pending. Remove the surrounding #| and |# lines to run this test.
check "this test will only run after the surrounding block comment is removed":
  hi() is true
end
|#

check "this test will run whether or not the second test is commented out":
  foo() is-not true
end

Launch tracking

Overall documentation for building an Exercism track lives at https://exercism.org/docs/building/tracks/new

This issue helps keep track of the tasks you're working on towards launching this track.

The next steps are:

Once you've finished a task, you can check them in this list.

Questions

Please ask if you have any questions or if anything is confusing!

Implement Space Age?

Space Age would be a good exercise to include if someone's interested. I think we should keep it as as a series of functions because a student could still use a data declaration, object expressions, or functions returning functions behind the scenes if they'd like. However, if we're expecting a data declaration or object expression, they can only use one or the other because of the dot expression. By keeping it loose, we can put together a Dig Deeper document for this as well.

If the test runner is expecting on-earth(seconds),

fun on-earth(seconds):
   seconds
where:
  on-earth(10) is 10
end

is the same to the tests as

my-object = { method on-earth(self, seconds): seconds end}
on-earth =  my-object.on-earth

check "":
  on-earth(10) is 10
end

and

space-age = lam(ratio): lam(seconds): ratio * seconds end end

on-earth = space-age(1)
on-earth(10)

check "":
  on-earth(10) is 10
end

Flatten List to Flatten Array

On second thought, I should restore the canonical name and make an instructions append that we're using lists not arrays in this exercise.

Implement additional exercises

I'm planning on adding these practice exercises.

  • Custom Set
  • Rotational Cipher
  • Sublist
  • Transpose
  • Allergies
  • Bank Account
  • Circular Buffer
  • Proverb
  • Robot Simulator

Update track documentation for Windows / WSL

In my testing, it appears the Pyret compile server doesn't work on Windows (but does on Linux and MacOS). I've confirmed that using WSL on Windows works so we should update any documentation to reflect that workaround

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.