Commit Graph

492 Commits

Author SHA1 Message Date
Erik Svedäng
48489a5771
feat: Implicit struct init (#1003)
* feat: Can omit .init in simple cases

* fix: Don't treat unqualified modules as interface sym:s

* feat: Can handle implicit init of type inside 'use':d module

* fix: Give deftypes and sumtypes correct parent environment!

* test: A few test cases

* refactor: Remove commented out code

Co-authored-by: Erik Svedang <erik@Eriks-iMac.local>
2020-11-23 09:59:35 +01:00
Erik Svedäng
a873099640
chore: Move some examples to test/produces-output (#989)
* chore: Moved examples that work more as tests to folder 'test/produces-output'

* fix: Corrections to the release script

* fix: Correct filename on Windows

* fix: Move more files around

* fix: Remove check-malloc example

* fix: Apparently unicode example does not work

* chore: Move nested_lambdas.carp back to examples

* chore: Remove .DS_Store files

* fix: Bring back unicode test

* test: Make sure benchmark compile (had to remove mandelbrot and n-bodies)

* fix: Replacement implementation of clock_gettime on Windows

* chore: Trigger CI

* fix: Define CLOCK_REALTIME

Co-authored-by: Erik Svedang <erik@Eriks-iMac.local>
2020-11-23 06:30:43 +01:00
Erik Svedäng
2f302aa046
Merge pull request #973 from jacereda/fix-suffix
Fix suffix docs and implementation, simplify prefix.
2020-11-17 23:59:46 +01:00
Jorge Acereda
e4d4a345b8 Fix suffix docs and implementation, simplify prefix. 2020-11-17 23:42:03 +01:00
Erik Svedäng
4e943bd506
Merge pull request #942 from hellerve/veit/reseed
Call Random.reseed at program start
2020-11-17 22:29:58 +01:00
Jorge Acereda
2d91f49600 Fix crash reported in #923. 2020-11-16 23:46:16 +01:00
Jorge Acereda
46a0abe897 Fix nixpkgs build. 2020-11-14 15:28:17 +01:00
Tim Dévé
4971be73f4 Moves scripts in scripts folder 2020-11-09 10:51:11 +00:00
Tim Dévé
9a3870afe4 Adds unsafe-raw to StaticArray module 2020-11-07 17:49:41 +00:00
hellerve
2ea1dfb5e7 tests: remove determinism test 2020-10-15 13:16:49 +02:00
Jorge Acereda
58a61dd42e Add support for cross-compilation. 2020-10-10 20:01:18 +02:00
Erik Svedäng
87a49f66ff
Merge pull request #921 from hellerve/veit/doto
Add doto and doto-ref
2020-08-26 20:58:12 +02:00
Erik Svedäng
ec20679440
Merge pull request #918 from hellerve/veit/static-args
core: use static array for args
2020-08-26 20:57:56 +02:00
hellerve
ac6979fcbb macros: add doto and doto-ref 2020-08-25 11:58:20 +02:00
hellerve
ef355b91d8 core: use static array for args 2020-08-24 11:20:52 +02:00
Scott Olsen
af1d0065e2 Index arguments from 0 in with-copy
Indexing from zero is consistent with the rest of Carp's indexing
behavior, so this should make the function more predictable. I've also
added a note to the docs about this.
2020-08-18 22:52:56 -04:00
scottolsen
3a82e7d5c0 Rename proxy->with-copy, update docs
with-copy better communicates that this macro will produce a function
that performs a copy--it doesn't cover the fact that it creates a
references to an anonymous function...but there's only so much we can
cover in a name.

I've also updated the documentation.
2020-08-10 17:59:26 -04:00
scottolsen
6327f51c73 Add a proxy macro for generating functions for higher-orders
It's a fairly common pattern in Carp to call a higher-order function on
some structure of values, such as an Array. However, these structures,
and their members, all have lifetimes under Carp's memory management
model, which means they expect functions that are mapped over them to
take *a reference to a value* rather than a pure value. Array.reduce is
one example of such a "referential" higher-order, the type of its
function argument is:

```
(Fn [a, (Ref b c)] a)
```

That is, this function takes some pure initial value, then expects to be
called against the members of an array, which are *references* to the
values that are alive throughout the Array's lifetime.

However, one often wants to use a function that operates on pure values
in such contexts, such as +, which forces the programmer to write
anonymous functions that handle copying referenced values to pass them
to the underlying "pure" function:

```
(Array.reduce &(fn [x y] (+ x @y)) 0 &[1 2 3])
```

So, in using some high-order function over some structure in Carp one
usually has to do two things:

1. Wrap the function in a ref
2. Handle copying references into values in order to pass them into some
   simpler function that can also be used outside of memory-bound
   contexts.

The `proxy` macro captures this pattern. It wraps a given function in a
referenced anonymous function and copies an argument of that function at
a designated position before calling the underlying function. For
example, with `proxy`, the above example becomes:

```
(Array.reduce (proxy + 2) 0 &[1 2 3])
```

The macro effectively gives a name to a common pattern--typically it
will only save the programmer a few characters, but it perhaps makes the
act of using a "function that doesn't care about references" in a
reference dominant context more apparent.

One can also use the macro to develop more specialized macros for
certain higher-orders, since these usually dictate where copying must be
performed. For instance, the `Array.reduce` function argument always
expects the referenced value to occur in the second position, thus one
could write:

```
(defmacro reducer [function] (eval (list proxy function 2)))
```

Then the above code becomes even simpler:

```
(Array.reducer (reducer +) 0 &[1 2 3])
```

Which roughly means, "use the + function (which has no concept of
references) in this reference dependent context".

N.B. The examples using `+` won't work as of now due to current bugs
related to calling `arity` directly on an interface--but a synonym for
plus `add` defined as an explicit function will make all the above work
as expected.
2020-08-07 17:12:43 -04:00
Erik Svedäng
5f8e9318b2
Merge pull request #906 from hellerve/veit/string-from-bytes
Add String.from-bytes
2020-07-13 14:09:07 +02:00
Erik Svedäng
0a2a2d257f
Merge pull request #894 from jacereda/addc
Added add-c to include additional compilation units in the compiler i…
2020-07-13 14:07:53 +02:00
hellerve
91b220c051 core: add String.from-bytes 2020-07-08 21:56:14 +02:00
Erik Svedäng
28873e92d0
Merge pull request #896 from hellerve/veit/unreachable
Add unreachable
2020-07-03 09:42:14 +02:00
Jorge Acereda
134d9a5b02 Implement load-stack. 2020-06-28 19:53:43 +02:00
hellerve
fb3ef6a47f core: add Bool.zero 2020-06-23 12:26:53 +02:00
hellerve
a96f774bc5 core: add unreachable 2020-06-23 12:19:14 +02:00
scottolsen
0b34f9b31a Add a valid use of a private binding to private-binding test 2020-06-19 15:01:27 -04:00
scottolsen
915a539d2d Add a test for private bindings
This commit adds a simple test to ensure binding privacy works as
expected.
2020-06-19 14:53:00 -04:00
Erik Svedäng
15bdf38f23
Merge pull request #888 from hellerve/veit/phantoms
core: add Phantom
2020-06-19 09:30:42 +02:00
Lucas Leblow
59758c33f8 V2 of match-ref-1 regression test 2020-06-14 09:30:49 -06:00
Lucas Leblow
bf7602e609 Add regression test 2020-06-14 09:21:40 -06:00
hellerve
e5fd0e73f9 core: add phantom 2020-06-14 12:16:45 +02:00
Scott Olsen
b61a439e29 Update test to account for constrained interfaces
Constrained interfaces require little change to core carp. In rare cases
(illustrated in test/interfaces.carp) we need to make our functions
slightly more specific. This weakens inference slightly, but in my
opinion is a reasonable case of weakness and not a fault of the type
system.

Exceptional cases that were typed `a-> a` that is, cases that relied on
the previous typing errors related to interfaces, as might be expected,
no longer work (as is the case for the higher-order use of fmap in
examples/functor.carp).

Aside from that, nothing changes.
2020-06-01 23:39:19 -04:00
scottolsen
9a0a061192 Add basic tests for the Introspect module 2020-05-27 14:20:11 -04:00
Erik Svedäng
bbb7920332
Merge pull request #815 from hellerve/veit/fix-776
Make Array.range safe
2020-05-26 20:55:16 +02:00
Erik Svedäng
bf4fed793a
Merge pull request #833 from hellerve/veit/fix-830
Autogenerate Tuple types and document
2020-05-26 20:51:46 +02:00
hellerve
be8424657d core: rename unsafe-range to range-or-default 2020-05-24 12:26:18 +02:00
hellerve
9be2b8e4fb core: autogenerate Tuple types and document 2020-05-24 11:49:27 +02:00
Jorge Acereda
59ef5bbf2b Added --compile-fast to compile with tcc. 2020-05-21 20:04:54 +02:00
hellerve
74d734903e core: move range into array ext and add unsafe-range 2020-05-21 15:23:29 +02:00
hellerve
3353427dd9 core: make Array.range safe 2020-05-18 22:59:41 +02:00
hellerve
1f76f94c1a test: add char literal test 2020-05-18 09:52:01 +02:00
hellerve
b9b5ffba45 parse: add \return, \backspace, \formfeed, and \u unicode literals 2020-05-17 12:02:42 +02:00
Erik Svedäng
f71613a0c8
Merge pull request #796 from dbalan/freebsd_platform
Add FreeBSD as a supported platform
2020-05-13 21:25:20 +02:00
Erik Svedäng
14a0d7e722
Merge pull request #799 from hellerve/veit/string-to-bytes
Add String.to-bytes
2020-05-13 20:59:37 +02:00
hellerve
468c232741 core: add String.to-bytes 2020-05-13 17:15:26 +02:00
Dhananjay Balan
34b63fe1c7 Use Double.approx to compare exp results 2020-05-13 16:52:32 +02:00
hellerve
c569666a0a core: make from-string better 2020-05-12 22:33:40 +02:00
Erik Svedäng
aae743fb35
Merge pull request #769 from scolsen/implement-prim
Add an `implements` primitive, update core
2020-05-12 21:45:29 +02:00
Erik Svedäng
2121b87151
Merge pull request #787 from hellerve/veit/add-new-asserts
Add assert-ref-equal, assert-just, and assert-nothing
2020-05-12 19:59:36 +02:00
hellerve
9e2c2fe2fd test: add assert-ref-equal, assert-just, and assert-nothing 2020-05-12 14:53:42 +02:00