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

merge objects and envs into scopes #2

Merged
merged 25 commits into from
Sep 6, 2021
Merged

merge objects and envs into scopes #2

merged 25 commits into from
Sep 6, 2021

Conversation

vito
Copy link
Owner

@vito vito commented Sep 5, 2021

This is a bit of a doozy. The commit messages don't really help. Most of the
rationalization can be found in Roam.

tldr: I kept noticing the symmetry between Keywords, Symbols, Objects, and
Envs, so I wanted to see if that could be consolidated. Turns out it's doable,
and has pretty (imo) interesting results.

The delta:

  • Envs have been renamed to Scopes
  • {parent :a 1 :b 2} constructs a Scope
  • Object is no more; Scope has absorbed its functionality
  • "Objects" (now Scopes) now have parents
  • "Objects" (now Scopes) are now mutable
    • kind of scary; could maybe enforce single assignment?
  • Keywords are just Symbol constructors now; they are not a discrete type
    • same semantics as [] for ()
    • [:foo] evaluates to (foo)

Interesting outcomes:

  • literal syntax for Kernel envs can replace a lot of env related builtin
    functions
  • makes keywords and objects feel less "bolted on" - they are now an integral
    part of the core language semantics
  • using scopes to replace objects pretty much repeats the same scope semantics
    as Atomo - but in a functional language, instead of prototype-based OOP
  • symmetry between symbol constructors and list constructors
    • [] : () :: :foo : foo
  • a simpler implementation of (let) could be implemented using {} for the
    bindings

TODO:

  • update the docs
  • use {} for (let) too sacreligious
  • rename Scope.Clone to .Copy
    • .Clone is too easy to confuse with prototype-based OOP

vito and others added 25 commits September 4, 2021 19:31
* phase 1 of unifying with Object
* next phase is to remove Object and turn {} into Env literal
* the plan: {} takes a sequence of parent scopes followed by alternating
  binding value pairs, e.g. {p1 p2 :a 1 :b 2}
* create a child scope: {parent}

Signed-off-by: Alex Suraci <[email protected]>
{parent :a 1 :b 2} constructs a scope inheriting from parent, with a
bound to 1 and b bound to 2

* applicative; all contents are evaluated in the calling scope
* parent scopes may be listed anywhere (typically beginning I guess)
* keywords followed by values set bindings in the child scope
this is all kind of one big bang, but all the tests pass. docs sitll
need to be updated.
* :foo evaluates to foo (symbol)
* remove keyword? and keyword constructors/converters
* move keyword operative semantics to symbols
Resolved issues in the following files via DeepSource Autofix:
1. applicative.go
2. bool.go
3. builtin.go
4. continuation.go
5. empty.go
6. fspath.go
7. host_path.go
8. ignore.go
9. int.go
10. keyword.go
11. null.go
12. operative.go
13. path.go
14. pipes.go
15. reader.go
16. scope.go
17. string.go
18. suite_test.go
19. symbol.go
20. value.go
21. workload_path.go
* no shrunken text
* giant (parens) (simulated with a border)
* fix false positive for rendering workload path as workload instead
just fudging the numbers tbh, this was kind of annoyingly frequent for
fast local iteration. an hourly/daily cycle seems good enough for
picking up changes gradually. set it lower when needed.
.Clone could be confused with a prototype-style child scope, when in
reality it performs a deep copy including all parent bindings, resulting
in an independent but equivalent value
* bassics page now generates tags and anchors
* flattened bassics page into a more clear glossary
* render scopes + parent scopes, rather than objects
* rename object to scope everywhere
useful for profiling
use cheaper direct type checking instead to avoid allocs, since these
values should never be annotated anyway

(knock on wood)
another hot code path which should be able to trust the return values a
bit more
these get allocated on basically every turn, so let's re-use them
embed.FS paths Stringify terribly
since most throwaway scopes won't have any

also simplify Bind implementation; clear out parents instead of making
two scopes
@vito vito merged commit a83000e into main Sep 6, 2021
@vito vito added the enhancement New feature or request label Jan 2, 2022
vito added a commit that referenced this pull request Feb 20, 2022
merge objects and envs into scopes
@vito vito deleted the scopes branch February 20, 2022 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant