Commit Graph

31 Commits

Author SHA1 Message Date
Veit Heller
dacc13560b
feat: add dynamic Map type (#1168)
* feat: add dynamic map prototype

* feat: feature parity for dynamic map

* docs: document dynamic map

* test: add dynamic map tests

* fix: defdynamics are handled in getBinderDescription

* test: i forgot to add dynamic tests, whoops
2021-02-11 09:12:58 +01:00
Veit Heller
ff30fbc26e
feat: add Map.merge (#1106)
* feat: add Map.merge

* refactor: simplify ref in Map.merge
2021-01-03 13:20:46 +01:00
Scott Olsen
856171ef16
Support defining types in modules (BREAKING) (#1084)
* fix: don't set the inner env to globals in type mods

Previously, we set the inner environment of a type generated module to
the global env in cases where the overarching context didn't have an
inner env. This leads to problems where by the recognition of modules is
inconsistent, and one can't use the names of types as submodules in
certain circumstances.

This commit fixes that issue.

* refactor: refactor primitiveDefmodule

This refactor fixes a issues with meta information on submodules, for
instance, sigs on submodule functions used to result in a compiler error
about ambiguous identifiers. This fixes that.

Unfortunately, I don't have a precise idea about what exactly was wrong
with the original definition of this function. My suspicion is that the
recursion originally altered submodule paths in the wrong way, but I'm
not certain. In any case it's fixed.

* fix: ensure macros are expanded in the correct module

Previously, macro expansions folded over all forms after the top level
form, without performing any context updates on encountered
`defmodules`. This created an issue in which macro calls that produced
new bindings, "meta stubs", were *hoisted* out of submodules and into
the top-level module, creating duplicate definitions.

This commit fixes that issue by adding a special case for defmodule in
macroExpand.

* fix: ensure submodules and globals don't conflict

Previously, our module lookups during new module definition always
eventually fell back to the global environment, which caused submodules
that happen to share a name with a global module to be confused with the
global module. This change fixes that, so now one can define both
`Dynamic` (global) and `Foo.Dynamic` without issue.

* fix: remove old prefixes from vector tests

Commit 7b7cb5d1e replaced /= with a generic function. However, the
vector tests still called the specific Vector variants of this function,
which were removed when the generic was introduced. After recent
changes, these calls are now (correctly) identified as erroneous. My
guess is that they only worked in the past because of problems with our
lookups.

* chore: format code

* feat!: support defining types in modules

This commit adds support for defining types (using deftype) in modules.
Previously, all types were hoisted to the top level of the type
environment. After this commit, the type environment supports defining
nested modules just like the value env, so, calling the following:

```
(defmodule Foo (deftype Bar Baz))
```

Adds the following to the type env:

```
Foo : Module = {
    Bar : Type
}
```

and the following to the value env:

```
Foo : Module = {
    Bar : Module = {
        Baz : (Fn [] Foo.Bar)
        copy : (Fn [(Ref Foo.Bar q)] Foo.Bar)
        delete : (Fn [Foo.Bar] ())
        get-tag : (Fn [(Ref Foo.Bar q)] Int)
        prn : (Fn [(Ref Foo.Bar q)] String)
        str : (Fn [(Ref Foo.Bar q)] String)
    }
}

```

Such a type is *distinct* from any type defined at the top level that
happens to also have the name `Bar`.

This commit also updates info and tests to account for types in modules.

BREAKING CHANGE: This change is breaking since it alters the names of
types that were previously defined in modules. A good example of this is
the `Id` type in the `Color` module. Previously, one could refer to this
type by simply typing `Id` since it was hoisted to the top level. Now it
*must* be referred to by `Color.Id` since `Id` at the top level of the
type env and `Color.Id` (Id in the color module) are considered to be
distinct types.

* chore: format code

* refactor: use concat instead of intercalate

* chore: remove excess parentheses

* chore: Add todo to return IO () in printIfFound
2020-12-22 13:27:57 +01:00
hellerve
c87893dd14 core: make map’s higher order functions non-owning 2019-05-27 18:42:25 +02:00
hellerve
9010a5c2ee core: add Map.put! and Set.put! 2019-05-22 20:13:38 +02:00
hellerve
58e280c553 core: add Pair.reverse and Map.reverse 2019-05-05 11:49:30 +02:00
Erik Svedäng
32f14cd9e3 Work in progress... 2019-03-26 10:23:27 +01:00
hellerve
e54ead1922 all: various sumtype fixes
- add get-maybe to Map
- add tests
- fix emitter error on ref types
2019-02-13 11:46:20 +01:00
Erik Svedäng
de1439c927
Merge pull request #368 from opqdonut/map-set-all
Set.all?, Map.all? and Map.=
2018-12-20 14:29:39 +01:00
Joel Kaasinen
5bb17b82ee core/Map.carp: Map.all? and Map.= 2018-12-18 16:17:08 +02:00
Joel Kaasinen
7aae7d55bd core/Map.carp: Set.all? 2018-12-18 15:58:58 +02:00
Joel Kaasinen
7f7f7c26b1 core/Map.carp: get-with-default
nice for types with no (zero) defined
2018-12-18 14:57:02 +02:00
Joel Kaasinen
a5e46dc71b core/Map.carp: set operations
- equality
- subset
- intersection
- union
- difference
2018-12-13 08:33:42 +02:00
Joel Kaasinen
1755d673ee add test for Set Int stringification 2018-12-12 08:21:16 +02:00
Joel Kaasinen
8020434ace core/Map.carp: hash for Pair
Algorithm from https://stackoverflow.com/questions/1646807/quick-and-simple-hash-code-combinations
2018-12-11 17:37:51 +02:00
Joel Kaasinen
31824bcadb Map.to-array and Set.to-array functions, equality for non-ref Pairs 2018-12-07 21:28:36 +02:00
Joel Kaasinen
10a9de39da core/Map.carp: Map.update and Map.update-with-default functions 2018-12-07 13:41:17 +02:00
Joel Kaasinen
845fd6409e core/Map.carp: Map.endo-map function 2018-12-07 13:27:48 +02:00
Joel Kaasinen
f28b0f9197 core/Map.carp: Set.reduce function 2018-12-07 13:17:58 +02:00
Joel Kaasinen
afd7dec6a8 core/Map.carp: Map.vals and Map.keys functions 2018-12-07 13:04:18 +02:00
Joel Kaasinen
6cf17937d7 core/Map.carp: add Map.kv-reduce function 2018-12-07 12:55:27 +02:00
Joel Kaasinen
a473b54e06 fix Map.put and Set.put 2018-12-03 20:45:23 +02:00
Joel Kaasinen
cfb61847cb fix Map and Set behaviour for negative hash values
fixes #335

- add new Int.positive-mod function
- use it for Map and Set operations
- add tests
2018-12-01 18:01:02 +02:00
hellerve
ca22bfc8cd test: use deftest everywhere 2018-11-08 07:16:52 +01:00
hellerve
e887a5633b core: remove put! and remove! from map and set 2018-10-31 13:42:05 +01:00
hellerve
16e2d7fb85 core: add remove! and put! and make reduce take ownership 2018-10-31 11:33:29 +01:00
Craig Roy
92501770e6 Print results as part of test macro 2018-09-13 00:13:03 +01:00
hellerve
012f048f7f core: change from str to prn in map stringification 2018-08-07 09:32:35 +02:00
hellerve
57e2afe332 core: add tests for map and set stringification 2018-08-07 09:32:35 +02:00
hellerve
d95c28ad5d core: fixed set and tests 2018-08-07 09:32:32 +02:00
hellerve
913e8e3892 core: add map 2018-06-11 20:50:54 +02:00