Commit Graph

4847 Commits

Author SHA1 Message Date
Veit Heller
e42922e96e
feat: add Introspect.arguments (#1163)
* feat: add Introspect.arguments

* fix: fix struct case of Introspect.arguments
2021-02-01 17:03:38 +01:00
Veit Heller
59d43abf74
fix: release resources on break (#1153)
* fix: release resources on break

* refactor: remove outdated reference to bangpatterns

* refactor: rename searchBreak to searchForInnerBreak
2021-01-31 21:15:54 +01:00
Veit Heller
d20414e87d
feat: Add drop interface (#1088)
* add sketch for drop

* add drop example

* correct drop ordering

* fix: simplify drop and add to deleter

* docs: add drop docs

* fix: use a sound lifetime var
2021-01-31 21:15:10 +01:00
Veit Heller
74da9c2277
refactor: reformat (sorry for forgetting) (#1162) 2021-01-31 14:54:13 +01:00
Veit Heller
2f03c4af6a
feat: make reseeding of Random at startup configurable (#1161)
* fix: respect quotes in macro expand

* feat: make reseeding of Random at startup configurable

* refactor: better reseed api
2021-01-29 17:38:39 +01:00
Veit Heller
f6c9c338bb
fix: check calls of address and ref (#1156)
* fix: check calls of address and ref

* fix: expand arg to ref

* fix: allow lists in call to address
2021-01-29 17:24:04 +01:00
Veit Heller
b0a207dd49
refactor: don’t print compilation info on implicit compile (#1157) 2021-01-29 17:21:19 +01:00
Veit Heller
6057b03288
fix: respect quotes in macro expand (#1160) 2021-01-28 16:40:41 +01:00
Veit Heller
881e904ae9
docs: fix typo in make-deriver and add implementor note (#1155) 2021-01-27 19:00:31 +01:00
Veit Heller
8e1e827e57
fix: register should only take unqualified symbols (#1154)
* fix: register should only take unqualified symbols

* test: add tests for unqualified register
2021-01-27 13:31:00 +01:00
Veit Heller
384c41909d
feat: add deprecation meta (#1136)
* feat: add deprecation meta

* refactor: print only deprecated

* refactor: add argument to deprecated

* fix: make deprecated work early on
2021-01-26 13:22:50 +01:00
Veit Heller
5e39f665f1
feat: add dynamic-type command (#1148)
* feat: add dynamic-type command

* refactor: use symbols for dynamic-type
2021-01-26 13:22:26 +01:00
Veit Heller
144b114cda
docs: don’t confuse liquid (#1152) 2021-01-26 13:21:20 +01:00
Veit Heller
a6a52c7605
feat: a proper dynamic numeric tower (#1140)
* feat: a proper dynamic numeric tower

The following things were changed and/or added:
- `Dynamic.neg` was added
- `Dynamic.mod` was changed to work on float values
- `Dynamic.cxr` was changed to work with `0` instructions
- `Dynamic.=` was changed to ignore the type of the number
- `Dynamic.round` was added
- dynamic arithmetic was changed to respect the numeric type tower
- the instances of `Eq` and `Ord` for `Number` are no longer derived, so that they work across numeric types
- the instance of `Num` for `Number` was changed to work across numeric types
- `promoteNumber` was added as a type function to implement the numeric tower.

The numeric tower is as follows:
Byte -> Int -> Long -> Float -> Double

* test: add tests for cxr, neg, and =

* test: add tests for Dynamic.round
2021-01-26 06:19:00 +01:00
Veit Heller
07f6330bf2
fix: deal with literals in match (#1146) 2021-01-26 06:18:32 +01:00
Veit Heller
8c1999d656
feat: add fstr (#1142)
* feat: add fstr

* test: add fstr test

* fix: memory error in test

* fix: fix backslash parser

* feat: add octal escape literals
2021-01-26 06:18:16 +01:00
Veit Heller
63291c53af
refactor: use Set for used modules (#1150)
* refactor: use Set for used modules

* fix: fix lookup test
2021-01-25 21:18:01 +01:00
Scott Olsen
95881850a2
fix: make set! work with dynamic args (thanks @hellerve) (#1151)
* fix: make set! work with dynamic args (thanks @hellerve)

Like `let` before it, we used to bind function arguments to their values
only, which wasn't accounted for in `set!` such that one could not
`set!` `i` in `defndynamic [i] ...`. To fix this for let bindings we
introduced a `LetDef` form for consistency with Def forms. This commit
renames `LetDef` to `LocalDef` and uses it as a value for function
arguments in addition to let bindings, ensuring `set!` works on function
arguments too. Big thanks to @hellerve for the suggestion!

* test: add regression test for set! on dynamic function args
2021-01-25 21:16:53 +01:00
Veit Heller
96a1085145
refactor: refactor quasiquotation (#1145) 2021-01-24 22:49:51 +01:00
Veit Heller
9cfde34fbc
docs: add Introspect and Unit (#1147) 2021-01-24 22:44:47 +01:00
Veit Heller
bdaf96550f
refactor: use quasiquoting in STDLIB and go through array in quasiquote (#1135) 2021-01-21 06:20:03 +01:00
Veit Heller
2584518d1c
refactor: use derive in Vector modules (#1141) 2021-01-21 06:19:45 +01:00
Veit Heller
2d34af6aa9
feat: make empty? an interface (#1139) 2021-01-20 09:54:08 +01:00
Veit Heller
f23d5d0448
refactor: make Maybe.zip a macro (#1138) 2021-01-19 15:59:37 +01:00
Veit Heller
23db6be8c2
fix: mark Float.pi as implementor of pi (#1137) 2021-01-19 10:34:01 +01:00
Veit Heller
e966f36a58
feat: add walk* (#1134) 2021-01-17 23:34:11 +01:00
Veit Heller
dd81164f93
feat: add string? and number? (#1130) 2021-01-17 14:39:11 +01:00
Veit Heller
5d225905ea
fix: expand macros in closure bodies (#1131) 2021-01-17 14:38:45 +01:00
Veit Heller
99ff24bd2b
refactor: make dynamic equality more permissive (#1132) 2021-01-16 23:20:08 +01:00
Veit Heller
2023c93d62
feat: Quasiquotation (#1129)
* feat: quasiquotation

* test: add tests for quasiquotation

* fix: fix typo in call to doc

* fix: do not evaluate quasiquote too eagerly

* test: pull quasiquote test into macro

* docs: fix unquote example with better constant

* feat: add quasiquote literals

* refactor: simplify reader macros
2021-01-15 10:50:04 +01:00
Veit Heller
02936cc74c
feat: Derive (#1120)
* core: add derive

* fix: fix errors with set!

Notably, don't type check dynamic bindings (which can be set to
whatever) and eliminate a hang that resulted from not handling an error
at the end of the `set!` call. Also refactors some of the code in
efforts to make it a bit cleaner.

Also adds an error when `set!` can't find the variable one calls set!
on.

* feat: better derive

* test: add error test for derive

* document derive

* add derive to core documentation to generate

* core: add derive

* fix: fix errors with set!

Notably, don't type check dynamic bindings (which can be set to
whatever) and eliminate a hang that resulted from not handling an error
at the end of the `set!` call. Also refactors some of the code in
efforts to make it a bit cleaner.

Also adds an error when `set!` can't find the variable one calls set!
on.

* feat: better derive

* document derive

* feat: first completely working version of derive

* feat: make name of derivable customizable (thanks @scolsen)

* refactor: implement doc edits provided by @scolsen

* feat: change argument order for derive

* fix: change deriver error test

* test: add derive tests

* fix: change order of derive back

* docs: fix typo in derive document

Co-authored-by: scottolsen <scg.olsen@gmail.com>
2021-01-15 10:48:34 +01:00
Scott Olsen
9bd44227c3
fix: don't combine internal envs in closures (#1126) 2021-01-13 07:16:38 +01:00
Scott Olsen
381fa0f179
fix: Closure context (#1124)
* feat: add semigroup instance for Env and Context

Adds a semigroup instance for combining Envs and Contexts--this will be
necessary to ensure closure's are evaluated under the combination of the
context captured in the closure and the current global context during
evaluation.

The semigroup instances are left biased and will prefer bindings defined
in the left context/env argument in the case of conflicts (this is in
keeping with the implementation of `union` in Data.Map, the underlying
function powering this instance).

* fix: evaluate closures under the current context

Previously, closures were evaluated only under the context that was
stored during their creation. However, this can lead to issues where
closures do not resolve bindings to their latest definitions.

This commit leverages the semigroup instance of Context to evaluate
closures under the combination of the context captured during their
creation and the broader context during their evaluation/application,
preferring the context captured in the closure when bindings conflict.

This ensures that when we apply closures their local bindings still
resolve to definitions encapsulated in the closure, while other bindings
resolve to the definitions contained in the current overarching context
(instead of the old context captured by the closure).

* fix: fix bias for context env combinations in semigroup

Previously, the semigroup instance for Context was left-biased in all
the combinations of each context's environment. However, one usually
calls this function to combine some older context with a newer context,
intending to have the older context win *only* in the case of internal
environments.

This commit changes the behavior of the semigroup instance to better
reflect this use case. When one calls:

`c <> c'`

The envs in each context are combined as follows:

- internal: If conflicts occur, prefer the bindings of the context on
  the LHS (the "older" context)
- global: If conflicts occur, prefer the bindings of the context on the
  RHS ("newer" context)
- type: If conflicts occur, prefer the bindings of the context on the
  RHS ("newer" context)

This ensures the resulting context uses the latest values in the chance
of conflicts in the global env/type env, and the older values in the
case of an internal env (a closure).

* test: add basic tests for closures

* refactor: rename test/closure -> test/dynamic-closure

Also updates the forms to test dynamic closures.
2021-01-12 22:28:51 +01:00
Scott Olsen
02e04f33b2
fix: replace qualified bindings (#1125)
Previously, we couldn't replace qualified bindings in Envs. This change
updates envReplaceBindings to accept qualified paths and to replace the
binding denoted by the path, updating the module environments the binder
belongs to accordingly.

If the qualified path does not denote an existing module, it simply
returns the environment as is (just like the unqualified case).
2021-01-12 21:37:27 +01:00
Veit Heller
afa9b1223d
Respect use in dynamic lookup (#1122)
* fix: respect use in dynamic lookup

* refactor: apply ormolu format

* test: add dynamic use test
2021-01-12 12:52:54 +01:00
Scott Olsen
81c73e2003
fix: account for interfaces in function lookups (#1118)
* fix: account for interfaces in function lookups

An older version of Carp only allowed users to implement interfaces by
defining a function of the same name. Since PR 769 and roughly commit
040e9e4 however, this was no longer the case, since we added a primitive
for implementing interfaces, allowing users to implement interfaces
  using functions with whatever name they want.

When this happened, the function lookups that happen during
concretization were never updated to reflect the fact that interface
implementations might have different names than their corresponding
interfaces. It's rare, but this can lead to errors for template
functions in the compiler.

For example, registered types automatically get an implementation of
`prn` with the same name. This function takes a ref to the registered
type as an argument. If a user wants to use such a type as an array
member however, they must provide a prn that takes a value argument
instead of a ref. If the user still wants to keep the ref variant handy,
however, they need to give this new prn implementation a different name,
otherwise Carp will think they are redefining the existing function.
However, using an arbitrary name would result in this second prn
instance not being found during the lookup fixed in this commit, since
it did not match the name of the interface exactly.

After this commit, this issue will no longer crop up, as the
concretize.hs function lookup now accounts for the fact that, if the
function it is looking for is an interface, it may need to find
functions with names that differ from the name it received as an
argument; e.g. a lookup for `prn` could result in finding a function
named `foo` that is a valid implementation of `prn`.

* fix: include interface name in concretize lookup

* refactor: rename allFunctionsWithNameAndSignature

This function now finds implementations of interfaces as well, which
might have a different name than the function name passed as an
argument. This commit renames the function to reflect this; I've also
added some explanatory notes.
2021-01-12 12:52:15 +01:00
Veit Heller
ce7ccfe290
fix: closure history on dynamic eval (#1119) 2021-01-11 14:47:59 +01:00
Veit Heller
2db218353c
eval: fix resolve semantics for successive evaluation (#1116) 2021-01-11 13:22:05 +01:00
Veit Heller
926eb08b03
macros: try fixing #1030 (#1117) 2021-01-11 13:21:29 +01:00
jacereda
0c6eae63c8
feat: Reduce binary size with more compact exhaustiveness error reporting (#1112) 2021-01-05 07:22:43 +01:00
Efi
eb1e060f54
Documentation on Structs (#1110)
* Update LanguageGuide.md

Clarify Struct instantiation and usage.

* Update LanguageGuide.md

* Update LanguageGuide.md

* Update docs/LanguageGuide.md
2021-01-03 13:24:00 +01:00
Charlotte Koch
45288cd69e
feat: Recognize the NetBSD platform. (#1109) 2021-01-03 13:22:56 +01:00
Veit Heller
d5e324683d
fix: fix members (#1108) 2021-01-03 13:22:08 +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
jacereda
1607af1d6a
refactor: Use different primitive types for each arity (#1103)
* refactor: Use different primitive types for each arity

* chore: Remove obsolete code

* fix: Arity error reporting was broken
2020-12-28 23:48:57 +01:00
jacereda
34f5021f64
refactor: Replace foldl uses with foldl' (#1104) 2020-12-28 23:47:42 +01:00
Scott Olsen
e05cf0e022
fix: manage nested modules in the type environment (#1102)
A misplaced type env reference caused a bug in which types could not be
placed in modules more than a single level deep. Similarly, existing
modules in the type env were always overwritten when new types were
added to modules that were not disjoint. This commit fixes both issues.

In the future, we should likely make module management functions more
general and call them to manage modules in both the value and type envs.
2020-12-27 21:58:55 +01:00
Scott Olsen
6c551a104b
fix: fix errors with set! (#1100)
Notably, don't type check dynamic bindings (which can be set to
whatever) and eliminate a hang that resulted from not handling an error
at the end of the `set!` call. Also refactors some of the code in
efforts to make it a bit cleaner.

Also adds an error when `set!` can't find the variable one calls set!
on.
2020-12-24 16:20:07 +01:00
Efi
c1fe094885
feat: Add "rest" function to Array (#1099)
* feat: Add "rest" function to Array

* typo

* Update core/Array.carp
2020-12-24 16:19:53 +01:00
Scott Olsen
d420635762
feat: overwrite existing interface implementations (#1094)
* feat: overwrite existing interface implementations

This commit alters the behavior of interfaces so that implementations
with the same type signature will overwrite previous implementations
with that signature--before this was a runtime error.

Previously, if a user defined two distinctly named implementations of an
interface that shared a type, Carp would panic and error at runtime if
the interface was called and resolved to the type, since it couldn't
decide which implementation to use from the type alone. After this
commit, we instead issue a warning and overwrite existing
implementations of the same type, so that defining:

```
(defn foo [] 0)
(implements zero foo)
```

will replace `Int.zero` in the `zero` interface's implementation path
list and won't result in a runtime error--instead `foo` will be called
when `zero` is called in a context in which it returns an int:

```
[WARNING] An implementation of the interface zero with type (Fn [] Int)
already exists: Int.zero. It will be replaced by the implementation:
foo.
This may break a bunch of upstream code!
```

test/interface.carp also has a concrete illustration of this case.

* chore: address hlint suggestions

* fix: don't print overridden interface implementations in info

This commit updates our handling of interface overrides to remove
interfaces from the implements meta of a function that was overridden by
a new implementation.

Similarly, this refactors primitiveInfo to prevent printing binders that
do not actually implement an interface.

* refactor: incorporate @TimDeve's error message suggestion
2020-12-23 22:24:52 +01:00