* refactor: move Context updates into functions Previously, we had a lot of instances of updating Context records directly, replacing environments where needed. This commit replaces those hand-written record setting instances with functions, which should allow us to more gracefully abstract over any preprocessing we should have to do and help ensure we're updating contexts in the right way. * refactor: replace inline context manipulation in primitives Like the commit that altered Eval before it, this commit leverages Context functions to remove a bunch of inline record field setting code and direct env manipulation. * refactor: replace generic binder lookups with contextual ones * refactor: move true and false XObjs into Obj.hs Previously, trueXObj and falseXObj were defined in Commands.hs, but since they're just literal constructed XObj values, I feel Obj.hs is a more appropriate home for them and makes them more widely accessible to other modules without needing to import Commands. * refactor: model symbol qualification requirements at typelevel This commit refactors the Qualify module to express symbol qualification at type level. In the past, all functions operated on SymPaths. In some cases, the functions operated on paths that *were not yet qualified* and so the functions would perform qualification inline. Contrarily, other functions like define received XObjs (from another part of the codebase entirely!) that were already fully qualified, and so it would be a grave mistake to re-qualify them. In the general case, it's difficult or impossible to tell across modules whether or not a given SymPath is coming in qualified or unqualified, which can easily lead to mistakes of double-qualification, e.g. transforming `Foo.bar` into `Foo.Foo.bar`. Modelling qualification in the type system enables us to avoid the problem by distinguishing between unqualified and qualified paths. A function receiving an SymPath can safely qualify it, whereas a function receiving a QualifiedPath should not further qualify the path. This helps better express and ensure constraints across modules. In addition, this commit also refactors a few functions where there was opportunity to do so. * refactor: remove eval call from `doc` This can lead to problems where a doc call intended to be evaluated later (in a macro body) is evaluated *immediately* resulting in a binding being added to the wrong scope (see the function reverse in core). The reason this behavior crops up now is that a special case for evaluating module contexts was removed last commit--this special case caused problems of its own, and the real root of things stems from the unnecessary eval call. Generally, evaling a doc call provides no benefit other than making evaluation of the meta set immediate in the repl, which is easy enough for one to do on one's own by calling eval where needed. * refactor: use do notation to clarify case qualification * refactor: rename runQualified to unQualified @eriksvedang pointed out the `run` prefix typically denotes a monad. As `Qualified` is not monadic (no monad instance defined) we drop the `r` to ensure we don't mislead readers. * refactor: convert a few more binds to do notation Do notation is generally clearer in cases where we use mapM, etc. We can also leverage liftM frequently in the qualification functions to transform a Qualified xobj back into an xobj for further use. * refactor: temporarily restore special case in meta set Meta set disallows setting the meta of a prefixed, absolute path such as `Foo.bar`. It only allows relative, unqualified paths `bar` and uses the current context to determine the appropriate module. If we eventually throw and error from envInsertAt, we can remove this special case. I intend to do that later, but for now we'll keep the special case to make for a more pleasant user experience. |
||
---|---|---|
.github | ||
app | ||
bench | ||
core | ||
docs | ||
examples | ||
headerparse | ||
resources | ||
scripts | ||
src | ||
test | ||
.build.yml | ||
.clang-format | ||
.dir-locals.el | ||
.gitignore | ||
.travis.yml | ||
CarpHask.cabal | ||
default.nix | ||
LICENSE | ||
LUA_LICENSE | ||
README.md | ||
Setup.hs | ||
stack.yaml |
Carp
![Logo](/carp-lang/Carp/media/commit/8263a0da646bb300781505fcdb80a24c54bd5841/resources/logo/carp_logo_300_c.png)
WARNING! This is a research project and a lot of information here might become outdated and misleading without any explanation. Don't use it for anything important just yet!
Version 0.4 of the language is out!
About
Carp is a programming language designed to work well for interactive and performance sensitive use cases like games, sound synthesis and visualizations.
The key features of Carp are the following:
- Automatic and deterministic memory management (no garbage collector or VM)
- Inferred static types for great speed and reliability
- Ownership tracking enables a functional programming style while still using mutation of cache-friendly data structures under the hood
- No hidden performance penalties – allocation and copying are explicit
- Straightforward integration with existing C code
- Lisp macros, compile time scripting and a helpful REPL
Learn more
- The Compiler Manual - how to install and use the compiler
- Carp Language Guide - syntax and semantics of the language
- Core Docs - documentation for our standard library
A Very Small Example
(load-and-use SDL)
(defn tick [state]
(+ state 10))
(defn draw [app rend state]
(bg rend &(rgb (/ @state 2) (/ @state 3) (/ @state 4))))
(defn main []
(let [app (SDLApp.create "The Minimalistic Color Generator" 400 300)
state 0]
(SDLApp.run-with-callbacks &app SDLApp.quit-on-esc tick draw state)))
For instructions on how to run Carp code, see this document.
For more examples, check out the examples directory.
Maintainers
Contributing
Thanks to all the awesome people who have contributed to Carp over the years!
We are always looking for more help – check out the contributing guide to get started.
License
Copyright 2016 - 2020 Erik Svedäng
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
The regular expression implementation as found in src/carp_regex.h are Copyright (C) 1994-2017 Lua.org, PUC-Rio under the terms of the MIT license. Details can be found in the License file LUA_LICENSE.