Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nock language and evaluator #2557

Closed
lukaszcz opened this issue Dec 10, 2023 · 0 comments · Fixed by #2564
Closed

Nock language and evaluator #2557

lukaszcz opened this issue Dec 10, 2023 · 0 comments · Fixed by #2564
Assignees
Labels
Milestone

Comments

@lukaszcz
Copy link
Collaborator

  • Define a Haskell data structure and a readable textual representation for the Nock language. This can be based on the write-up I did, omitting or simplifying Nock features we won't need.
  • Implement parsing, pretty printing and an evaluator.
  • Write basic tests for the evaluator.
@lukaszcz lukaszcz added the nock label Dec 10, 2023
@lukaszcz lukaszcz added this to the 0.6.0 milestone Dec 10, 2023
@lukaszcz lukaszcz self-assigned this Dec 10, 2023
This was referenced Dec 10, 2023
@lukaszcz lukaszcz removed their assignment Dec 13, 2023
paulcadman added a commit that referenced this issue Jan 11, 2024
This PR adds an parser, pretty printer, evaluator, repl and quasi-quoter
for Nock terms.

## Parser / Pretty Printer

The parser and pretty printer handle both standard Nock terms and
'pretty' Nock terms (where op codes and paths can be named). Standard
and pretty Nock forms can be mixed in the same term.

For example instead of `[0 2]` you can write `[@ L]`.

See
https://github.com/anoma/juvix/blob/a6028b0d92e2dff02329ab7f441bf48ccdeb3eb3/src/Juvix/Compiler/Nockma/Language.hs#L79
for the correspondence between pretty Nock and Nock operators.

In pretty Nock, paths are represented as strings of `L` (for head) and
`R` (for tail) instead of the number encoding in standard nock. The
character `S` is used to refer to the whole subject, i.e it is sugar for
`1` in standard Nock.

See
https://github.com/anoma/juvix/blob/a6028b0d92e2dff02329ab7f441bf48ccdeb3eb3/src/Juvix/Compiler/Nockma/Language.hs#L177
for the correspondence between pretty Nock path and standard Nock
position.

## Quasi-quoter

A quasi-quoter is added so Nock terms can be included in the source, e.g
`[nock| [@ LL] |]`.

## REPL

Launch the repl with `juvix dev nockma repl`.

A Nock `[subject formula]` cell is input as `subject / formula` , e.g:

```
nockma>  [1 0] / [@ L]
1
```

The subject can be set using `:set-stack`.

```
nockma> :set-stack [1 0]
nockma> [@ L]
1
```

The subject can be viewed using `:get-stack`.

```
nockma> :set-stack [1 0]
nockma> :get-stack
[1 0]
```

You can assign a Nock term to a variable and use it in another
expression:

```
nockma> r := [@ L]
nockma> [1 0] / r
1
```

A list of assignments can be read from a file:

```
$ cat stack.nock
r := [@ L]
$ juvix dev nockma repl
nockma> :load stack.nock
nockma> [1 0] / r
1
```

* Closes #2557

---------

Co-authored-by: Jan Mas Rovira <[email protected]>
Co-authored-by: Lukasz Czajka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants