mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
Merge branch 'master' into match-on-refs
This commit is contained in:
commit
101eaaea75
19
.clang-format
Normal file
19
.clang-format
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
BasedOnStyle: Google
|
||||
AlignEscapedNewlinesLeft: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'true'
|
||||
AllowShortBlocksOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: 'true'
|
||||
AllowShortLoopsOnASingleLine: 'true'
|
||||
BinPackParameters: 'true'
|
||||
ColumnLimit: '80'
|
||||
PointerAlignment: Left
|
||||
SpaceBeforeAssignmentOperators: 'true'
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpacesInContainerLiterals: 'true'
|
||||
Standard: Cpp11
|
||||
TabWidth: '4'
|
||||
IndentWidth: '4'
|
||||
UseTab: Never
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
*.dSYM
|
||||
*~
|
||||
*#
|
||||
*/.DS_Store
|
||||
|
||||
.stack-work/
|
||||
@ -12,3 +14,4 @@ dist/
|
||||
/releases
|
||||
main.obj
|
||||
examples/out
|
||||
/stack.yaml.lock
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: CarpHask
|
||||
version: 0.2.0.0
|
||||
version: 0.3.0.0
|
||||
-- synopsis:
|
||||
-- description:
|
||||
homepage: https://github.com/eriksvedang/Carp
|
||||
@ -45,6 +45,7 @@ library
|
||||
StartingEnv,
|
||||
RenderDocs,
|
||||
StructUtils,
|
||||
Path,
|
||||
Validate
|
||||
|
||||
build-depends: base >= 4.7 && < 5
|
||||
@ -73,6 +74,7 @@ executable carp
|
||||
, CarpHask
|
||||
, containers
|
||||
, directory
|
||||
, filepath
|
||||
, haskeline
|
||||
, process
|
||||
default-language: Haskell2010
|
||||
|
@ -6,9 +6,7 @@
|
||||
|
||||
<i>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!</i>
|
||||
|
||||
<i>Update (March 5, 2019): Union types are merged into master. The final big feature before release is "lifetimes", after those are in the core language will be more or less finished.</i>
|
||||
|
||||
<i>A conference talk about Carp was recorded and the video can be seen [here](https://youtu.be/BQeG6fXMk28).</i>
|
||||
<i>[Version 0.3.0](https://github.com/carp-lang/Carp/releases/tag/v0.3.0) of the language is out!</i>
|
||||
|
||||
## About
|
||||
|
||||
@ -49,7 +47,7 @@ The Carp REPL has built-in documentation, run ```(help)``` to access it!
|
||||
(SDLApp.run-with-callbacks &app SDLApp.quit-on-esc tick draw state)))
|
||||
```
|
||||
|
||||
To build this example, save it to a file called 'example.carp' and load it with ```(load "example.carp")```, then execute ```(build)``` to build an executable, and ```(run)``` to start. The external dependecies are SDL2 and pkg-config.
|
||||
To build this example, save it to a file called 'example.carp' and load it with ```(load "example.carp")```, then execute ```(build)``` to build an executable, and ```(run)``` to start. The external dependencies are SDL2 and pkg-config. On macOS Catalina libiconv is also required.
|
||||
|
||||
### Language Designer & Lead Developer
|
||||
[Erik Svedäng](http://www.eriksvedang.com) ([@e_svedang](https://twitter.com/e_svedang))
|
||||
@ -68,12 +66,13 @@ To build this example, save it to a file called 'example.carp' and load it with
|
||||
* Jonas Granquist
|
||||
* Joel Kaasinen ([@opqdonut](https://github.com/opqdonut))
|
||||
* Eric Shimizu Karbstein ([@GrayJack](https://github.com/GrayJack))
|
||||
* Jorge Acereda ([@jacereda](https://github.com/jacereda))
|
||||
|
||||
Are you missing from the contributors list? Please send a pull request!
|
||||
|
||||
## License
|
||||
|
||||
Copyright 2016 - 2018 Erik Svedäng
|
||||
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.
|
||||
|
42
app/Main.hs
42
app/Main.hs
@ -1,10 +1,7 @@
|
||||
module Main where
|
||||
|
||||
import Control.Monad
|
||||
import qualified System.Environment as SystemEnvironment
|
||||
import System.IO (stdout)
|
||||
import System.Console.Haskeline (runInputT)
|
||||
import System.Directory (doesPathExist, getHomeDirectory)
|
||||
import GHC.IO.Encoding
|
||||
|
||||
import ColorText
|
||||
@ -15,29 +12,28 @@ import StartingEnv
|
||||
import Eval
|
||||
import Util
|
||||
import Lookup
|
||||
import Path
|
||||
|
||||
defaultProject :: Project
|
||||
defaultProject =
|
||||
Project { projectTitle = "Untitled"
|
||||
, projectIncludes = [SystemInclude "core.h"]
|
||||
, projectIncludes = []
|
||||
, projectCFlags = [""]
|
||||
, projectLibFlags = [""]
|
||||
, projectFiles = []
|
||||
, projectAlreadyLoaded = []
|
||||
, projectEchoC = False
|
||||
, projectLibDir = ".carp/libs/"
|
||||
, projectCarpDir = "./"
|
||||
, projectOutDir = case platform of
|
||||
Windows -> ".\\out"
|
||||
_ -> "./out"
|
||||
, projectDocsDir = "./docs/"
|
||||
, projectLibDir = "libs"
|
||||
, projectCarpDir = "."
|
||||
, projectOutDir = "out"
|
||||
, projectDocsDir = "docs"
|
||||
, projectDocsLogo = ""
|
||||
, projectDocsPrelude = ""
|
||||
, projectDocsURL = ""
|
||||
, projectDocsGenerateIndex = True
|
||||
, projectDocsStyling = "carp_style.css"
|
||||
, projectPrompt = case platform of
|
||||
MacOS -> "鲮 "
|
||||
MacOS -> "鲤 "
|
||||
_ -> "> "
|
||||
, projectCarpSearchPaths = []
|
||||
, projectPrintTypedAST = False
|
||||
@ -61,36 +57,34 @@ main = do setLocaleEncoding utf8
|
||||
noCore = NoCore `elem` otherOptions
|
||||
optimize = Optimize `elem` otherOptions
|
||||
generateOnly = GenerateOnly `elem` otherOptions
|
||||
projectWithFiles = defaultProject { projectCFlags = (if logMemory then ["-D LOG_MEMORY"] else []) ++
|
||||
(if optimize then ["-O3 -D NDEBUG"] else []) ++
|
||||
(projectCFlags defaultProject),
|
||||
projectWithFiles = defaultProject { projectCFlags = ["-D LOG_MEMORY" | logMemory] ++
|
||||
["-O3 -D NDEBUG" | optimize] ++
|
||||
projectCFlags defaultProject,
|
||||
projectCore = not noCore,
|
||||
projectGenerateOnly = generateOnly}
|
||||
noArray = False
|
||||
coreModulesToLoad = if noCore then [] else (coreModules (projectCarpDir projectWithCarpDir))
|
||||
coreModulesToLoad = if noCore then [] else coreModules (projectCarpDir projectWithCarpDir)
|
||||
projectWithCarpDir = case lookup "CARP_DIR" sysEnv of
|
||||
Just carpDir -> projectWithFiles { projectCarpDir = carpDir }
|
||||
Nothing -> projectWithFiles
|
||||
projectWithCustomPrompt = setCustomPromptFromOptions projectWithCarpDir otherOptions
|
||||
startingContext = (Context
|
||||
startingContext = Context
|
||||
(startingGlobalEnv noArray)
|
||||
(TypeEnv startingTypeEnv)
|
||||
[]
|
||||
projectWithCustomPrompt
|
||||
""
|
||||
execMode)
|
||||
execMode
|
||||
context <- loadFiles startingContext coreModulesToLoad
|
||||
home <- getHomeDirectory
|
||||
let carpProfile = home ++ "/.carp/profile.carp"
|
||||
hasProfile <- doesPathExist carpProfile
|
||||
carpProfile <- configPath "profile.carp"
|
||||
hasProfile <- doesFileExist carpProfile
|
||||
context' <- if hasProfile
|
||||
then loadFiles context [carpProfile]
|
||||
else do --putStrLn ("No '" ++ carpProfile ++ "' found.")
|
||||
return context
|
||||
else return context
|
||||
finalContext <- loadFiles context' argFilesToLoad
|
||||
settings <- readlineSettings (bindingNames $ contextGlobalEnv finalContext)
|
||||
case execMode of
|
||||
Repl -> do putStrLn "Welcome to Carp 0.2.0"
|
||||
Repl -> do putStrLn "Welcome to Carp 0.3.0"
|
||||
putStrLn "This is free software with ABSOLUTELY NO WARRANTY."
|
||||
putStrLn "Evaluate (help) for more information."
|
||||
runInputT settings (repl finalContext "")
|
||||
@ -104,7 +98,7 @@ main = do setLocaleEncoding utf8
|
||||
BuildAndRun -> do _ <- executeString True finalContext ":bx" "Compiler (Build & Run)"
|
||||
-- TODO: Handle the return value from executeString and return that one to the shell
|
||||
return ()
|
||||
Check -> do return ()
|
||||
Check -> return ()
|
||||
|
||||
-- | Options for how to run the compiler.
|
||||
data OtherOptions = NoCore
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
(defn some-subarray []
|
||||
(let-do [a (replicate n &1)
|
||||
b (subarray &a 0 (/ n 2))]
|
||||
b (slice &a 0 (/ n 2))]
|
||||
(assert (= (/ n 2) (length &b)))))
|
||||
|
||||
(defn perform-bench [new-n]
|
||||
|
@ -4,21 +4,21 @@
|
||||
(defn insert []
|
||||
(let [m {}]
|
||||
(for [i 0 100]
|
||||
(set! m (Map.put &m &i &1)))))
|
||||
(Map.put! &m &i &1))))
|
||||
|
||||
(defn insert-collisions []
|
||||
(let [m (Map.create-with-len 1)]
|
||||
(for [i 0 100]
|
||||
(set! m (Map.put &m &1 &1)))))
|
||||
(Map.put! &m &1 &1))))
|
||||
|
||||
(def m (the (Map Int Int) {}))
|
||||
|
||||
(defn single-insert []
|
||||
(set! m (Map.put &m &1 &1)))
|
||||
(Map.put! &m &1 &1))
|
||||
|
||||
(defn setup-big-map []
|
||||
(for [i 0 10000]
|
||||
(set! m (Map.put &m &i &1))))
|
||||
(Map.put! &m &i &1)))
|
||||
|
||||
(defn retrieve []
|
||||
(Map.get &m &10))
|
||||
@ -52,21 +52,21 @@
|
||||
(defn insert-set []
|
||||
(let [m (Set.create)]
|
||||
(for [i 0 100]
|
||||
(set! m (Set.put &m &i)))))
|
||||
(Set.put! &m &i))))
|
||||
|
||||
(defn insert-set-collisions []
|
||||
(let [m (Set.create-with-len 1)]
|
||||
(for [i 0 100]
|
||||
(set! m (Set.put &m &i)))))
|
||||
(Set.put! &m &i))))
|
||||
|
||||
(def s (the (Set Int) (Set.create)))
|
||||
|
||||
(defn single-insert-set []
|
||||
(set! s (Set.put &s &1)))
|
||||
(Set.put! &s &1))
|
||||
|
||||
(defn setup-big-set []
|
||||
(for [i 0 10000]
|
||||
(set! s (Set.put &s &i))))
|
||||
(Set.put! &s &i)))
|
||||
|
||||
(defn contains-set []
|
||||
(Set.contains? &s &10))
|
||||
|
@ -8,7 +8,7 @@
|
||||
(defn creation [] (Point.init 0 0))
|
||||
(defn bench-access [] (ignore (Point.x &p))) ;; The name 'access' collides with an existing C-function.
|
||||
(defn set [] (Point.set-x @&p 5))
|
||||
(defn update [] (Point.update-x @&p Int.inc))
|
||||
(defn update [] (Point.update-x @&p &Int.inc))
|
||||
|
||||
(defn main []
|
||||
(do
|
||||
|
@ -2,12 +2,9 @@
|
||||
|
||||
set -e; # will make the script stop if there are any errors
|
||||
|
||||
stack build;
|
||||
stack install;
|
||||
|
||||
# Actual tests (using the test suite)
|
||||
for f in ./bench/*.carp; do
|
||||
echo $f
|
||||
carp -x --optimize $f
|
||||
./carp.sh -x --optimize $f
|
||||
echo
|
||||
done
|
||||
|
13
build.sh
Executable file
13
build.sh
Executable file
@ -0,0 +1,13 @@
|
||||
if [ -z "$CARP" ]
|
||||
then
|
||||
if [ -z "$NIX_CC" ]
|
||||
then
|
||||
stack build
|
||||
else
|
||||
cabal build
|
||||
fi
|
||||
fi
|
||||
if which clang-format > /dev/null
|
||||
then
|
||||
clang-format -i core/*.h
|
||||
fi
|
10
carp.sh
Executable file
10
carp.sh
Executable file
@ -0,0 +1,10 @@
|
||||
if [ -z "$CARP" ]
|
||||
then
|
||||
if [ -z "$NIX_CC" ]
|
||||
then
|
||||
CARP="stack exec carp --"
|
||||
else
|
||||
CARP="cabal -v0 run carp --"
|
||||
fi
|
||||
fi
|
||||
$CARP $*
|
165
core/Array.carp
165
core/Array.carp
@ -6,7 +6,7 @@ As an example, consider this definition of `sum` based on `reduce`:
|
||||
|
||||
```
|
||||
(defn sum [x]
|
||||
(reduce + 0 x))
|
||||
(reduce &(fn [x y] (+ x @y)) 0 x))
|
||||
```
|
||||
|
||||
It will sum the previous sum with each new value, starting at `0`.")
|
||||
@ -14,7 +14,7 @@ It will sum the previous sum with each new value, starting at `0`.")
|
||||
(let [total x]
|
||||
(do
|
||||
(for [i 0 (length xs)]
|
||||
(set! total (~f total (nth xs i))))
|
||||
(set! total (~f total (unsafe-nth xs i))))
|
||||
total)))
|
||||
|
||||
(doc empty? "checks whether the array `a` is empty.")
|
||||
@ -25,7 +25,7 @@ It will sum the previous sum with each new value, starting at `0`.")
|
||||
(defn any? [f a]
|
||||
(let-do [res false]
|
||||
(for [i 0 (length a)]
|
||||
(when (~f (nth a i))
|
||||
(when (~f (unsafe-nth a i))
|
||||
(do
|
||||
(set! res true)
|
||||
(break))))
|
||||
@ -35,7 +35,7 @@ It will sum the previous sum with each new value, starting at `0`.")
|
||||
(defn all? [f a]
|
||||
(let-do [res true]
|
||||
(for [i 0 (length a)]
|
||||
(when (not (~f (nth a i)))
|
||||
(when (not (~f (unsafe-nth a i)))
|
||||
(do
|
||||
(set! res false)
|
||||
(break))))
|
||||
@ -47,9 +47,9 @@ If it doesn’t find an element, `Nothing` will be returned.")
|
||||
(defn find [f a]
|
||||
(let-do [res (Maybe.Nothing)]
|
||||
(for [i 0 (length a)]
|
||||
(when (~f (nth a i))
|
||||
(when (~f (unsafe-nth a i))
|
||||
(do
|
||||
(set! res (Maybe.Just @(nth a i)))
|
||||
(set! res (Maybe.Just @(unsafe-nth a i)))
|
||||
(break))))
|
||||
res))
|
||||
|
||||
@ -59,7 +59,7 @@ If it doesn’t find an index, `Nothing` will be returned.")
|
||||
(defn find-index [f a]
|
||||
(let-do [ret (Maybe.Nothing)]
|
||||
(for [i 0 (length a)]
|
||||
(when (~f (nth a i))
|
||||
(when (~f (unsafe-nth a i))
|
||||
(do
|
||||
(set! ret (Maybe.Just i))
|
||||
(break))))
|
||||
@ -69,7 +69,7 @@ If it doesn’t find an index, `Nothing` will be returned.")
|
||||
|
||||
Generates a runtime error if the array is empty.")
|
||||
(defn unsafe-first [a]
|
||||
@(Array.nth a 0))
|
||||
@(Array.unsafe-nth a 0))
|
||||
|
||||
(doc first "takes the first element of an array and returns a `Just`.
|
||||
|
||||
@ -77,13 +77,13 @@ Returns `Nothing` if the array is empty.")
|
||||
(defn first [a]
|
||||
(if (empty? a)
|
||||
(Maybe.Nothing)
|
||||
(Maybe.Just @(Array.nth a 0))))
|
||||
(Maybe.Just @(Array.unsafe-nth a 0))))
|
||||
|
||||
(doc unsafe-last "takes the last element of an array.
|
||||
|
||||
Generates a runtime error if the array is empty.")
|
||||
(defn unsafe-last [a]
|
||||
@(Array.nth a (Int.dec (Array.length a))))
|
||||
@(Array.unsafe-nth a (Int.dec (Array.length a))))
|
||||
|
||||
|
||||
(doc last "takes the last element of an array and returns a `Just`.
|
||||
@ -92,7 +92,7 @@ Returns `Nothing` if the array is empty.")
|
||||
(defn last [a]
|
||||
(if (empty? a)
|
||||
(Maybe.Nothing)
|
||||
(Maybe.Just @(Array.nth a (Int.dec (Array.length a))))))
|
||||
(Maybe.Just @(Array.unsafe-nth a (Int.dec (Array.length a))))))
|
||||
|
||||
(doc = "compares two arrays.")
|
||||
(defn = [a b]
|
||||
@ -100,26 +100,22 @@ Returns `Nothing` if the array is empty.")
|
||||
false
|
||||
(let-do [eq true]
|
||||
(for [i 0 (length a)]
|
||||
(when (/= @(nth a i) @(nth b i))
|
||||
(when (/= (unsafe-nth a i) (unsafe-nth b i))
|
||||
(do
|
||||
(set! eq false)
|
||||
(break))))
|
||||
eq)))
|
||||
|
||||
(doc /= "compares two arrays and inverts the result.")
|
||||
(defn /= [a b]
|
||||
(not (= (the (Ref (Array a)) a) b)))
|
||||
|
||||
(doc maximum "gets the maximum in an array (elements must support `<`) and wraps it in a `Just`.
|
||||
|
||||
If the array is empty, it returns `Nothing`.")
|
||||
(defn maximum [xs]
|
||||
(if (empty? xs)
|
||||
(Maybe.Nothing)
|
||||
(let-do [result (nth xs 0)
|
||||
(let-do [result (unsafe-nth xs 0)
|
||||
n (length xs)]
|
||||
(for [i 1 n]
|
||||
(let [x (nth xs i)]
|
||||
(let [x (unsafe-nth xs i)]
|
||||
(when (< result x)
|
||||
(set! result x))))
|
||||
(Maybe.Just @result))))
|
||||
@ -130,10 +126,10 @@ If the array is empty, returns `Nothing`")
|
||||
(defn minimum [xs]
|
||||
(if (empty? xs)
|
||||
(Maybe.Nothing)
|
||||
(let-do [result (nth xs 0)
|
||||
(let-do [result (unsafe-nth xs 0)
|
||||
n (length xs)]
|
||||
(for [i 1 n]
|
||||
(let [x (nth xs i)]
|
||||
(let [x (unsafe-nth xs i)]
|
||||
(when (> result x)
|
||||
(set! result x))))
|
||||
(Maybe.Just @result))))
|
||||
@ -142,28 +138,28 @@ If the array is empty, returns `Nothing`")
|
||||
(defn sum [xs]
|
||||
(Array.reduce &(fn [x y] (+ x @y)) (zero) xs))
|
||||
|
||||
(doc subarray "gets a subarray from `start-index` to `end-index`.")
|
||||
(defn subarray [xs start-index end-index]
|
||||
(doc slice "gets a subarray from `start-index` to `end-index`.")
|
||||
(defn slice [xs start-index end-index]
|
||||
(let-do [result []]
|
||||
(for [i start-index end-index]
|
||||
(set! result (push-back result @(nth xs i))))
|
||||
(set! result (push-back result @(unsafe-nth xs i))))
|
||||
result))
|
||||
|
||||
(doc prefix-array "gets a prefix array to `end-index`.")
|
||||
(defn prefix-array [xs end-index]
|
||||
(subarray xs 0 end-index))
|
||||
(doc prefix "gets a prefix array to `end-index`.")
|
||||
(defn prefix [xs end-index]
|
||||
(slice xs 0 end-index))
|
||||
|
||||
(doc suffix-array "gets a suffix array from `start-index`.")
|
||||
(defn suffix-array [xs start-index]
|
||||
(subarray xs start-index (length xs)))
|
||||
(doc suffix "gets a suffix array from `start-index`.")
|
||||
(defn suffix [xs start-index]
|
||||
(slice xs start-index (length xs)))
|
||||
|
||||
(doc reverse "reverses an array.")
|
||||
(defn reverse [a]
|
||||
(let-do [i 0
|
||||
j (Int.dec (length &a))]
|
||||
(while (Int.< i j)
|
||||
(let-do [tmp @(nth &a i)]
|
||||
(aset! &a i @(nth &a j))
|
||||
(let-do [tmp @(unsafe-nth &a i)]
|
||||
(aset! &a i @(unsafe-nth &a j))
|
||||
(set! i (Int.inc i))
|
||||
(aset! &a j tmp)
|
||||
(set! j (Int.dec j))))
|
||||
@ -175,7 +171,7 @@ If the element is not found, returns `Nothing`")
|
||||
(defn index-of [a e]
|
||||
(let-do [idx (Maybe.Nothing)]
|
||||
(for [i 0 (length a)]
|
||||
(when (= (nth a i) e)
|
||||
(when (= (unsafe-nth a i) e)
|
||||
(do
|
||||
(set! idx (Maybe.Just i))
|
||||
(break))))
|
||||
@ -185,36 +181,36 @@ If the element is not found, returns `Nothing`")
|
||||
(defn element-count [a e]
|
||||
(let-do [c 0]
|
||||
(for [i 0 (length a)]
|
||||
(when (= e (nth a i)) (set! c (Int.inc c))))
|
||||
(when (= e (unsafe-nth a i)) (set! c (Int.inc c))))
|
||||
c))
|
||||
|
||||
(doc predicate-count "counts the number of elements satisfying the predicate function `pred` in an array.")
|
||||
(defn predicate-count [a pred]
|
||||
(let-do [c 0]
|
||||
(for [i 0 (length a)]
|
||||
(when (~pred (nth a i))
|
||||
(when (~pred (unsafe-nth a i))
|
||||
(set! c (Int.inc c))))
|
||||
c))
|
||||
|
||||
(doc aupdate "transmutes (i.e. updates) the element at index `i` of an array `a` using the function `f`.")
|
||||
(defn aupdate [a i f]
|
||||
(let [new-value (~f (nth &a i))]
|
||||
(let [new-value (~f (unsafe-nth &a i))]
|
||||
(aset a i new-value)))
|
||||
|
||||
(doc aupdate! "transmutes (i.e. updates) the element at index `i` of an array `a` using the function `f` in place.")
|
||||
(defn aupdate! [a i f]
|
||||
(aset! a i (~f (nth a i))))
|
||||
(aset! a i (~f (unsafe-nth a i))))
|
||||
|
||||
(doc swap "swaps the indices `i` and `j` of an array `a`.")
|
||||
(defn swap [a i j]
|
||||
(let [x @(nth &a i)
|
||||
y @(nth &a j)]
|
||||
(let [x @(unsafe-nth &a i)
|
||||
y @(unsafe-nth &a j)]
|
||||
(aset (aset a i y) j x)))
|
||||
|
||||
(doc swap! "swaps the indices `i` and `j` of an array `a` in place.")
|
||||
(defn swap! [a i j]
|
||||
(let-do [x @(nth a i)
|
||||
y @(nth a j)]
|
||||
(let-do [x @(unsafe-nth a i)
|
||||
y @(unsafe-nth a j)]
|
||||
(aset! a i y)
|
||||
(aset! a j x)))
|
||||
|
||||
@ -238,7 +234,7 @@ If the element is not found, returns `Nothing`")
|
||||
(for [i 0 n] (aset-uninitialized! &a i (~f)))
|
||||
a))
|
||||
|
||||
(doc repeat-indexed "repeats function `f` `n `times and stores the results in an array.
|
||||
(doc repeat-indexed "repeats function `f` `n` times and stores the results in an array.
|
||||
|
||||
This is similar to [`repeat`](#repeat), but the function `f` will be supplied with the index of the element.")
|
||||
(defn repeat-indexed [n f]
|
||||
@ -258,9 +254,27 @@ This function copies the array. If you don’t want that, use [`endo-map`](#endo
|
||||
(defn copy-map [f a]
|
||||
(let-do [na (allocate (length a))]
|
||||
(for [i 0 (length a)]
|
||||
(aset-uninitialized! &na i (~f (nth a i))))
|
||||
(aset-uninitialized! &na i (~f (unsafe-nth a i))))
|
||||
na))
|
||||
|
||||
(doc unreduce "creates an array by producing values using `step` until they
|
||||
no longer satisfy `test`. The initial value is `start`.
|
||||
|
||||
Example:
|
||||
```
|
||||
; if we didn’t have Array.range, we could define it like this:
|
||||
(defn range [start end step]
|
||||
(unreduce start &(fn [x] (< x (+ step end))) &(fn [x] (+ x step)))
|
||||
)
|
||||
```")
|
||||
(defn unreduce [start test step]
|
||||
(let-do [elem start
|
||||
acc []]
|
||||
(while-do (~test elem)
|
||||
(push-back! &acc elem)
|
||||
(set! elem (~step elem)))
|
||||
acc))
|
||||
|
||||
(doc zip "maps over two arrays using a function `f` that takes two arguments. It will produces a new array with the length of the shorter input.
|
||||
|
||||
The trailing elements of the longer array will be discarded.")
|
||||
@ -268,7 +282,7 @@ The trailing elements of the longer array will be discarded.")
|
||||
(let-do [l (Int.min (length a) (length b))
|
||||
na (allocate l)]
|
||||
(for [i 0 l]
|
||||
(aset-uninitialized! &na i (~f (nth a i) (nth b i))))
|
||||
(aset-uninitialized! &na i (~f (unsafe-nth a i) (unsafe-nth b i))))
|
||||
na))
|
||||
|
||||
(doc sum-length "returns the sum of lengths from a nested array `xs`.")
|
||||
@ -276,7 +290,7 @@ The trailing elements of the longer array will be discarded.")
|
||||
(let-do [sum 0
|
||||
lxs (Array.length xs)]
|
||||
(for [i 0 lxs]
|
||||
(set! sum (+ sum (Array.length (Array.nth xs i)))))
|
||||
(set! sum (+ sum (Array.length (Array.unsafe-nth xs i)))))
|
||||
sum))
|
||||
|
||||
(doc zero "returns the empty array.")
|
||||
@ -292,19 +306,27 @@ The trailing elements of the longer array will be discarded.")
|
||||
lxs (Array.length xs)
|
||||
result (Array.allocate (sum-length xs))]
|
||||
(for [i 0 lxs]
|
||||
(let-do [arr (Array.nth xs i)
|
||||
(let-do [arr (Array.unsafe-nth xs i)
|
||||
len (Array.length arr)]
|
||||
(for [k 0 len]
|
||||
(aset-uninitialized! &result (+ j k) @(Array.nth arr k)))
|
||||
(aset-uninitialized! &result (+ j k) @(Array.unsafe-nth arr k)))
|
||||
(set! j (+ j len))))
|
||||
result))
|
||||
|
||||
(doc enumerated "creates a new array of `Pair`s where the first position is the index and the second position is the element from the original array `xs`.")
|
||||
(defn enumerated [xs]
|
||||
(zip &Pair.init-from-refs
|
||||
&(range 0 (length xs) 1) ;; Inefficient, creates a temporary array.
|
||||
&(range 0 (length xs) 1) ; Inefficient, creates a temporary array.
|
||||
xs))
|
||||
|
||||
(doc nth "gets a reference to the `n`th element from an array `arr` wrapped on a `Maybe`.
|
||||
|
||||
If the `index` is out of bounds, return `Maybe.Nothing`")
|
||||
(defn nth [xs index]
|
||||
(if (and (>= index 0) (< index (length xs)))
|
||||
(Maybe.Just @(unsafe-nth xs index)) ; the copy will go away with lifetimes
|
||||
(Maybe.Nothing)))
|
||||
|
||||
(doc remove "removes all occurrences of the element `el` in the array `arr`, in place.")
|
||||
(defn remove [el arr]
|
||||
(endo-filter &(fn [x] (not (= el x)))
|
||||
@ -316,11 +338,56 @@ The trailing elements of the longer array will be discarded.")
|
||||
;;(assert (<= 0 i))
|
||||
;;(assert (< i (Array.length &arr)))
|
||||
(for [j i (Int.dec (Array.length &arr))]
|
||||
(aset! &arr j @(nth &arr (inc j))))
|
||||
(aset! &arr j @(unsafe-nth &arr (inc j))))
|
||||
(pop-back arr)))
|
||||
|
||||
(doc copy-filter "filters the elements in an array.
|
||||
|
||||
It will create a copy. If you want to avoid that, consider using [`endo-filter`](#endo-filter) instead.")
|
||||
(defn copy-filter [f a] (endo-filter f @a))
|
||||
(defn copy-filter [f a] (endo-filter f @a))
|
||||
|
||||
(doc contains? "checks wether an element exists in the array.")
|
||||
(defn contains? [arr el]
|
||||
(let-do [result false]
|
||||
(for [i 0 (Array.length arr)]
|
||||
(when (= el (Array.unsafe-nth arr i))
|
||||
(do
|
||||
(set! result true)
|
||||
(break))))
|
||||
result))
|
||||
|
||||
(doc partition
|
||||
"Partitions an array `arr` into an array of arrays of length `n`
|
||||
sequentially filled with the `arr`'s original values.
|
||||
|
||||
This function will fill partitions until `arr` is exhuasted.
|
||||
|
||||
If `n` is greater than or equal to the length of `arr`, the result of this
|
||||
function is an array containing a single array of length `n`.
|
||||
|
||||
For example:
|
||||
|
||||
```clojure
|
||||
(Array.partition &[1 2 3 4] 2)
|
||||
=> [[1 2] [3 4]]
|
||||
(Array.partition &[1 2 3 4] 3)
|
||||
=> [[1 2 3] [4]]
|
||||
(Array.partition &[1 2 3 4] 6)
|
||||
=> [[1 2 3 4]]
|
||||
```")
|
||||
(sig partition (Fn [(Ref (Array a) b) Int] (Array (Array a))))
|
||||
(defn partition [arr n]
|
||||
(let-do [x 0
|
||||
y 0
|
||||
a []]
|
||||
;; We use while since we're doing custom incrementation of x
|
||||
;; dealing with the extra increment implicitly called by for is messier
|
||||
(while (< x (Array.length arr))
|
||||
(do
|
||||
(set! y (+ x n))
|
||||
(when (> y (Array.length arr))
|
||||
(set! y (Array.length arr)))
|
||||
(set! a (push-back a (Array.slice arr x y)))
|
||||
(set! x y)))
|
||||
a))
|
||||
)
|
||||
|
@ -1,13 +1,16 @@
|
||||
(load "Statistics.carp")
|
||||
|
||||
(system-include "carp_bench.h")
|
||||
(register get-time-elapsed (Fn [] Double))
|
||||
|
||||
(defmodule Bench
|
||||
(def min-runs 50)
|
||||
(private min-runs)
|
||||
(hidden min-runs)
|
||||
|
||||
(private get-time-elapsed)
|
||||
(hidden get-time-elapsed)
|
||||
(register get-time-elapsed (Fn [] Double) "get_time_elapsed")
|
||||
|
||||
(doc set-min-runs! "sets the minimum number of runs to `n`.
|
||||
|
||||
If your functions takes a large amount of time, experimenting with this might make sense. The default value is `50`, which means that your function runs at least `50` times before even hitting a timeout.")
|
||||
@ -106,15 +109,15 @@ If your functions takes a large amount of time, experimenting with this might ma
|
||||
|
||||
|
||||
(defmacro benchn [n form]
|
||||
(list 'let ['before (get-time-elapsed)
|
||||
(list 'let ['before (Bench.get-time-elapsed)
|
||||
'times []]
|
||||
(list 'do
|
||||
(list 'for ['i 0 n]
|
||||
(list 'let ['before-once (get-time-elapsed)]
|
||||
(list 'let ['before-once (Bench.get-time-elapsed)]
|
||||
(list 'do
|
||||
form
|
||||
(list 'set! × (Array.push-back (Array.copy ×) (Double.- (get-time-elapsed) before-once))))))
|
||||
(list 'let ['total (Double.- (get-time-elapsed) before)
|
||||
(list 'set! × (Array.push-back (Array.copy ×) (Double.- (Bench.get-time-elapsed) before-once))))))
|
||||
(list 'let ['total (Double.- (Bench.get-time-elapsed) before)
|
||||
'per (list 'Double./ 'total (list 'Double.from-int n))]
|
||||
(do
|
||||
(Bench.print "Total time elapsed: " total)
|
||||
|
365
core/Binary.carp
Normal file
365
core/Binary.carp
Normal file
@ -0,0 +1,365 @@
|
||||
(system-include "carp_binary.h")
|
||||
(load "StdInt.carp")
|
||||
|
||||
;; Helper functions for making working with Maybe easier
|
||||
;; TODO: Replace all of these with a single type-generic
|
||||
;; zip-n macro.
|
||||
(defmodule Maybe
|
||||
(defn zip [f a b]
|
||||
(match a
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x)
|
||||
(match b
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just y) (Just (~f x y)))))
|
||||
|
||||
(defn zip4 [f a b c d]
|
||||
(match a
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x)
|
||||
(match b
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just y)
|
||||
(match c
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just z)
|
||||
(match d
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x2) (Just (~f x y z x2)))))))
|
||||
|
||||
(defn zip8 [f a b c d e a1 b1 c1]
|
||||
(match a
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x)
|
||||
(match b
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just y)
|
||||
(match c
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just z)
|
||||
(match d
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x2)
|
||||
(match e
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just y2)
|
||||
(match a1
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just z2)
|
||||
(match b1
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just x3)
|
||||
(match c1
|
||||
(Maybe.Nothing) (Maybe.Nothing)
|
||||
(Just y3) (Just (~f x y z x2 y2 z2 x3 y3)))))))))))
|
||||
)
|
||||
|
||||
;; Temporary fix for issue #698
|
||||
;; The underlying issue is deeper, and should probably be fixed.
|
||||
(doc ByteOrder
|
||||
"The type of byte orders.
|
||||
|
||||
LittleEndian designates the little endian ordering, and indicates the least
|
||||
significant byte appears first in a given byte sequence.
|
||||
|
||||
BigEndian designates the big endian ordering, and indicates the most
|
||||
significant byte occurs first in a given byte sequence.")
|
||||
(deftype ByteOrder LittleEndian BigEndian)
|
||||
|
||||
(defmodule Binary
|
||||
(register to-int16 (λ [Byte Byte] Uint16))
|
||||
(register to-int32 (λ [Byte Byte Byte Byte] Uint32))
|
||||
(register to-int64 (λ [Byte Byte Byte Byte Byte Byte Byte Byte] Uint64))
|
||||
(register int16-to-byte (λ [(Ref Uint16)] Byte))
|
||||
(register int32-to-byte (λ [(Ref Uint32)] Byte))
|
||||
(register int64-to-byte (λ [(Ref Uint64)] Byte))
|
||||
(register system-endianness-internal (λ [] Int))
|
||||
|
||||
(defn unwrap-success [x]
|
||||
(Result.unwrap-or-zero @x))
|
||||
|
||||
(defn unwrap-error [x]
|
||||
(Result.from-error @x (zero)))
|
||||
|
||||
(doc byte-converter
|
||||
"Returns a function that, when called, attempts to convert an array of bytes using `f` and `order`
|
||||
|
||||
If the conversion is successful, returns a `Result.Success` containing the converted value.
|
||||
|
||||
If the conversion fails, returns a `Result.Error` containing the byte array passed as an argument.")
|
||||
(defn byte-converter [f order]
|
||||
(fn [bs]
|
||||
(match (~f order bs)
|
||||
(Maybe.Nothing) (Result.Error @bs)
|
||||
(Maybe.Just i) (Result.Success i))))
|
||||
(doc interpreted
|
||||
"Returns the interpreted value from a sequence of byte-converion results")
|
||||
(private interpreted)
|
||||
(defn interpreted [results]
|
||||
(==> results
|
||||
(Array.copy-filter &Result.success?)
|
||||
(ref)
|
||||
(Array.copy-map &unwrap-success)))
|
||||
|
||||
(doc remaining-bytes
|
||||
"Returns the number of uninterpreted bytes from a seuqence of byte-conversion results")
|
||||
(private remaining-bytes)
|
||||
(defn remaining-bytes [results]
|
||||
(==> results
|
||||
(Array.copy-filter &Result.error?)
|
||||
(ref)
|
||||
(Array.copy-map &unwrap-error)
|
||||
(ref)
|
||||
(Array.copy-map &Array.length)
|
||||
(ref)
|
||||
(Array.reduce &(fn [x y] (+ x @y)) 0)))
|
||||
|
||||
(doc system-endianness
|
||||
"Returns the endianness of the host system.")
|
||||
(sig system-endianness (λ [] ByteOrder))
|
||||
(defn system-endianness []
|
||||
(if (= (system-endianness-internal) 1)
|
||||
(ByteOrder.LittleEndian)
|
||||
(ByteOrder.BigEndian)))
|
||||
|
||||
(doc unsafe-bytes->int16
|
||||
"Interprets the first two bytes in a byte sequence as an Uint16 value.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int16 (Fn [ByteOrder (Ref (Array Byte) a)] Uint16))
|
||||
(defn unsafe-bytes->int16 [order bs]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(to-int16 @(Array.unsafe-nth bs 0) @(Array.unsafe-nth bs 1))
|
||||
(ByteOrder.BigEndian)
|
||||
(to-int16 @(Array.unsafe-nth bs 1) @(Array.unsafe-nth bs 0))))
|
||||
|
||||
(doc bytes->int16
|
||||
"Interprets the first two bytes in a byte sequence as an Uint16 value.
|
||||
|
||||
If the first two bytes are inaccessible, or the given array contains less
|
||||
than two bytes, returns Maybe.Nothing.")
|
||||
(sig bytes->int16 (Fn [ByteOrder (Ref (Array Byte) a)] (Maybe Uint16)))
|
||||
(defn bytes->int16 [order bytes]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Maybe.zip &to-int16 (Array.nth bytes 0) (Array.nth bytes 1))
|
||||
(ByteOrder.BigEndian)
|
||||
(Maybe.zip &to-int16 (Array.nth bytes 1) (Array.nth bytes 0))))
|
||||
|
||||
(doc int16->bytes
|
||||
"Converts a Uint16 to a sequence of bytes representing the value using the provided `order`")
|
||||
(sig int16->bytes (Fn [ByteOrder Uint16] (Array Byte)))
|
||||
(defn int16->bytes [order i]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Array.copy-map &int16-to-byte &[i (Uint16.bit-shift-right i (Uint16.from-long 8l))])
|
||||
(ByteOrder.BigEndian)
|
||||
(Array.copy-map &int16-to-byte &[(Uint16.bit-shift-right i (Uint16.from-long 8l)) i])))
|
||||
|
||||
(doc unsafe-bytes->int16-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint16 values.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int16-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Array Uint16)))
|
||||
(defn unsafe-bytes->int16-seq [order bs]
|
||||
(let [partitions (Array.partition bs 2)
|
||||
f (fn [b] (unsafe-bytes->int16 order b))]
|
||||
(Array.copy-map &f &partitions)))
|
||||
|
||||
(doc bytes->int16-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint16 values.
|
||||
|
||||
Returns a pair containing interpreted values and the number of bytes that were not interpreted.")
|
||||
(sig bytes->int16-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Pair (Array Uint16) Int)))
|
||||
(defn bytes->int16-seq [order bs]
|
||||
(let [partitions (Array.partition bs 2)
|
||||
f (byte-converter &bytes->int16 order)]
|
||||
(let [results (Array.copy-map &f &partitions)]
|
||||
(Pair.init (interpreted &results) (remaining-bytes &results)))))
|
||||
|
||||
(doc bytes->int16-seq-exact
|
||||
"Attempts to interpret a given byte sequence as an exact sequence of Uint16 values.
|
||||
|
||||
If successful, returns the interpreted values. If unsuccessful, returns the number of excess bytes.")
|
||||
(sig bytes->int16-seq-exact (Fn [ByteOrder (Ref (Array Byte) a)] (Result (Array Uint16) Int)))
|
||||
(defn bytes->int16-seq-exact [order bs]
|
||||
(let [r (bytes->int16-seq order bs)]
|
||||
(if (= 0 @(Pair.b &r))
|
||||
(Result.Success @(Pair.a &r))
|
||||
(Result.Error @(Pair.b &r)))))
|
||||
|
||||
(doc int16-seq->bytes
|
||||
"Converts an array of Uint16 values into byte sequences.")
|
||||
(sig int16-seq->bytes (Fn [ByteOrder (Ref (Array Uint16) a)] (Array (Array Byte))))
|
||||
(defn int16-seq->bytes [order is]
|
||||
(let [f (fn [i] (int16->bytes order @i))]
|
||||
(Array.copy-map &f is)))
|
||||
|
||||
(doc unsafe-bytes->int32
|
||||
"Interprets the first four bytes in a byte sequence as an Uint32 value.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int32 (Fn [ByteOrder (Ref (Array Byte))] Uint32))
|
||||
(defn unsafe-bytes->int32 [order bs]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(to-int32 @(Array.unsafe-nth bs 0) @(Array.unsafe-nth bs 1)
|
||||
@(Array.unsafe-nth bs 2) @(Array.unsafe-nth bs 3))
|
||||
(ByteOrder.BigEndian)
|
||||
(to-int32 @(Array.unsafe-nth bs 3) @(Array.unsafe-nth bs 2)
|
||||
@(Array.unsafe-nth bs 1) @(Array.unsafe-nth bs 0))))
|
||||
|
||||
(doc bytes->int32
|
||||
"Interprets the first four bytes in a byte sequence as an Uint32 value.
|
||||
|
||||
If the first four bytes are inaccessible, or the given array contains less
|
||||
than four bytes, returns Maybe.Nothing.")
|
||||
(sig bytes->int32 (Fn [ByteOrder (Ref (Array Byte))] (Maybe Uint32)))
|
||||
(defn bytes->int32 [order bs]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Maybe.zip4 &to-int32 (Array.nth bs 0) (Array.nth bs 1)
|
||||
(Array.nth bs 2) (Array.nth bs 3))
|
||||
(ByteOrder.BigEndian)
|
||||
(Maybe.zip4 &to-int32 (Array.nth bs 3) (Array.nth bs 2)
|
||||
(Array.nth bs 1) (Array.nth bs 0))))
|
||||
|
||||
(doc int32->bytes
|
||||
"Converts a Uint32 to a sequence of bytes representing the value using the provided `order`")
|
||||
(sig int32->bytes (Fn [ByteOrder Uint32] (Array Byte)))
|
||||
(defn int32->bytes [order i]
|
||||
(let [shift (fn [lng] (Uint32.bit-shift-right i (Uint32.from-long lng)))]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Array.copy-map &int32-to-byte
|
||||
&[i (shift 8l) (shift 16l) (shift 24l)])
|
||||
(ByteOrder.BigEndian)
|
||||
(Array.copy-map &int32-to-byte
|
||||
&[(shift 24l) (shift 16l) (shift 8l) i]))))
|
||||
|
||||
(doc unsafe-bytes->int32-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint32 values.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int32-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Array Uint32)))
|
||||
(defn unsafe-bytes->int32-seq [order bs]
|
||||
(let [partitions (Array.partition bs 4)
|
||||
f (fn [b] (unsafe-bytes->int32 order b))]
|
||||
(Array.copy-map &f &partitions)))
|
||||
|
||||
(doc bytes->int32-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint32 values.
|
||||
|
||||
Returns a pair containing interpreted values and the number of bytes that were not interpreted.")
|
||||
(sig bytes->int32-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Pair (Array Uint32) Int)))
|
||||
(defn bytes->int32-seq [order bs]
|
||||
(let [partitions (Array.partition bs 4)
|
||||
f (byte-converter &bytes->int32 order)]
|
||||
(let [results (Array.copy-map &f &partitions)]
|
||||
(Pair.init (interpreted &results) (remaining-bytes &results)))))
|
||||
|
||||
(doc bytes->int32-seq-exact
|
||||
"Attempts to interpret a given byte sequence as an exact sequence of Uint32 values.
|
||||
|
||||
If successful, returns the interpreted values. If unsuccessful, returns the number of excess bytes.")
|
||||
(sig bytes->int32-seq-exact (Fn [ByteOrder (Ref (Array Byte) a)] (Result (Array Uint32) Int)))
|
||||
(defn bytes->int32-seq-exact [order bs]
|
||||
(let [r (bytes->int32-seq order bs)]
|
||||
(if (= 0 @(Pair.b &r))
|
||||
(Result.Success @(Pair.a &r))
|
||||
(Result.Error @(Pair.b &r)))))
|
||||
|
||||
(doc int32-seq->bytes
|
||||
"Converts an array of Uint32 values into byte sequences.")
|
||||
(sig int32-seq->bytes (Fn [ByteOrder (Ref (Array Uint32) a)] (Array (Array Byte))))
|
||||
(defn int32-seq->bytes [order is]
|
||||
(let [f (fn [i] (int32->bytes order @i))]
|
||||
(Array.copy-map &f is)))
|
||||
|
||||
(doc unsafe-bytes->int64
|
||||
"Interprets the first eight bytes in a byte sequence as an Uint64 value.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int64 (Fn [ByteOrder (Ref (Array Byte) a)] Uint64))
|
||||
(defn unsafe-bytes->int64 [order bs]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(to-int64 @(Array.unsafe-nth bs 0) @(Array.unsafe-nth bs 1)
|
||||
@(Array.unsafe-nth bs 2) @(Array.unsafe-nth bs 3)
|
||||
@(Array.unsafe-nth bs 4) @(Array.unsafe-nth bs 5)
|
||||
@(Array.unsafe-nth bs 6) @(Array.unsafe-nth bs 7))
|
||||
(ByteOrder.BigEndian)
|
||||
(to-int64 @(Array.unsafe-nth bs 7) @(Array.unsafe-nth bs 6)
|
||||
@(Array.unsafe-nth bs 5) @(Array.unsafe-nth bs 4)
|
||||
@(Array.unsafe-nth bs 3) @(Array.unsafe-nth bs 2)
|
||||
@(Array.unsafe-nth bs 1) @(Array.unsafe-nth bs 0))))
|
||||
|
||||
(doc bytes->int64
|
||||
"Interprets the first eight bytes in a byte sequence as an Uint64 value.
|
||||
|
||||
If the first eight bytes are inaccessible, or the given array contains less
|
||||
than eight bytes, returns Maybe.Nothing.")
|
||||
(sig bytes->int64 (Fn [ByteOrder (Ref (Array Byte) a)] (Maybe Uint64)))
|
||||
(defn bytes->int64 [order bs]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Maybe.zip8 &to-int64 (Array.nth bs 0) (Array.nth bs 1)
|
||||
(Array.nth bs 2) (Array.nth bs 3)
|
||||
(Array.nth bs 4) (Array.nth bs 5)
|
||||
(Array.nth bs 6) (Array.nth bs 7))
|
||||
(ByteOrder.BigEndian)
|
||||
(Maybe.zip8 &to-int64 (Array.nth bs 7) (Array.nth bs 6)
|
||||
(Array.nth bs 5) (Array.nth bs 4)
|
||||
(Array.nth bs 3) (Array.nth bs 2)
|
||||
(Array.nth bs 1) (Array.nth bs 0))))
|
||||
(doc int64->bytes
|
||||
"Converts a Uint64 to a sequence of bytes representing the value using the provided `order`")
|
||||
(sig int64->bytes (Fn [ByteOrder Uint64] (Array Byte)))
|
||||
(defn int64->bytes [order i]
|
||||
(let [shift (fn [lng] (Uint64.bit-shift-right i (Uint64.from-long lng)))]
|
||||
(match order
|
||||
(ByteOrder.LittleEndian)
|
||||
(Array.copy-map &int64-to-byte
|
||||
&[i (shift 8l) (shift 16l)
|
||||
(shift 24l) (shift 32l)
|
||||
(shift 40l) (shift 48l) (shift 56l)])
|
||||
(ByteOrder.BigEndian)
|
||||
(Array.copy-map &int64-to-byte
|
||||
&[(shift 56l) (shift 48l)
|
||||
(shift 40l) (shift 32l)
|
||||
(shift 24l) (shift 16l) (shift 8l) i]))))
|
||||
|
||||
(doc unsafe-bytes->int64-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint64 values.
|
||||
**This operation is unsafe.**")
|
||||
(sig unsafe-bytes->int64-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Array Uint64)))
|
||||
(defn unsafe-bytes->int64-seq [order bs]
|
||||
(let [partitions (Array.partition bs 8)
|
||||
f (fn [b] (unsafe-bytes->int64 order b))]
|
||||
(Array.copy-map &f &partitions)))
|
||||
|
||||
(doc bytes->int64-seq
|
||||
"Interprets a sequence of bytes as a sequence of Uint64 values.
|
||||
|
||||
Returns a pair containing interpreted values and the number of bytes that were not interpreted.")
|
||||
(sig bytes->int64-seq (Fn [ByteOrder (Ref (Array Byte) a)] (Pair (Array Uint64) Int)))
|
||||
(defn bytes->int64-seq [order bs]
|
||||
(let [partitions (Array.partition bs 8)
|
||||
f (byte-converter &bytes->int64 order)]
|
||||
(let [results (Array.copy-map &f &partitions)]
|
||||
(Pair.init (interpreted &results) (remaining-bytes &results)))))
|
||||
|
||||
(doc bytes->int64-seq-exact
|
||||
"Attempts to interpret a given byte sequence as an exact sequence of Uint64 values.
|
||||
|
||||
If successful, returns the interpreted values. If unsuccessful, returns the number of excess bytes.")
|
||||
(sig bytes->int64-seq-exact (Fn [ByteOrder (Ref (Array Byte) a)] (Result (Array Uint64) Int)))
|
||||
(defn bytes->int64-seq-exact [order bs]
|
||||
(let [r (bytes->int64-seq order bs)]
|
||||
(if (= 0 @(Pair.b &r))
|
||||
(Result.Success @(Pair.a &r))
|
||||
(Result.Error @(Pair.b &r)))))
|
||||
|
||||
(doc int64-seq->bytes
|
||||
"Converts an array of Uint64 values into byte sequences.")
|
||||
(sig int64-seq->bytes (Fn [ByteOrder (Ref (Array Uint64) a)] (Array (Array Byte))))
|
||||
(defn int64-seq->bytes [order is]
|
||||
(let [f (fn [i] (int64->bytes order @i))]
|
||||
(Array.copy-map &f is)))
|
||||
)
|
@ -2,11 +2,15 @@
|
||||
|
||||
(defmodule Bool
|
||||
(register = (Fn [Bool Bool] Bool))
|
||||
(register /= (Fn [Bool Bool] Bool))
|
||||
(register copy (Fn [&Bool] Bool))
|
||||
(register format (Fn [&String Bool] String))
|
||||
(register not (Fn [Bool] Bool))
|
||||
(register and (Fn [Bool Bool] Bool))
|
||||
(register or (Fn [Bool Bool] Bool))
|
||||
)
|
||||
|
||||
(defmodule RefBool
|
||||
(defn = [a b]
|
||||
(Bool.= @a @b)))
|
||||
|
||||
(defn not [a] (Bool.not a))
|
||||
|
61
core/Byte.carp
Normal file
61
core/Byte.carp
Normal file
@ -0,0 +1,61 @@
|
||||
(system-include "carp_byte.h")
|
||||
|
||||
(defmodule Byte
|
||||
(register + (λ [Byte Byte] Byte))
|
||||
(register - (λ [Byte Byte] Byte))
|
||||
(register * (λ [Byte Byte] Byte))
|
||||
(register / (λ [Byte Byte] Byte))
|
||||
(register < (λ [Byte Byte] Bool))
|
||||
(register > (λ [Byte Byte] Bool))
|
||||
(register = (λ [Byte Byte] Bool))
|
||||
(register mod (λ [Byte Byte] Byte))
|
||||
(register bit-shift-left (λ [Byte Byte] Byte))
|
||||
(register bit-shift-right (λ [Byte Byte] Byte))
|
||||
(register bit-and (λ [Byte Byte] Byte))
|
||||
(register bit-or (λ [Byte Byte] Byte))
|
||||
(register bit-xor (λ [Byte Byte] Byte))
|
||||
(register bit-not (λ [Byte] Byte))
|
||||
(register inc (λ [Byte] Byte))
|
||||
(register dec (λ [Byte] Byte))
|
||||
(register copy (λ [&Byte] Byte))
|
||||
(register to-int (λ [Byte] Int))
|
||||
(register from-int (λ [Int] Byte))
|
||||
|
||||
(defn even? [a] (= (mod a 2b) 0b))
|
||||
(defn odd? [a] (not (even? a)))
|
||||
|
||||
(defn zero [] 0b)
|
||||
|
||||
(defn add-ref [x y]
|
||||
(Byte.+ @x @y))
|
||||
|
||||
;; Move to generic math module?
|
||||
(defn clamp [min, max, val]
|
||||
(if (> val max)
|
||||
max
|
||||
(if (< val min)
|
||||
min
|
||||
val)))
|
||||
|
||||
(doc pow "Raise x to the power of y.")
|
||||
(defn pow [x y]
|
||||
(let-do [r 1b]
|
||||
(while (/= y 0b)
|
||||
(do
|
||||
(when (/= (bit-and y 1b) 0b)
|
||||
(set! r (* r x)))
|
||||
(set! y (/ y 2b))
|
||||
(set! x (* x x))))
|
||||
r))
|
||||
)
|
||||
|
||||
(defmodule ByteRef
|
||||
(defn = [a b]
|
||||
(Byte.= @a @b))
|
||||
|
||||
(defn < [a b]
|
||||
(Byte.< @a @b))
|
||||
|
||||
(defn > [a b]
|
||||
(Byte.> @a @b))
|
||||
)
|
@ -10,21 +10,19 @@
|
||||
|
||||
(doc meaning "converts a numerical char into the appropriate number (e.g. from `\1` to `1`).")
|
||||
(defn meaning [char-ref]
|
||||
(cond
|
||||
(= @char-ref \0) 0
|
||||
(= @char-ref \1) 1
|
||||
(= @char-ref \2) 2
|
||||
(= @char-ref \3) 3
|
||||
(= @char-ref \4) 4
|
||||
(= @char-ref \5) 5
|
||||
(= @char-ref \6) 6
|
||||
(= @char-ref \7) 7
|
||||
(= @char-ref \8) 8
|
||||
(= @char-ref \9) 9
|
||||
-1))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= (the Char a) b)))
|
||||
(let [c @char-ref]
|
||||
(case c
|
||||
\0 0
|
||||
\1 1
|
||||
\2 2
|
||||
\3 3
|
||||
\4 4
|
||||
\5 5
|
||||
\6 6
|
||||
\7 7
|
||||
\8 8
|
||||
\9 9
|
||||
-1)))
|
||||
|
||||
(doc lower-case? "tests whether a character is lower case.")
|
||||
(defn lower-case? [c]
|
||||
@ -46,15 +44,12 @@
|
||||
(defn alphanum? [c]
|
||||
(or (alpha? c) (num? c)))
|
||||
|
||||
(defn zero []
|
||||
(from-int 0))
|
||||
(defn zero [] (the Char (from-int 0)))
|
||||
)
|
||||
|
||||
(defmodule CharRef
|
||||
(defn = [a b]
|
||||
(Char.= @a @b))
|
||||
(defn /= [a b]
|
||||
(Char./= @a @b))
|
||||
(defn < [a b]
|
||||
(Char.< @a @b))
|
||||
(defn > [a b]
|
||||
|
@ -1,48 +1,78 @@
|
||||
(defmodule Color
|
||||
(hidden table)
|
||||
(deftype Id
|
||||
Black
|
||||
Red
|
||||
Green
|
||||
Yellow
|
||||
Blue
|
||||
Magenta
|
||||
Cyan
|
||||
White
|
||||
Reset
|
||||
None
|
||||
Bold
|
||||
Italic
|
||||
Underline
|
||||
BlinkSlow
|
||||
BlinkRapid
|
||||
BgBlack
|
||||
BgRed
|
||||
BgGreen
|
||||
BgYellow
|
||||
BgBlue
|
||||
BgMagenta
|
||||
BgCyan
|
||||
BgWhite)
|
||||
(use Id)
|
||||
(defn hash [k]
|
||||
(get-tag k))
|
||||
(defn = [a b]
|
||||
(= (hash (the (Ref Id) a)) (hash b)))
|
||||
|
||||
(def table
|
||||
{@"black" @"30"
|
||||
@"red" @"31"
|
||||
@"green" @"32"
|
||||
@"yellow" @"33"
|
||||
@"blue" @"34"
|
||||
@"magenta" @"35"
|
||||
@"cyan" @"36"
|
||||
@"white" @"37"
|
||||
@"reset" @"0"
|
||||
@"none" @"0"
|
||||
@"bold" @"1"
|
||||
@"italic" @"3"
|
||||
@"underline" @"4"
|
||||
@"blink-slow" @"5"
|
||||
@"blink-rapid" @"6"
|
||||
@"bg-black" @"40"
|
||||
@"bg-red" @"41"
|
||||
@"bg-green" @"42"
|
||||
@"bg-yellow" @"43"
|
||||
@"bg-blue" @"44"
|
||||
@"bg-magenta" @"45"
|
||||
@"bg-cyan" @"46"
|
||||
@"bg-white" @"47"})
|
||||
{(Black) @"30"
|
||||
(Red) @"31"
|
||||
(Green) @"32"
|
||||
(Yellow) @"33"
|
||||
(Blue) @"34"
|
||||
(Magenta) @"35"
|
||||
(Cyan) @"36"
|
||||
(White) @"37"
|
||||
(Reset) @"0"
|
||||
(None) @"0"
|
||||
(Bold) @"1"
|
||||
(Italic) @"3"
|
||||
(Underline) @"4"
|
||||
(BlinkSlow) @"5"
|
||||
(BlinkRapid) @"6"
|
||||
(BgBlack) @"40"
|
||||
(BgRed) @"41"
|
||||
(BgGreen) @"42"
|
||||
(BgYellow) @"43"
|
||||
(BgBlue) @"44"
|
||||
(BgMagenta) @"45"
|
||||
(BgCyan) @"46"
|
||||
(BgWhite) @"47"})
|
||||
|
||||
(doc color "generates ANSI coloration based on a color name `cname`.")
|
||||
(defn color [cname]
|
||||
(let [n (Map.get &table cname)]
|
||||
(defn color [cid]
|
||||
(let [n (Map.get &table &cid)]
|
||||
(String.append "\x1b[" &(String.append &n "m"))))
|
||||
|
||||
(doc colorize "wraps a string `s` in ANSI coloration based on a color name `cname` and prints it.
|
||||
(doc colorize "wraps a string `s` in ANSI coloration based on a color id `cid` and prints it.
|
||||
|
||||
It will reset the color afterwards.")
|
||||
(defn colorize [cname s]
|
||||
(String.append &(color cname) &(String.append s &(color "reset"))))
|
||||
(defn colorize [cid s]
|
||||
(String.append &(color cid) &(String.append s &(color (Reset)))))
|
||||
)
|
||||
|
||||
(defmodule IO
|
||||
(doc color "sets the output color using ANSI coloration based on a color name `cname`.")
|
||||
(defn color [cname]
|
||||
(print &(Color.color cname)))
|
||||
(doc color "sets the output color using ANSI coloration based on a color id `cid`.")
|
||||
(defn color [cid]
|
||||
(print &(Color.color cid)))
|
||||
|
||||
(doc colorize "wraps a string in ANSI coloration based on a color name `cname` and prints it.")
|
||||
(defn colorize [cname s]
|
||||
(print &(Color.colorize cname s)))
|
||||
(doc colorize "wraps a string in ANSI coloration based on a color id `cid` and prints it.")
|
||||
(defn colorize [cid s]
|
||||
(print &(Color.colorize cid s)))
|
||||
)
|
||||
|
@ -1,9 +1,35 @@
|
||||
(system-include "assert.h")
|
||||
(system-include "stddef.h")
|
||||
(system-include "stdlib.h")
|
||||
(system-include "stdint.h")
|
||||
(system-include "inttypes.h")
|
||||
(system-include "float.h")
|
||||
(system-include "limits.h")
|
||||
(system-include "string.h")
|
||||
(system-include "math.h")
|
||||
(system-include "ctype.h")
|
||||
(system-include "stdarg.h")
|
||||
(system-include "stdio.h")
|
||||
(system-include "time.h")
|
||||
(system-include "carp_stdbool.h")
|
||||
(system-include "core.h")
|
||||
(system-include "carp_memory.h")
|
||||
|
||||
(if (not (Dynamic.or (= "windows" (os)) (= "mingw32" (os))))
|
||||
(do
|
||||
(system-include "sys/wait.h")
|
||||
(system-include "unistd.h"))
|
||||
())
|
||||
|
||||
(load "Interfaces.carp")
|
||||
(load "Bool.carp")
|
||||
(load "Generics.carp")
|
||||
(load "Macros.carp")
|
||||
(load "Maybe.carp")
|
||||
(load "Result.carp")
|
||||
(load "Dynamic.carp")
|
||||
(load "Format.carp")
|
||||
(load "Byte.carp")
|
||||
(load "Int.carp")
|
||||
(load "Long.carp")
|
||||
(load "Double.carp")
|
||||
@ -11,14 +37,16 @@
|
||||
(load "Tuples.carp")
|
||||
(load "Array.carp")
|
||||
(load "Char.carp")
|
||||
(load "Bool.carp")
|
||||
(load "String.carp")
|
||||
(load "IO.carp")
|
||||
(load "StdInt.carp")
|
||||
(load "System.carp")
|
||||
(load "IO.carp")
|
||||
(load "Pattern.carp")
|
||||
(load "Debug.carp")
|
||||
(load "Pointer.carp")
|
||||
(load "Format.carp")
|
||||
(load "Random.carp")
|
||||
(load "Map.carp")
|
||||
(load "Heap.carp")
|
||||
(load "Sort.carp")
|
||||
(load "Binary.carp")
|
||||
|
@ -54,4 +54,4 @@ immediately, raising a `SIGABRT` if it fails.")
|
||||
()
|
||||
(list 'do
|
||||
(list 'println* (list 'fmt "Assertion '%s' failed at line %d, column %d in file %s" (str expr) (line) (column) (file)))
|
||||
'(System.exit 1))))
|
||||
'(System.abort))))
|
||||
|
@ -3,6 +3,7 @@
|
||||
(defmodule Double
|
||||
(def pi 3.141592653589793)
|
||||
(def e 2.718281828459045)
|
||||
(register MAX Double "CARP_DBL_MAX")
|
||||
(register = (Fn [Double Double] Bool))
|
||||
(register < (Fn [Double Double] Bool))
|
||||
(register > (Fn [Double Double] Bool))
|
||||
@ -18,52 +19,47 @@
|
||||
(register to-long (Fn [Double] Long))
|
||||
(register from-long (Fn [Long] Double))
|
||||
(register to-bytes (Fn [Double] Long))
|
||||
(register sin (Fn [Double] Double))
|
||||
(register cos (Fn [Double] Double))
|
||||
(register tan (Fn [Double] Double))
|
||||
(register copy (Fn [(Ref Double)] Double))
|
||||
|
||||
(register abs (Fn [Double] Double))
|
||||
(register acos (Fn [Double] Double))
|
||||
(register asin (Fn [Double] Double))
|
||||
(register atan (Fn [Double] Double))
|
||||
(register atan2 (Fn [Double Double] Double))
|
||||
(register ceil (Fn [Double] Double))
|
||||
(register cos (Fn [Double] Double))
|
||||
(register cosh (Fn [Double] Double))
|
||||
(register sinh (Fn [Double] Double))
|
||||
(register tanh (Fn [Double] Double))
|
||||
(register exp (Fn [Double] Double))
|
||||
(register floor (Fn [Double] Double))
|
||||
(register frexp (Fn [Double (Ref Int)] Double))
|
||||
(register ldexp (Fn [Double Int] Double))
|
||||
(register log (Fn [Double] Double))
|
||||
(register log10 (Fn [Double] Double))
|
||||
(register mod (Fn [Double Double] Double))
|
||||
(register modf (Fn [Double (Ref Double)] Double))
|
||||
(register pow (Fn [Double Double] Double))
|
||||
(register sin (Fn [Double] Double))
|
||||
(register sinh (Fn [Double] Double))
|
||||
(register sqrt (Fn [Double] Double))
|
||||
(register floor (Fn [Double] Double))
|
||||
(register ceil (Fn [Double] Double))
|
||||
(register mod (Fn [Double Double] Double))
|
||||
(register copy (Fn [(Ref Double)] Double))
|
||||
(register abs (Fn [Double] Double))
|
||||
|
||||
(defn clamp [min, max, val]
|
||||
(if (> val max)
|
||||
max
|
||||
(if (< val min)
|
||||
min
|
||||
val)))
|
||||
(register tan (Fn [Double] Double))
|
||||
(register tanh (Fn [Double] Double))
|
||||
|
||||
(doc approx "checks whether `x` and `y` are approximately equal.
|
||||
|
||||
The margin of error is `0.00001`.")
|
||||
(defn approx [x y]
|
||||
(if (> x y)
|
||||
(< (- x y) 0.00001)
|
||||
(< (- y x) 0.00001)))
|
||||
|
||||
(defn /= [x y]
|
||||
(not (Double.= x y)))
|
||||
(Generics.approx x y))
|
||||
|
||||
(doc zero "returns the value `0.0`.")
|
||||
(defn zero []
|
||||
0.0)
|
||||
|
||||
(defn inc [x]
|
||||
(+ 1.0 x))
|
||||
|
||||
(defn dec [x]
|
||||
(- x 1.0))
|
||||
|
||||
(defn add-ref [x y]
|
||||
(Double.+ @x @y))
|
||||
)
|
||||
|
@ -16,7 +16,17 @@
|
||||
(Project.config "print-ast" false)
|
||||
(Project.config "echo-compiler-cmd" false))))
|
||||
|
||||
(defmodule String
|
||||
(defndynamic prefix [s to]
|
||||
(String.slice s 0 to))
|
||||
|
||||
(defndynamic suffix [s from]
|
||||
(String.slice s from (String.length s)))
|
||||
|
||||
(defndynamic tail [s ]
|
||||
(String.suffix s 1))
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
;; The following functions are not put into a module for now:
|
||||
|
@ -6,7 +6,7 @@
|
||||
(defn dir-from-path [path]
|
||||
(let [segments (split-by path &[\/])
|
||||
n (dec (length &segments))
|
||||
without-last (prefix-array &segments n)]
|
||||
without-last (prefix &segments n)]
|
||||
(concat &(copy-map &(fn [s] (str* s "/")) &without-last))))
|
||||
|
||||
(doc file-from-path "removes the base name part of a path to a file, similar to the `filename` utility in Shell scripting.")
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
(defmodule Float
|
||||
(def pi 3.1415926536f)
|
||||
(register MAX Float "CARP_FLT_MAX")
|
||||
(register neg (Fn [Float] Float))
|
||||
(register + (Fn [Float Float] Float))
|
||||
(register - (Fn [Float Float] Float))
|
||||
@ -13,8 +14,6 @@
|
||||
(register copy (Fn [(Ref Float)] Float))
|
||||
|
||||
(register = (Fn [Float Float] Bool))
|
||||
(defn /= [x y]
|
||||
(not (Float.= x y)))
|
||||
(register < (Fn [Float Float] Bool))
|
||||
(register > (Fn [Float Float] Bool))
|
||||
|
||||
@ -29,38 +28,43 @@
|
||||
|
||||
The margin of error is 0.00001.")
|
||||
(defn approx [x y]
|
||||
(if (> x y)
|
||||
(< (- x y) 0.00001f)
|
||||
(< (- y x) 0.00001f)))
|
||||
(Generics.approx x y))
|
||||
|
||||
(register sin (Fn [Float] Float))
|
||||
(register cos (Fn [Float] Float))
|
||||
(register tan (Fn [Float] Float))
|
||||
(register copy (Fn [(Ref Float)] Float))
|
||||
|
||||
(register abs (Fn [Float] Float))
|
||||
(register acos (Fn [Float] Float))
|
||||
(register asin (Fn [Float] Float))
|
||||
(register atan (Fn [Float] Float))
|
||||
(register atan2 (Fn [Float Float] Float))
|
||||
(register ceil (Fn [Float] Float))
|
||||
(register cos (Fn [Float] Float))
|
||||
(register cosh (Fn [Float] Float))
|
||||
(register sinh (Fn [Float] Float))
|
||||
(register tanh (Fn [Float] Float))
|
||||
(register exp (Fn [Float] Float))
|
||||
(register floor (Fn [Float] Float))
|
||||
(register frexp (Fn [Float (Ref Int)] Float))
|
||||
(register ldexp (Fn [Float Int] Float))
|
||||
(register log (Fn [Float] Float))
|
||||
(register log10 (Fn [Float] Float))
|
||||
(register mod (Fn [Float Float] Float))
|
||||
(register modf (Fn [Float (Ref Float)] Float))
|
||||
(register pow (Fn [Float Float] Float))
|
||||
(register sin (Fn [Float] Float))
|
||||
(register sinh (Fn [Float] Float))
|
||||
(register sqrt (Fn [Float] Float))
|
||||
(register floor (Fn [Float] Float))
|
||||
(register ceil (Fn [Float] Float))
|
||||
(register mod (Fn [Float Float] Float))
|
||||
(register copy (Fn [(Ref Float)] Float))
|
||||
(register abs (Fn [Float] Float))
|
||||
(register tan (Fn [Float] Float))
|
||||
(register tanh (Fn [Float] Float))
|
||||
|
||||
(doc zero "returns `0.0f`.")
|
||||
(defn zero []
|
||||
0.0f)
|
||||
|
||||
(defn inc [x]
|
||||
(+ 1.0f x))
|
||||
|
||||
(defn dec [x]
|
||||
(- x 1.0f))
|
||||
|
||||
(defn add-ref [x y]
|
||||
(Float.+ @x @y))
|
||||
)
|
||||
|
@ -4,27 +4,40 @@
|
||||
(let [idx (String.index-of s \%)
|
||||
len (String.length s)]
|
||||
(if (= idx -1)
|
||||
(list 'copy s) ; no more splits found, just return string
|
||||
(if (= \% (String.char-at s (inc idx))) ; this is an escaped %
|
||||
(list 'ref
|
||||
(list 'String.append
|
||||
"%"
|
||||
(fmt-internal (String.substring s (+ idx 2) len) args)))
|
||||
(if (= 0 (length args)) ; we need to insert something, but have nothing
|
||||
(macro-error "error in format string: not enough arguments to format string")
|
||||
; okay, this is the meat:
|
||||
; get the next % after our escaper
|
||||
(let [next (String.index-of (String.substring s (inc idx) len) \%)]
|
||||
(if (= -1 next)
|
||||
(if (< 1 (length args))
|
||||
(macro-error "error in format string: too many arguments to format string")
|
||||
(list 'ref (list 'format s (car args))))
|
||||
(let [slice (String.substring s 0 (+ (inc idx) next))]
|
||||
(list 'ref
|
||||
(list 'String.append
|
||||
(list 'ref (list 'format slice (car args)))
|
||||
(fmt-internal (String.substring s (+ (inc idx) next) len)
|
||||
(cdr args))))))))))))
|
||||
(if (= (length args) 0)
|
||||
s ; no more splits found, just return string
|
||||
(macro-error
|
||||
(str "error in format string: too many arguments to format string (missing directive for '"
|
||||
(car args)
|
||||
"')")))
|
||||
(if (= len 1)
|
||||
(macro-error "error in format string: expected expression after last %")
|
||||
(if (= \% (String.char-at s (inc idx))) ; this is an escaped %
|
||||
(list 'ref
|
||||
(list 'String.append
|
||||
"%"
|
||||
(fmt-internal (String.slice s (+ idx 2) len) args)))
|
||||
(if (= 0 (length args)) ; we need to insert something, but have nothing
|
||||
(macro-error
|
||||
(str "error in format string: not enough arguments to format string (missing argument for '%"
|
||||
(String.slice s (inc idx) (inc (inc idx)))
|
||||
"')"))
|
||||
; okay, this is the meat:
|
||||
; get the next % after our escaper
|
||||
(let [next (String.index-of (String.slice s (inc idx) len) \%)]
|
||||
(if (= -1 next)
|
||||
(if (< 1 (length args))
|
||||
(macro-error
|
||||
(str "error in format string: too many arguments to format string (missing directive for '"
|
||||
(cadr args)
|
||||
"')"))
|
||||
(list 'ref (list 'format s (car args))))
|
||||
(let [slice (String.slice s 0 (+ (inc idx) next))]
|
||||
(list 'ref
|
||||
(list 'String.append
|
||||
(list 'ref (list 'format slice (car args)))
|
||||
(fmt-internal (String.slice s (+ (inc idx) next) len)
|
||||
(cdr args)))))))))))))
|
||||
|
||||
(doc fmt "formats a string. It supports all of the string interpolations defined in format of the type that should be interpolated (e.g. %d and %x on integers).")
|
||||
(defmacro fmt [s :rest args]
|
||||
|
110
core/Generics.carp
Normal file
110
core/Generics.carp
Normal file
@ -0,0 +1,110 @@
|
||||
;; The following generic functions make use of the interfaces
|
||||
|
||||
(defmodule Generics
|
||||
(defn one [] (inc (zero)))
|
||||
(defn minus-one [] (dec (zero)))
|
||||
(defn two [] (inc (one)))
|
||||
(defn three [] (inc (two)))
|
||||
(defn minus-two [] (* (two) (minus-one)))
|
||||
(defn four [] (+ (two) (two)))
|
||||
(defn five [] (+ (four) (one)))
|
||||
(defn ten [] (+ (five) (five)))
|
||||
(defn hundred [] (* (ten) (ten)))
|
||||
(defn thousand [] (* (hundred) (ten)))
|
||||
(defn hundred-thousand [] (* (hundred) (thousand)))
|
||||
(defn million [] (* (thousand) (thousand)))
|
||||
(defn minus-four [] (* (four) (minus-one)))
|
||||
(defn twice [x] (* (two) x))
|
||||
(defn halved [x] (/ x (two)))
|
||||
(defn squared [x] (* x x))
|
||||
(defn inverse [x] (/ (one) x))
|
||||
(defn half [] (halved (one)))
|
||||
(defn half-pi [] (halved pi))
|
||||
(defn tau [] (twice pi))
|
||||
(defn ninety [] (* (two) (* (* (three) (three)) (five))))
|
||||
(defn one-hundred-eighty [] (* (two) (ninety)))
|
||||
(defn small [] (inverse (hundred-thousand)))
|
||||
|
||||
(doc approx-margin "checks whether `x` and `y` are approximately equal within a `margin`.")
|
||||
(defn approx-margin [x y margin]
|
||||
(if (> x y)
|
||||
(< (- x y) margin)
|
||||
(< (- y x) margin)))
|
||||
|
||||
(doc approx "checks whether `x` and `y` are approximately equal with a margin.
|
||||
|
||||
The margin of error is 0.00001.")
|
||||
(defn approx [a b]
|
||||
(approx-margin a b (small)))
|
||||
|
||||
)
|
||||
|
||||
(with Generics
|
||||
;; These are defined in the global scope.
|
||||
|
||||
(defn <= [a b]
|
||||
(or (< a b)
|
||||
(= a b)))
|
||||
|
||||
(defn >= [a b]
|
||||
(or (> a b)
|
||||
(= a b)))
|
||||
|
||||
(defn cmp [a b]
|
||||
(if (= a b)
|
||||
0
|
||||
(if (< a b) -1 1)))
|
||||
|
||||
(defn max [a b]
|
||||
(if (> a b) a b))
|
||||
|
||||
(defn min [a b]
|
||||
(if (< a b) a b))
|
||||
|
||||
(defn zero? [x]
|
||||
(= (zero) x))
|
||||
|
||||
(defn pos? [x]
|
||||
(< (zero) x))
|
||||
|
||||
(defn neg? [x]
|
||||
(< x (zero)))
|
||||
|
||||
(defn not-neg? [x]
|
||||
(not (neg? x)))
|
||||
|
||||
(defn id [x] x)
|
||||
(defn const [x] (fn [_] x))
|
||||
|
||||
(defn null? [p]
|
||||
(Pointer.eq NULL (the (Ptr t) p)))
|
||||
|
||||
(defn not-null? [p]
|
||||
(not (null? p)))
|
||||
|
||||
(defn clamp [min, max, val]
|
||||
(if (> val max)
|
||||
max
|
||||
(if (< val min)
|
||||
min
|
||||
val)))
|
||||
|
||||
(defn clamp--1-1 [v]
|
||||
(clamp (minus-one) (one) v))
|
||||
|
||||
(defn lerp [from to amount]
|
||||
(+ from (* (- to from) amount)))
|
||||
|
||||
(defn between [x l u]
|
||||
(and (>= x l) (<= x u)))
|
||||
|
||||
(defn random-0-1 []
|
||||
(random-between (zero) (one)))
|
||||
|
||||
(defn random--1-1 []
|
||||
(random-between (minus-one) (one)))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= a b)))
|
||||
|
||||
)
|
@ -1,9 +1,9 @@
|
||||
(defmodule Geometry
|
||||
(doc degree-to-radians "converts degrees expressed as a double `n` into radians.")
|
||||
(defn degree-to-radians [n]
|
||||
(Double.* n (Double./ Double.pi 180.0)))
|
||||
(* n (/ pi (Generics.one-hundred-eighty))))
|
||||
|
||||
(doc radians-to-degree "converts radians expressed as a double `n` into degrees.")
|
||||
(defn radians-to-degree [n]
|
||||
(Double.* n (Double./ 180.0 Double.pi)))
|
||||
(* n (/ (Generics.one-hundred-eighty) pi)))
|
||||
)
|
||||
|
@ -22,9 +22,9 @@
|
||||
(defn max-of-three-until! [heap i len ord]
|
||||
(let-do [lchild-i (lchild i)
|
||||
rchild-i (rchild i)]
|
||||
(when (and (< lchild-i len) (ord (Array.nth heap lchild-i) (Array.nth heap i)))
|
||||
(when (and (< lchild-i len) (~ord (Array.unsafe-nth heap lchild-i) (Array.unsafe-nth heap i)))
|
||||
(set! i lchild-i))
|
||||
(when (and (< rchild-i len) (ord (Array.nth heap rchild-i) (Array.nth heap i)))
|
||||
(when (and (< rchild-i len) (~ord (Array.unsafe-nth heap rchild-i) (Array.unsafe-nth heap i)))
|
||||
(set! i rchild-i))
|
||||
i))
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
|
||||
(defn push-down-until! [heap i len ord]
|
||||
(while true
|
||||
(let [challenger (max-of-three-until! heap i len @ord)]
|
||||
(let [challenger (max-of-three-until! heap i len ord)]
|
||||
(if (= challenger i)
|
||||
(break)
|
||||
(do
|
||||
@ -45,10 +45,10 @@
|
||||
|
||||
(defn push-up! [heap i ord]
|
||||
(while (/= i 0)
|
||||
(let [elem (Array.nth heap i)
|
||||
(let [elem (Array.unsafe-nth heap i)
|
||||
parent-i (Heap.parent i)
|
||||
parent-elem (Array.nth heap parent-i)]
|
||||
(if (not (ord elem parent-elem))
|
||||
parent-elem (Array.unsafe-nth heap parent-i)]
|
||||
(if (not (~ord elem parent-elem))
|
||||
(break)
|
||||
(do (Array.swap! heap i parent-i)
|
||||
(set! i parent-i))))))
|
||||
@ -61,7 +61,7 @@
|
||||
(defn heapify! [arr ord]
|
||||
(let [len (Array.length arr)]
|
||||
(for [i 1 len]
|
||||
(push-up! arr i @ord))))
|
||||
(push-up! arr i ord))))
|
||||
|
||||
(doc push! "Insert a new item onto the heap.")
|
||||
(defn push! [heap item ord]
|
||||
@ -92,7 +92,7 @@
|
||||
(Heap.push-down-until! heap i len &ord))
|
||||
|
||||
(defn push-up! [heap i]
|
||||
(Heap.push-up! heap i ord))
|
||||
(Heap.push-up! heap i &ord))
|
||||
|
||||
(doc peek "Returns minimum item on min-heap.")
|
||||
(defn peek [heap]
|
||||
@ -104,7 +104,7 @@
|
||||
|
||||
(doc push! "Insert a new element onto the min-heap.")
|
||||
(defn push! [heap item]
|
||||
(Heap.push! heap item ord))
|
||||
(Heap.push! heap item &ord))
|
||||
|
||||
(doc pop! "Remove and return the first item in the min-heap.")
|
||||
(defn pop! [heap]
|
||||
@ -123,7 +123,7 @@
|
||||
(Heap.push-down-until! heap i len &ord))
|
||||
|
||||
(defn push-up! [heap i]
|
||||
(Heap.push-up! heap i ord))
|
||||
(Heap.push-up! heap i &ord))
|
||||
|
||||
(doc peek "Returns maximum first item on max-heap.")
|
||||
(defn peek [heap]
|
||||
@ -135,7 +135,7 @@
|
||||
|
||||
(doc push! "Insert a new element onto the max-heap.")
|
||||
(defn push! [heap item]
|
||||
(Heap.push! heap item ord))
|
||||
(Heap.push! heap item &ord))
|
||||
|
||||
(doc pop! "Remove and return the first item in the max-heap.")
|
||||
(defn pop! [heap]
|
||||
|
47
core/IO.carp
47
core/IO.carp
@ -3,6 +3,9 @@
|
||||
(register-type FILE)
|
||||
|
||||
(defmodule IO
|
||||
(register stdin (Ptr FILE) "stdin")
|
||||
(register stdout (Ptr FILE) "stdout")
|
||||
(register stderr (Ptr FILE) "stderr")
|
||||
(doc println "prints a string ref to stdout, appends a newline.")
|
||||
(register println (Fn [(Ref String)] ()))
|
||||
(doc print "prints a string ref to stdout, does not append a newline.")
|
||||
@ -10,7 +13,7 @@
|
||||
(doc errorln "prints a string ref to stderr, appends a newline.")
|
||||
(register errorln (Fn [(Ref String)] ()))
|
||||
(doc error "prints a string ref to stderr, does not append a newline.")
|
||||
(register print (Fn [(Ref String)] ()))
|
||||
(register error (Fn [(Ref String)] ()))
|
||||
(doc get-line "gets a line from stdin.")
|
||||
(register get-line (Fn [] String))
|
||||
(doc get-char "gets a character from stdin.")
|
||||
@ -21,8 +24,17 @@
|
||||
(register exit (Fn [Int] a))
|
||||
(register EOF Char)
|
||||
(doc EOF "the End-Of-File character as a literal.")
|
||||
(doc fopen "opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a file pointer.")
|
||||
(doc fopen "opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a file pointer. Consider using the function open-file instead.")
|
||||
(register fopen (Fn [&String &String] (Ptr FILE)))
|
||||
|
||||
(doc open-file "opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a Result type that contains an error string or a file pointer.")
|
||||
(defn open-file [filename mode]
|
||||
(let [ptr (IO.fopen filename mode)]
|
||||
(if (null? ptr)
|
||||
(do
|
||||
(Result.Error System.errno))
|
||||
(Result.Success ptr))))
|
||||
|
||||
(doc fclose "closes a file pointer.")
|
||||
(register fclose (Fn [(Ptr FILE)] ()))
|
||||
(doc fgetc "gets a character from a file pointer.")
|
||||
@ -48,15 +60,24 @@
|
||||
|
||||
(doc read->EOF "reads a file given by name until the End-Of-File character is reached.")
|
||||
(defn read->EOF [filename]
|
||||
(let [f (IO.fopen filename "rb")]
|
||||
(if (null? f)
|
||||
(Result.Error (fmt "File “%s” couldn’t be opened!" filename))
|
||||
(let [c (zero)
|
||||
r []]
|
||||
(do
|
||||
(while (do (set! c (IO.fgetc f))
|
||||
(/= c IO.EOF))
|
||||
(set! r (Array.push-back r c)))
|
||||
(IO.fclose f)
|
||||
(Result.Success (String.from-chars &r)))))))
|
||||
(let [maybe (IO.open-file filename "rb")]
|
||||
(match maybe
|
||||
(Result.Error x) (Result.Error x)
|
||||
(Result.Success f) (let [c (zero)
|
||||
r []]
|
||||
(do
|
||||
(while (do (set! c (IO.fgetc f))
|
||||
(/= c IO.EOF))
|
||||
(set! r (Array.push-back r c)))
|
||||
(IO.fclose f)
|
||||
(Result.Success (String.from-chars &r)))))))
|
||||
|
||||
(private getenv-)
|
||||
(hidden getenv-)
|
||||
(register getenv- (Fn [String] (Ptr Char)) "getenv")
|
||||
(defn getenv [s]
|
||||
(let [e (getenv- s)]
|
||||
(if (null? e)
|
||||
(Maybe.Nothing)
|
||||
(Maybe.Just (from-cstr e)))))
|
||||
)
|
||||
|
@ -10,7 +10,6 @@
|
||||
(register < (λ [Int Int] Bool))
|
||||
(register > (λ [Int Int] Bool))
|
||||
(register = (λ [Int Int] Bool))
|
||||
(register /= (λ [Int Int] Bool))
|
||||
(register neg (λ [Int] Int))
|
||||
(register mod (λ [Int Int] Int))
|
||||
(register bit-shift-left (λ [Int Int] Int))
|
||||
@ -74,9 +73,6 @@
|
||||
(defn = [a b]
|
||||
(Int.= @a @b))
|
||||
|
||||
(defn /= [a b]
|
||||
(Int./= @a @b))
|
||||
|
||||
(defn < [a b]
|
||||
(Int.< @a @b))
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
;;(definterface str (λ [a] String))
|
||||
|
||||
(definterface = (λ [a a] Bool))
|
||||
(definterface /= (λ [a a] Bool))
|
||||
|
||||
(definterface add-ref (λ [&a &a] a))
|
||||
(definterface sub-ref (λ [&a &a] a))
|
||||
@ -21,8 +20,10 @@
|
||||
(definterface < (λ [a a] Bool))
|
||||
(definterface > (λ [a a] Bool))
|
||||
|
||||
(definterface zero (λ [] a))
|
||||
(definterface inc (λ [a] a))
|
||||
(definterface dec (λ [a] a))
|
||||
(definterface neg (λ [a] a))
|
||||
|
||||
(definterface to-int (λ [a] Int))
|
||||
(definterface from-int (λ [Int] a))
|
||||
@ -30,50 +31,32 @@
|
||||
(definterface format (λ [&String a] String))
|
||||
(definterface from-string (λ [&String] a))
|
||||
|
||||
(definterface zero (λ [] a))
|
||||
(definterface random (Fn [] a))
|
||||
(definterface random-between (Fn [a a] a))
|
||||
|
||||
(definterface pi a)
|
||||
|
||||
(definterface neg (λ [a] a))
|
||||
(definterface abs (λ [a] a))
|
||||
(definterface acos (λ [a] a))
|
||||
(definterface asin (λ [a] a))
|
||||
(definterface atan (λ [a] a))
|
||||
(definterface atan2 (λ [a a] a))
|
||||
(definterface ceil (λ [a] a))
|
||||
(definterface cos (λ [a] a))
|
||||
(definterface cosh (λ [a] a))
|
||||
(definterface exp (λ [a] a))
|
||||
(definterface floor (λ [a] a))
|
||||
(definterface frexp (λ [a (Ref Int)] a))
|
||||
(definterface ldexp (λ [a Int] a))
|
||||
(definterface log (λ [a] a))
|
||||
(definterface log10 (λ [a] a))
|
||||
(definterface mod (λ [a a] a))
|
||||
(definterface modf (λ [a (Ref a)] a))
|
||||
(definterface pow (λ [a a] a))
|
||||
(definterface sin (λ [a] a))
|
||||
(definterface sinh (λ [a] a))
|
||||
(definterface sqrt (λ [a] a))
|
||||
(definterface tan (λ [a] a))
|
||||
(definterface tanh (λ [a] a))
|
||||
|
||||
|
||||
|
||||
;; The following functions make use of the interfaces
|
||||
|
||||
(defn <= [a b]
|
||||
(or (< a b)
|
||||
(= a b)))
|
||||
|
||||
(defn >= [a b]
|
||||
(or (> a b)
|
||||
(= a b)))
|
||||
|
||||
(defn cmp [a b]
|
||||
(if (= a b)
|
||||
0
|
||||
(if (< a b) -1 1)))
|
||||
|
||||
(defn max [a b]
|
||||
(if (> a b) a b))
|
||||
|
||||
(defn min [a b]
|
||||
(if (< a b) a b))
|
||||
|
||||
(defn zero? [x]
|
||||
(= (zero) x))
|
||||
|
||||
(defn pos? [x]
|
||||
(< (zero) x))
|
||||
|
||||
(defn neg? [x]
|
||||
(< x (zero)))
|
||||
|
||||
(defn id [x] x)
|
||||
|
||||
(defn null? [p]
|
||||
(Pointer.eq NULL (the (Ptr t) p)))
|
||||
|
||||
(defn not-null? [p]
|
||||
(not (null? p)))
|
||||
(definterface slice (Fn [&a Int Int] a))
|
||||
|
@ -1,6 +1,8 @@
|
||||
(system-include "carp_long.h")
|
||||
|
||||
(defmodule Long
|
||||
(register MAX Long "LONG_MAX")
|
||||
(register MIN Long "LONG_MIN")
|
||||
(register + (λ [Long Long] Long))
|
||||
(register - (λ [Long Long] Long))
|
||||
(register * (λ [Long Long] Long))
|
||||
@ -25,9 +27,6 @@
|
||||
to non-refs.")
|
||||
(register copy (λ [&Long] Long))
|
||||
|
||||
(defn /= [x y]
|
||||
(not (Long.= x y)))
|
||||
|
||||
(register safe-add (λ [Long Long (Ref Long)] Bool))
|
||||
(register safe-sub (λ [Long Long (Ref Long)] Bool))
|
||||
(register safe-mul (λ [Long Long (Ref Long)] Bool))
|
||||
@ -36,6 +35,8 @@ to non-refs.")
|
||||
|
||||
(defn even? [a] (= (mod a 2l) 0l))
|
||||
(defn odd? [a] (not (even? a)))
|
||||
|
||||
(defn zero [] 0l)
|
||||
)
|
||||
|
||||
(defmodule LongRef
|
||||
|
146
core/Macros.carp
146
core/Macros.carp
@ -29,14 +29,12 @@
|
||||
(list 'meta-set! name "todo" value))
|
||||
|
||||
(doc private? "Is this binding private?")
|
||||
(todo private? "This is buggy, will report true when meta is set to 'false'!")
|
||||
(defmacro private? [name]
|
||||
(list 'not (list '= () (list 'meta name "private"))))
|
||||
(list 'not (list 'list? (meta name "private"))))
|
||||
|
||||
(doc hidden? "Is this binding hidden?")
|
||||
(todo hidden? "This is buggy, will report true when meta is set to 'false'!")
|
||||
(defmacro hidden? [name]
|
||||
(list 'not (list '= () (list 'meta name "hidden"))))
|
||||
(list 'not (list 'list? (meta name "hidden"))))
|
||||
|
||||
(defndynamic annotate-helper [name annotation]
|
||||
(cons annotation (meta name "annotations")))
|
||||
@ -75,6 +73,25 @@
|
||||
(defndynamic cdddar [pair] (cdr (cdr (cdr (car pair)))))
|
||||
(defndynamic cddddr [pair] (cdr (cdr (cdr (cdr pair)))))
|
||||
|
||||
(defndynamic cxr [x pair]
|
||||
(if (= (length x) 0)
|
||||
(list 'quote pair)
|
||||
(list
|
||||
(if (= 'a (cadr x))
|
||||
'car
|
||||
(if (= 'd (cadr x))
|
||||
'cdr
|
||||
(macro-error "`cxr` expects either `a` or `d` symbols, got " (cadr x))))
|
||||
(if (= 1 (car x))
|
||||
(cxr (cddr x) pair)
|
||||
(cxr (cons (- (car x) 1) (cdr x)) pair)))))
|
||||
|
||||
(defndynamic nthcdr [n pair]
|
||||
(cxr (list (+ n 1) 'd) pair))
|
||||
|
||||
(defndynamic nthcar [n pair]
|
||||
(cxr (list 1 'a n 'd) pair))
|
||||
|
||||
(defndynamic eval-internal [form]
|
||||
(list 'do
|
||||
(list 'defn 'main [] (list 'IO.println* form))
|
||||
@ -87,6 +104,21 @@
|
||||
(defmacro e [form]
|
||||
(eval-internal form))
|
||||
|
||||
(defndynamic list-to-array-internal [xs acc]
|
||||
(if (= 0 (length xs))
|
||||
acc
|
||||
(list-to-array-internal (cdr xs) (append acc (array (car xs))))))
|
||||
|
||||
(defndynamic collect-into-internal [xs acc f]
|
||||
(if (= 0 (length xs))
|
||||
acc
|
||||
(collect-into-internal (cdr xs) (append acc (f (car xs))) f)))
|
||||
|
||||
(doc collect-into
|
||||
"Transforms a dynamic data literal into another, preserving order")
|
||||
(defndynamic collect-into [xs f]
|
||||
(list 'quote
|
||||
(collect-into-internal xs (f) f)))
|
||||
)
|
||||
|
||||
(defndynamic cond-internal [xs]
|
||||
@ -108,41 +140,46 @@
|
||||
(defmacro for [settings :rest body] ;; settings = variable, from, to, <step>
|
||||
(if (> (length body) 1)
|
||||
(macro-error "Warning: the body of the 'for' loop can only contain one expression")
|
||||
(list
|
||||
'let
|
||||
(array (car settings) (cadr settings))
|
||||
(list
|
||||
'while
|
||||
(list 'Int.< (car settings) (caddr settings))
|
||||
(list 'do
|
||||
(if (= (length body) 0)
|
||||
()
|
||||
(if (list? body)
|
||||
(car body)
|
||||
body))
|
||||
(list
|
||||
'set! (car settings)
|
||||
(list 'Int.+
|
||||
(car settings)
|
||||
(if (= 4 (length settings)) ;; optional arg for step
|
||||
(cadddr settings)
|
||||
1))))))))
|
||||
(let [variable (car settings)
|
||||
from (cadr settings)
|
||||
to (caddr settings)
|
||||
step (if (> (length settings) 3) (cadddr settings) 1)
|
||||
comp (if (> (length settings) 4)
|
||||
(cadddr (cdr settings))
|
||||
(if (< step (- step step)) '> '<))
|
||||
]
|
||||
(list
|
||||
'let (array variable from)
|
||||
(list
|
||||
'while (list comp variable to)
|
||||
(list
|
||||
'do
|
||||
(if (= (length body) 0)
|
||||
()
|
||||
(if (list? body)
|
||||
(car body)
|
||||
body))
|
||||
(list
|
||||
'set! variable
|
||||
(list '+ variable step))))))))
|
||||
|
||||
(defmacro refstr [x]
|
||||
(list 'ref
|
||||
(list 'str x)))
|
||||
|
||||
;; Old foreach, what's a better name for this? (it's just 'map' with side effects)
|
||||
;; (defmacro foreach [f xs]
|
||||
;; (list 'for ['i 0 (list 'Array.length (list 'ref xs))]
|
||||
;; (list f (list 'Array.nth (list 'ref xs) 'i))))
|
||||
(defmacro doall [f xs]
|
||||
(list 'for ['i 0 (list 'Array.length (list 'ref xs))]
|
||||
(list f (list 'Array.unsafe-nth (list 'ref xs) 'i))))
|
||||
|
||||
(defndynamic foreach-internal [var xs expr]
|
||||
(list 'let ['xs xs
|
||||
'len (list 'Array.length 'xs)]
|
||||
(list 'for ['i 0 'len]
|
||||
(list 'let [var (list 'Array.nth 'xs 'i)]
|
||||
expr))))
|
||||
(let [xsym (gensym-with 'xs)
|
||||
len (gensym-with 'len)
|
||||
i (gensym-with 'i)]
|
||||
(list 'let [xsym xs
|
||||
len (list 'Array.length xsym)]
|
||||
(list 'for [i 0 len]
|
||||
(list 'let [var (list 'Array.unsafe-nth xsym i)]
|
||||
expr)))))
|
||||
|
||||
(defmacro foreach [binding expr]
|
||||
(if (array? binding)
|
||||
@ -296,25 +333,18 @@
|
||||
(defmacro ignore [form]
|
||||
(list 'let (array '_ form) (list)))
|
||||
|
||||
;; Allows inclusion of C headers relative to the Carp file in which this macro is called.
|
||||
(defmacro relative-include [file]
|
||||
(list 'local-include
|
||||
(list 'Dynamic.String.join [(list 'Dynamic.String.directory (list 'file))
|
||||
"/"
|
||||
file])))
|
||||
|
||||
(defmacro save-docs [:rest modules]
|
||||
;; A trick to be able to send unquoted symbols to 'save-docs'
|
||||
(list 'save-docs-internal (list 'quote modules)))
|
||||
|
||||
(defndynamic project-config [bindings]
|
||||
(defndynamic project-config [bindings]
|
||||
(if (< (length bindings) 2)
|
||||
(list)
|
||||
(cons-last (project-config (cdr (cdr bindings))) (list 'do (list 'Project.config
|
||||
(car bindings) (car (cdr bindings)))))))
|
||||
|
||||
(doc defproject "Define a project configuration.")
|
||||
(defmacro defproject [:rest bindings]
|
||||
(defmacro defproject [:rest bindings]
|
||||
(project-config bindings))
|
||||
|
||||
(doc const-assert "asserts that the expression `expr` is true at compile time.
|
||||
@ -323,3 +353,37 @@ Otherwise it will fail with the message `msg`.
|
||||
The expression must be evaluable at compile time.")
|
||||
(defndynamic const-assert [expr msg]
|
||||
(if expr () (macro-error msg)))
|
||||
|
||||
(doc *gensym-counter* "is a helper counter for `gensym`.")
|
||||
(defdynamic *gensym-counter* 1000)
|
||||
|
||||
(doc gensym-with "generates symbols dynamically, based on a symbol name.")
|
||||
(defndynamic gensym-with [x]
|
||||
(do
|
||||
(defdynamic *gensym-counter* (inc *gensym-counter*))
|
||||
(Symbol.join [x (Symbol.from *gensym-counter*)])))
|
||||
|
||||
(doc gensym "generates symbols dynamically as needed.")
|
||||
(defndynamic gensym []
|
||||
(gensym-with 'gensym-generated))
|
||||
|
||||
(doc until "executes `body` until the condition `cnd` is true.")
|
||||
(defmacro until [cnd body]
|
||||
(list 'while (list 'not cnd)
|
||||
body))
|
||||
|
||||
(doc defdynamic-once "creates a dynamic variable and sets its value if it's not already defined.")
|
||||
(defmacro defdynamic-once [var expr]
|
||||
(list 'if (list 'defined? var)
|
||||
()
|
||||
(list 'defdynamic var expr)))
|
||||
|
||||
(defndynamic comp-internal [sym fns]
|
||||
(if (= (length fns) 0)
|
||||
sym
|
||||
(list (car fns) (comp-internal sym (cdr fns)))))
|
||||
|
||||
(doc comp "composes the functions `fns` into one `fn`.")
|
||||
(defmacro comp [:rest fns]
|
||||
(let [x (gensym)]
|
||||
(list 'fn [x] (comp-internal x fns))))
|
||||
|
144
core/Map.carp
144
core/Map.carp
@ -29,12 +29,48 @@
|
||||
(defn hash [k] (to-int (the Char @k)))
|
||||
)
|
||||
|
||||
(defmodule Byte
|
||||
(defn hash [k] (to-int (the Byte @k)))
|
||||
)
|
||||
|
||||
(defmodule Float
|
||||
(defn hash [k] (to-bytes @k))
|
||||
(defn hash [k] (Float.to-bytes @k))
|
||||
)
|
||||
|
||||
(defmodule Double
|
||||
(defn hash [k] (Long.to-int (to-bytes @k)))
|
||||
(defn hash [k] (Long.to-int (Double.to-bytes @k)))
|
||||
)
|
||||
|
||||
(defmodule Int8
|
||||
(defn hash [k] (Long.to-int (Int8.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Int16
|
||||
(defn hash [k] (Long.to-int (Int16.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Int32
|
||||
(defn hash [k] (Long.to-int (Int32.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Int64
|
||||
(defn hash [k] (Long.to-int (Int64.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Uint8
|
||||
(defn hash [k] (Long.to-int (Uint8.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Uint16
|
||||
(defn hash [k] (Long.to-int (Uint16.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Uint32
|
||||
(defn hash [k] (Long.to-int (Uint32.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Uint64
|
||||
(defn hash [k] (Long.to-int (Uint64.to-long @k)))
|
||||
)
|
||||
|
||||
(defmodule Pair
|
||||
@ -56,23 +92,29 @@
|
||||
l (Array.length (Bucket.entries b))
|
||||
es (entries b)]
|
||||
(for [i 0 l]
|
||||
(when (= (Pair.a (Array.nth es i)) k)
|
||||
(when (= (Pair.a (Array.unsafe-nth es i)) k)
|
||||
(do
|
||||
(set! ret i)
|
||||
(break))))
|
||||
ret))
|
||||
|
||||
(defn get-idx [b i]
|
||||
@(Pair.b (Array.nth (entries b) i)))
|
||||
@(Pair.b (Array.unsafe-nth (entries b) i)))
|
||||
|
||||
(defn set-idx [b i val]
|
||||
(do (Array.aupdate! (entries &b) i &(fn [p] (Pair.set-b @p @val)))
|
||||
b))
|
||||
|
||||
(defn set-idx! [b i val]
|
||||
(Array.aupdate! (entries b) i &(fn [p] (Pair.set-b @p @val))))
|
||||
|
||||
(defn push-back [b k v]
|
||||
(do (Array.push-back! (entries &b) (Pair.init-from-refs k v))
|
||||
b))
|
||||
|
||||
(defn push-back! [b k v]
|
||||
(Array.push-back! (entries b) (Pair.init-from-refs k v)))
|
||||
|
||||
(defn get [b k default-value]
|
||||
(let [i (find b k)]
|
||||
(if (<= 0 i)
|
||||
@ -83,7 +125,7 @@
|
||||
(let [i (find b k)]
|
||||
(if (<= 0 i)
|
||||
;; The call to copy ('@') here is annoying - had to add it since sumtypes can't contain refs for now:
|
||||
(Maybe.Just @(Pair.b (Array.nth (entries b) i)))
|
||||
(Maybe.Just @(Pair.b (Array.unsafe-nth (entries b) i)))
|
||||
(Maybe.Nothing))))
|
||||
|
||||
(defn put [b k v]
|
||||
@ -92,13 +134,19 @@
|
||||
(set-idx b i v)
|
||||
(push-back b k v))))
|
||||
|
||||
(defn put! [b k v]
|
||||
(let [i (find b k)]
|
||||
(if (<= 0 i)
|
||||
(set-idx! b i v)
|
||||
(push-back! b k v))))
|
||||
|
||||
(defn contains? [b k]
|
||||
(<= 0 (find b k)))
|
||||
|
||||
(defn remove [entries k]
|
||||
(let-do [nentries (the (Array (Pair a b)) [])]
|
||||
(for [i 0 (Array.length entries)]
|
||||
(let [e (Array.nth entries i)]
|
||||
(let [e (Array.unsafe-nth entries i)]
|
||||
(unless (= (Pair.a e) k)
|
||||
(set! nentries (Array.push-back nentries @e)))))
|
||||
nentries))
|
||||
@ -128,20 +176,20 @@
|
||||
(defn put [m k v]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &m))]
|
||||
(update-buckets m &(fn [b]
|
||||
(let [n (Array.nth &b idx)]
|
||||
(Array.aset b idx (Bucket.put @n k v)))))))
|
||||
(let [n (Array.unsafe-nth &b idx)]
|
||||
(Array.aset b idx (Bucket.put @n k v)))))))
|
||||
|
||||
(doc put! "Put a a value v into map m, using the key k, in place.")
|
||||
(defn put! [m k v]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets m))
|
||||
b (buckets m)
|
||||
n (Array.nth b idx)]
|
||||
(Array.aset! b idx (Bucket.put @n k v))))
|
||||
n (Array.unsafe-nth b idx)]
|
||||
(Bucket.put! n k v)))
|
||||
|
||||
(doc get-with-default "Get the value for the key k from map m. If it isn’t found, the default is returned.")
|
||||
(defn get-with-default [m k default-value]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets m))]
|
||||
(Bucket.get (Array.nth (buckets m) idx) k default-value)))
|
||||
(Bucket.get (Array.unsafe-nth (buckets m) idx) k default-value)))
|
||||
|
||||
(doc get "Get the value for the key k from map m. If it isn’t found, a zero element for the value type is returned.")
|
||||
(defn get [m k]
|
||||
@ -150,13 +198,13 @@
|
||||
(doc get-maybe "Get the value for the key k from map m. It returns a Maybe type, meaning that if nothing is found, Nothing is returned.")
|
||||
(defn get-maybe [m k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets m))]
|
||||
(Bucket.get-maybe (Array.nth (buckets m) idx) k)))
|
||||
(Bucket.get-maybe (Array.unsafe-nth (buckets m) idx) k)))
|
||||
|
||||
(doc update "Update value at key k in map with function f, if it exists.")
|
||||
(defn update [m k f]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &m))]
|
||||
(update-buckets m &(fn [b]
|
||||
(let [n (Array.nth &b idx)
|
||||
(let [n (Array.unsafe-nth &b idx)
|
||||
i (Bucket.find n k)]
|
||||
(if (<= 0 i)
|
||||
;; currently can't write a Bucket.update that takes f due to bug #347
|
||||
@ -167,7 +215,7 @@
|
||||
(defn update-with-default [m k f v]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &m))]
|
||||
(update-buckets m &(fn [b]
|
||||
(let [n (Array.nth &b idx)
|
||||
(let [n (Array.unsafe-nth &b idx)
|
||||
i (Bucket.find n k)]
|
||||
(if (<= 0 i)
|
||||
(Array.aset b idx (Bucket.set-idx @n i &(~f (Bucket.get-idx n i))))
|
||||
@ -177,7 +225,7 @@
|
||||
(defn length [m]
|
||||
(let-do [c 0]
|
||||
(for [i 0 @(n-buckets m)]
|
||||
(set! c (+ c (Array.length (Bucket.entries (Array.nth (buckets m) i))))))
|
||||
(set! c (+ c (Array.length (Bucket.entries (Array.unsafe-nth (buckets m) i))))))
|
||||
c))
|
||||
|
||||
(doc empty? "Check whether the map m is empty.")
|
||||
@ -187,24 +235,24 @@
|
||||
(doc contains? "Check whether the map m contains the key k.")
|
||||
(defn contains? [m k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets m))]
|
||||
(Bucket.contains? (Array.nth (buckets m) idx) k)))
|
||||
(Bucket.contains? (Array.unsafe-nth (buckets m) idx) k)))
|
||||
|
||||
(doc remove "Remove the value under the key k from the map m.")
|
||||
(defn remove [m k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &m))]
|
||||
(update-buckets m &(fn [b]
|
||||
(let [n (Array.nth &b idx)]
|
||||
(Array.aset b idx (Bucket.shrink @n k)))))))
|
||||
(let [n (Array.unsafe-nth &b idx)]
|
||||
(Array.aset b idx (Bucket.shrink @n k)))))))
|
||||
|
||||
(doc all? "Do all key-value pairs pass the given predicate (of two arguments)?")
|
||||
(defn all? [pred m]
|
||||
(let-do [ret true]
|
||||
(for [i 0 @(n-buckets m)]
|
||||
(let [bucket (Array.nth (buckets m) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets m) i)
|
||||
len (Array.length (Bucket.entries bucket))
|
||||
entries (Bucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(unless (~pred (Pair.a e) (Pair.b e))
|
||||
(set! ret false))))))
|
||||
ret))
|
||||
@ -217,22 +265,22 @@
|
||||
(doc for-each "Execute the binary function f for all keys and values in the map m.")
|
||||
(defn for-each [m f]
|
||||
(for [i 0 @(n-buckets m)]
|
||||
(let [bucket (Array.nth (buckets m) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets m) i)
|
||||
len (Array.length (Bucket.entries bucket))
|
||||
entries (Bucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(~f (Pair.a e) (Pair.b e)))))))
|
||||
|
||||
(doc endo-map "Transform values of the given map in place. f gets two arguments, key and value, and should return new value")
|
||||
(defn endo-map [f m]
|
||||
(do
|
||||
(for [i 0 @(n-buckets &m)]
|
||||
(let [bucket (Array.nth (buckets &m) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets &m) i)
|
||||
len (Array.length (Bucket.entries bucket))
|
||||
entries (Bucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(Array.aset! entries j (Pair.init @(Pair.a e)
|
||||
(~f (Pair.a e) (Pair.b e))))))))
|
||||
m))
|
||||
@ -241,11 +289,11 @@
|
||||
(defn kv-reduce [f init m]
|
||||
(do
|
||||
(for [i 0 @(n-buckets m)]
|
||||
(let [bucket (Array.nth (buckets m) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets m) i)
|
||||
len (Array.length (Bucket.entries bucket))
|
||||
entries (Bucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(set! init (~f init (Pair.a e) (Pair.b e)))))))
|
||||
init))
|
||||
|
||||
@ -265,7 +313,7 @@
|
||||
(defn from-array [a]
|
||||
(let-do [m (create)]
|
||||
(for [i 0 (Array.length a)]
|
||||
(let [e (Array.nth a i)
|
||||
(let [e (Array.unsafe-nth a i)
|
||||
k (Pair.a e)
|
||||
v (Pair.b e)]
|
||||
(set! m (put m k v))))
|
||||
@ -279,7 +327,7 @@
|
||||
|
||||
(defn str [m]
|
||||
(let [res (kv-reduce &(fn [s k v]
|
||||
(String.join @"" &[s @" " (prn @k) @" " (prn @v)]))
|
||||
(String.join "" &[s @" " (prn @k) @" " (prn @v)]))
|
||||
@"{"
|
||||
m)]
|
||||
(String.append &res " }")))
|
||||
@ -303,7 +351,7 @@
|
||||
es (entries b)
|
||||
l (Array.length es)]
|
||||
(for [i 0 l]
|
||||
(when (= (Array.nth es i) k)
|
||||
(when (= (Array.unsafe-nth es i) k)
|
||||
(do
|
||||
(set! e true)
|
||||
(break))))
|
||||
@ -312,11 +360,14 @@
|
||||
(defn remove [entries k]
|
||||
(let-do [nentries []]
|
||||
(for [i 0 (Array.length entries)]
|
||||
(let [e (Array.nth entries i)]
|
||||
(let [e (Array.unsafe-nth entries i)]
|
||||
(unless (= e k)
|
||||
(set! nentries (Array.push-back nentries @e)))))
|
||||
nentries))
|
||||
|
||||
(defn push-back! [b k]
|
||||
(Array.push-back! (entries b) k))
|
||||
|
||||
(defn shrink [b k]
|
||||
(if (contains? b k)
|
||||
(set-entries @b (remove (entries b) k))
|
||||
@ -339,26 +390,29 @@
|
||||
|
||||
(doc put "Put a a key k into the set s.")
|
||||
(defn put [s k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &s))]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &s))
|
||||
;; The lifetime system really doesn't like this function, had to put in a bunch of copying to make it compile:
|
||||
]
|
||||
(update-buckets s &(fn [b]
|
||||
(let [n (Array.nth &b idx)]
|
||||
(let [n (Array.unsafe-nth &b idx)]
|
||||
(if (SetBucket.contains? n k)
|
||||
b
|
||||
(Array.aset b idx (SetBucket.grow n @k))))))))
|
||||
(let [new-k @k] ;; HACK!
|
||||
(Array.aset b idx (SetBucket.grow n new-k)))))))))
|
||||
|
||||
(doc put! "Put a a key k into the set s, in place.")
|
||||
(defn put! [s k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets s))
|
||||
b (buckets s)
|
||||
n (Array.nth b idx)]
|
||||
n (Array.unsafe-nth b idx)]
|
||||
(when (not (SetBucket.contains? n k))
|
||||
(Array.aset! b idx (SetBucket.grow n @k)))))
|
||||
(SetBucket.push-back! n @k))))
|
||||
|
||||
(doc length "Get the length of set s.")
|
||||
(defn length [s]
|
||||
(let-do [c 0]
|
||||
(for [i 0 @(n-buckets s)]
|
||||
(set! c (+ c (Array.length (SetBucket.entries (Array.nth (buckets s) i))))))
|
||||
(set! c (+ c (Array.length (SetBucket.entries (Array.unsafe-nth (buckets s) i))))))
|
||||
c))
|
||||
|
||||
(doc empty? "Check whether the set s is empty.")
|
||||
@ -368,14 +422,14 @@
|
||||
(doc contains? "Check whether the set s contains the key k.")
|
||||
(defn contains? [s k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets s))]
|
||||
(SetBucket.contains? (Array.nth (buckets s) idx) k)))
|
||||
(SetBucket.contains? (Array.unsafe-nth (buckets s) idx) k)))
|
||||
|
||||
(doc remove "Remove the key k from the set s.")
|
||||
(defn remove [s k]
|
||||
(let [idx (Int.positive-mod (hash k) @(n-buckets &s))]
|
||||
(update-buckets s &(fn [b]
|
||||
(let [n (Array.nth &b idx)]
|
||||
(Array.aset b idx (SetBucket.shrink n k)))))))
|
||||
(let [n (Array.unsafe-nth &b idx)]
|
||||
(Array.aset b idx (SetBucket.shrink n k)))))))
|
||||
|
||||
(doc all? "Does the predicate hold for all values in this set?")
|
||||
(defn all? [pred set]
|
||||
@ -399,18 +453,18 @@
|
||||
(doc for-each "Execute the unary function f for each element in the set s.")
|
||||
(defn for-each [s f]
|
||||
(for [i 0 @(n-buckets s)]
|
||||
(let [bucket (Array.nth (buckets s) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets s) i)
|
||||
len (Array.length (SetBucket.entries bucket))
|
||||
entries (SetBucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(~f e))))))
|
||||
|
||||
(doc from-array "Create a set from the values in array a.")
|
||||
(defn from-array [a]
|
||||
(let-do [s (create)]
|
||||
(for [i 0 (Array.length a)]
|
||||
(let [e (Array.nth a i)]
|
||||
(let [e (Array.unsafe-nth a i)]
|
||||
(set! s (put s e))))
|
||||
s))
|
||||
|
||||
@ -418,11 +472,11 @@
|
||||
(defn reduce [f init s]
|
||||
(do
|
||||
(for [i 0 @(n-buckets s)]
|
||||
(let [bucket (Array.nth (buckets s) i)
|
||||
(let [bucket (Array.unsafe-nth (buckets s) i)
|
||||
len (Array.length (SetBucket.entries bucket))
|
||||
entries (SetBucket.entries bucket)]
|
||||
(for [j 0 len]
|
||||
(let [e (Array.nth entries j)]
|
||||
(let [e (Array.unsafe-nth entries j)]
|
||||
(set! init (~f init e))))))
|
||||
init))
|
||||
|
||||
@ -449,7 +503,7 @@
|
||||
(reduce &(fn [arr elt] (Array.push-back arr @elt)) [] s))
|
||||
|
||||
(defn str [set]
|
||||
(let [res (reduce &(fn [s e] (String.join @"" &[s @" " (prn e)]))
|
||||
(let [res (reduce &(fn [s e] (String.join "" &[s @" " (prn e)]))
|
||||
@"{"
|
||||
set)]
|
||||
(String.append &res " }")))
|
||||
|
@ -7,7 +7,7 @@
|
||||
(defn apply [a f]
|
||||
(match a
|
||||
(Nothing) (Nothing)
|
||||
(Just x) (Just (f x))))
|
||||
(Just x) (Just (~f x))))
|
||||
|
||||
(doc unsafe-from "is an unsafe unwrapper that will get the value from a `Just`. If `a` is `Nothing`, a runtime error will be generated.")
|
||||
(defn unsafe-from [a]
|
||||
@ -52,9 +52,9 @@ It is the inverse of [`just?`](#just?).")
|
||||
(Nothing) false
|
||||
(Just y) (= x y))))
|
||||
|
||||
(doc ptr "Creates a `(Ptr a)` from a `(Maybe a)`. If the `Maybe` was
|
||||
(doc unsafe-ptr "Creates a `(Ptr a)` from a `(Maybe a)`. If the `Maybe` was
|
||||
`Nothing`, this function will return a `NULL` value.")
|
||||
(defn ptr [a]
|
||||
(defn unsafe-ptr [a]
|
||||
(the (Ptr a) (Unsafe.coerce
|
||||
(match @a
|
||||
(Nothing) NULL
|
||||
|
@ -39,6 +39,30 @@ If you want to replace all occurrences of the pattern, use `-1`.")
|
||||
(doc from-chars "creates a pattern that matches a group of characters from a list of those characters.")
|
||||
(defn from-chars [chars]
|
||||
(Pattern.init &(str* @"[" (String.from-chars chars) @"]")))
|
||||
|
||||
(defn global-match-str [p s]
|
||||
(Array.copy-map &Array.unsafe-first &(global-match p s)))
|
||||
|
||||
(doc split "splits a string by a pattern.")
|
||||
(defn split [p s]
|
||||
(let-do [idx (find-all p s)
|
||||
strs (global-match-str p s)
|
||||
lidx (Array.length &idx)
|
||||
result (Array.allocate (Int.inc lidx))]
|
||||
(Array.aset-uninitialized! &result 0
|
||||
(slice s 0 (if (> lidx 0) @(Array.unsafe-nth &idx 0) (length s))))
|
||||
(for [i 0 (Int.dec (Array.length &idx))]
|
||||
(let [plen (length (Array.unsafe-nth &strs i))]
|
||||
(Array.aset-uninitialized! &result (Int.inc i)
|
||||
(slice s (+ @(Array.unsafe-nth &idx i) plen)
|
||||
@(Array.unsafe-nth &idx (Int.inc i))))))
|
||||
(when (> lidx 0)
|
||||
(let [plen (length (Array.unsafe-nth &strs (Int.dec lidx)))]
|
||||
(Array.aset-uninitialized! &result lidx
|
||||
(suffix s (+ @(Array.unsafe-nth &idx (Int.dec lidx))
|
||||
plen)))))
|
||||
result))
|
||||
|
||||
)
|
||||
|
||||
(defmodule String
|
||||
@ -84,7 +108,7 @@ If you want to replace all occurrences of the pattern, use `-1`.")
|
||||
|
||||
(doc chomp "trims a newline from the end of a string.")
|
||||
(defn chomp [s]
|
||||
(Pattern.substitute #"\n$" s "" 1))
|
||||
(Pattern.substitute #"\r$" &(Pattern.substitute #"\n$" s "" 1) "" 1))
|
||||
|
||||
(doc collapse-whitespace "collapses groups of whitespace into single spaces.")
|
||||
(defn collapse-whitespace [s]
|
||||
@ -97,13 +121,13 @@ If you want to replace all occurrences of the pattern, use `-1`.")
|
||||
lidx (Array.length &idx)
|
||||
result (Array.allocate (Int.inc lidx))]
|
||||
(Array.aset-uninitialized! &result 0
|
||||
(substring s 0 (if (> lidx 0) @(Array.nth &idx 0) (length s))))
|
||||
(slice s 0 (if (> lidx 0) @(Array.unsafe-nth &idx 0) (length s))))
|
||||
(for [i 0 (Int.dec (Array.length &idx))]
|
||||
(Array.aset-uninitialized! &result (Int.inc i)
|
||||
(substring s (Int.inc @(Array.nth &idx i)) @(Array.nth &idx (Int.inc i)))))
|
||||
(slice s (Int.inc @(Array.unsafe-nth &idx i)) @(Array.unsafe-nth &idx (Int.inc i)))))
|
||||
(when (> lidx 0)
|
||||
(Array.aset-uninitialized! &result lidx
|
||||
(suffix-string s (Int.inc @(Array.nth &idx (Int.dec lidx))))))
|
||||
(suffix s (Int.inc @(Array.unsafe-nth &idx (Int.dec lidx))))))
|
||||
result))
|
||||
|
||||
(doc words "splits a string into words.")
|
||||
|
4
core/Pointer.carp
Normal file
4
core/Pointer.carp
Normal file
@ -0,0 +1,4 @@
|
||||
(defmodule Pointer
|
||||
(defn inc [a] (Pointer.add a 1l))
|
||||
(defn dec [a] (Pointer.sub a 1l))
|
||||
)
|
@ -76,3 +76,12 @@
|
||||
(defn random-sized [n]
|
||||
(from-chars &(Array.repeat n &Char.random)))
|
||||
)
|
||||
|
||||
(defmodule Byte
|
||||
(defn random-between [lower upper]
|
||||
(Byte.from-int (Int.random-between (Byte.to-int lower) (Byte.to-int upper))))
|
||||
|
||||
(defn random []
|
||||
(Byte.from-int (Int.random)))
|
||||
)
|
||||
|
||||
|
@ -6,21 +6,27 @@
|
||||
(doc apply "takes a `Result` `a` and applies functions to them, one in the case that it is an `Error`, one in the case that it is a `Success`.")
|
||||
(defn apply [a success-f error-f]
|
||||
(match a
|
||||
(Success x) (Success (success-f x))
|
||||
(Error x) (Error (error-f x))))
|
||||
(Success x) (Success (~success-f x))
|
||||
(Error x) (Error (~error-f x))))
|
||||
|
||||
(doc map "takes a `Result` and applies a function `f` to it if it is a `Success` type, and wraps it back up. In the case that it is an `Error`, it is returned as is.")
|
||||
(defn map [a f]
|
||||
(match a
|
||||
(Success x) (Success (f x))
|
||||
(Success x) (Success (~f x))
|
||||
(Error x) (Error x)))
|
||||
|
||||
(doc map-error "takes a `Result` and applies a function `f` to it if it is an `Error` type, and wraps it back up. In the case that it is a `Success`, it is returned as is.")
|
||||
(defn map-error [a f]
|
||||
(match a
|
||||
(Success x) (Success x)
|
||||
(Error x) (Error (~f x))))
|
||||
|
||||
(doc and-then "takes a `Result` and applies a function `f` to it if it is a `Success` type. In the case that it is an `Error`, it is returned as is.
|
||||
|
||||
It is thus quite similar to [`map`](#map), but it will unwrap the value.")
|
||||
(defn and-then [a f]
|
||||
(match a
|
||||
(Success x) (f x)
|
||||
(Success x) (~f x)
|
||||
(Error x) (Error x)))
|
||||
|
||||
(doc unwrap-or-zero "takes a `Result` and either unwraps it if it is a `Success`, or calls `zero`. `zero` must be defined on the `Success` type.")
|
||||
@ -35,13 +41,13 @@ It is the inverse of [`and-then`](#and-then).")
|
||||
(defn or-else [a f]
|
||||
(match a
|
||||
(Success x) (Success x)
|
||||
(Error x) (f x)))
|
||||
(Error x) (~f x)))
|
||||
|
||||
(doc unwrap-or-else "takes a `Result` and either unwraps it if it is a `Success`, or calls a function `f` on the value contained in the `Error`.")
|
||||
(defn unwrap-or-else [a f]
|
||||
(match a
|
||||
(Success x) x
|
||||
(Error x) (f x)))
|
||||
(Error x) (~f x)))
|
||||
|
||||
(doc unsafe-from-success "is an unsafe unwrapper that will get the value from a `Success`. If `a` is an `Error`, a runtime error will be generated.")
|
||||
(defn unsafe-from-success [a]
|
||||
|
@ -1,21 +1,20 @@
|
||||
(system-include "math.h")
|
||||
|
||||
(local-include "../core/SDLHelper.h")
|
||||
(relative-include "SDLHelper.h")
|
||||
|
||||
(not-on-windows
|
||||
(add-pkg "sdl2"))
|
||||
|
||||
(defmodule SDL
|
||||
(defmodule Windows
|
||||
(defdynamic header-path "C:\\SDL2-2.0.9\\include")
|
||||
(defdynamic library-path "C:\\SDL2-2.0.9\\lib\\x86\\")))
|
||||
;; Only define these if they're not already defined (allows the user to pre-define them before including SDL.carp)
|
||||
(defdynamic-once sdl-windows-header-path "C:\\SDL2-2.0.9\\include")
|
||||
(defdynamic-once sdl-windows-library-path "C:\\SDL2-2.0.9\\lib\\x86\\")
|
||||
|
||||
(windows-only
|
||||
;; Note - you'll still need the SDL2.dll to be able to run the executable
|
||||
(add-cflag "-DSDL_MAIN_HANDLED")
|
||||
(add-cflag "-Wno-pragma-pack")
|
||||
(add-cflag (str "-I" SDL.Windows.header-path))
|
||||
(add-lib (str "/link " SDL.Windows.library-path "SDL2.lib " SDL.Windows.library-path "SDL2main.lib")))
|
||||
(add-cflag (str "-I" sdl-windows-header-path))
|
||||
(add-lib (str "/link " sdl-windows-library-path "SDL2.lib "))) ;; sdl-windows-library-path "SDL2main.lib")))
|
||||
|
||||
;; Types
|
||||
(register-type SDL_Keycode)
|
||||
@ -121,8 +120,6 @@
|
||||
(register str (Fn [SDL_Keycode] String))
|
||||
(defn prn [x]
|
||||
(SDL.Keycode.str x))
|
||||
(defn /= [x y]
|
||||
(not (SDL.Keycode.= x y)))
|
||||
|
||||
(register return SDL_Keycode "SDLK_RETURN")
|
||||
(register space SDL_Keycode "SDLK_SPACE")
|
||||
@ -251,6 +248,7 @@
|
||||
fps Int])
|
||||
|
||||
(defmodule SDLApp
|
||||
(doc create "creates an SDLApp instance that can then be used by `run-with-callbacks`.")
|
||||
(defn create [title width height]
|
||||
(let [win NULL
|
||||
ren NULL]
|
||||
@ -260,6 +258,13 @@
|
||||
(SDL.set-window-title win (cstr title))
|
||||
(SDLApp.init win ren 60))))
|
||||
|
||||
(hidden reduce-events)
|
||||
(defn reduce-events [app f state-to-reduce-over]
|
||||
(Array.reduce &(fn [s e] (~f app s e)) ;; Note, this will malloc an environment that captures the 'app' variable.
|
||||
state-to-reduce-over
|
||||
&(SDL.Event.all)))
|
||||
|
||||
(doc run-with-callbacks "starts the SDLApp and uses three callbacks to handle events, update state and render graphics.")
|
||||
(defn run-with-callbacks [app event-fn update-fn draw-fn initial-state]
|
||||
(let-do [rend @(SDLApp.renderer app)
|
||||
state initial-state
|
||||
@ -267,7 +272,7 @@
|
||||
target-dt (/ 1000 @(SDLApp.fps app))]
|
||||
(while true
|
||||
(do
|
||||
(event-fn app)
|
||||
(set! state (reduce-events app &event-fn state))
|
||||
(set! state (update-fn state))
|
||||
(let-do [dt (- (SDL.get-ticks) last-t)
|
||||
time-left (- target-dt dt)]
|
||||
@ -278,21 +283,23 @@
|
||||
(draw-fn app rend &state)
|
||||
(SDL.render-present rend)))))
|
||||
|
||||
(doc stop "stops the app. This function return 'a' to enable it to be called from anywhere.")
|
||||
(defn stop [app]
|
||||
(do (SDL.destroy-window @(window app))
|
||||
(SDL.quit)
|
||||
(System.exit 0)))
|
||||
|
||||
(doc default-draw "is a default rendering function that can be passed to `run-with-callbacks`.")
|
||||
(defn default-draw [app rend state-ref]
|
||||
(do (SDL.set-render-draw-color rend 0 0 0 255)
|
||||
(SDL.render-clear rend)))
|
||||
|
||||
(defn quit-on-esc [app]
|
||||
(foreach [event &(SDL.Event.all)]
|
||||
(case (SDL.Event.type event)
|
||||
SDL.Event.quit (SDLApp.stop app)
|
||||
SDL.Event.key-down (let [key (SDL.Event.keycode event)]
|
||||
(if (= key SDL.Keycode.escape)
|
||||
(SDLApp.stop app)
|
||||
()))
|
||||
()))))
|
||||
(doc quit-on-esc "is a default event handling function that can be passed to `run-with-callbacks`. Allows the application to quit if the player presses the escape key.")
|
||||
(defn quit-on-esc [app state event]
|
||||
(case (SDL.Event.type event)
|
||||
SDL.Event.quit (SDLApp.stop app)
|
||||
SDL.Event.key-down (let [key (SDL.Event.keycode event)]
|
||||
(if (= key SDL.Keycode.escape)
|
||||
(SDLApp.stop app)
|
||||
state))
|
||||
state)))
|
||||
|
@ -1,8 +1,5 @@
|
||||
#include <SDL.h>
|
||||
|
||||
#include <carp_memory.h>
|
||||
#include <core.h>
|
||||
|
||||
// Event
|
||||
SDL_Event SDL_Event_init() {
|
||||
SDL_Event e;
|
||||
@ -28,7 +25,7 @@ SDL_Event SDL_Event_copy(SDL_Event *e) {
|
||||
|
||||
// Keycode
|
||||
|
||||
SDL_Keycode SDL_Keycode_copy(SDL_Keycode* a) {
|
||||
SDL_Keycode SDL_Keycode_copy(SDL_Keycode *a) {
|
||||
return *a;
|
||||
}
|
||||
|
||||
@ -89,10 +86,10 @@ int SDL_Color_a(SDL_Color *col) {
|
||||
return (int)(col->a);
|
||||
}
|
||||
|
||||
void* SDL_SurfacePixels(SDL_Surface* s) {
|
||||
return s->pixels;
|
||||
void *SDL_SurfacePixels(SDL_Surface *s) {
|
||||
return s->pixels;
|
||||
}
|
||||
|
||||
int SDL_SurfacePitch(SDL_Surface* s) {
|
||||
return s->pitch;
|
||||
int SDL_SurfacePitch(SDL_Surface *s) {
|
||||
return s->pitch;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
(let [sum 0.0]
|
||||
(do
|
||||
(for [i 0 (Array.length a)]
|
||||
(let [tmp (Double.- (Double.copy (Array.nth a i)) mean)]
|
||||
(let [tmp (Double.- (Double.copy (Array.unsafe-nth a i)) mean)]
|
||||
(set! sum (Double.* tmp tmp))))
|
||||
sum)))
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
(let [sum 0.0]
|
||||
(do
|
||||
(for [i 0 (Array.length a)]
|
||||
(set! sum (Double.- (Double.copy (Array.nth a i)) mean)))
|
||||
(set! sum (Double.- (Double.copy (Array.unsafe-nth a i)) mean)))
|
||||
sum)))
|
||||
|
||||
(hidden _ss)
|
||||
@ -52,10 +52,10 @@
|
||||
(let [n (Array.length data)
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= (mod n 2) 1) @(Array.nth data (/ n 2))
|
||||
(= (mod n 2) 1) @(Array.unsafe-nth data (/ n 2))
|
||||
(let [mid (/ n 2)] ; else
|
||||
(/ (+ (the Double @(Array.nth data (dec mid)))
|
||||
@(Array.nth data mid))
|
||||
(/ (+ (the Double @(Array.unsafe-nth data (dec mid)))
|
||||
@(Array.unsafe-nth data mid))
|
||||
2.0)))))
|
||||
|
||||
(doc low-median "Compute the low median of the samples data.")
|
||||
@ -63,8 +63,8 @@
|
||||
(let [n (Array.length data)
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= (mod n 2) 1) @(Array.nth data (/ n 2))
|
||||
@(Array.nth data (dec (/ n 2)))))) ; else
|
||||
(= (mod n 2) 1) @(Array.unsafe-nth data (/ n 2))
|
||||
@(Array.unsafe-nth data (dec (/ n 2)))))) ; else
|
||||
|
||||
(doc high-median "Compute the high median of the samples data.")
|
||||
(defn high-median [data]
|
||||
@ -72,15 +72,15 @@
|
||||
sorted (Array.sorted data)]
|
||||
(if (= n 0)
|
||||
0.0
|
||||
@(Array.nth data (/ n 2)))))
|
||||
@(Array.unsafe-nth data (/ n 2)))))
|
||||
|
||||
(doc grouped-median "Compute the grouped median of the samples data.")
|
||||
(defn grouped-median [data interval]
|
||||
(let [n (Array.length data)
|
||||
sorted (Array.sorted data)]
|
||||
(cond (= n 0) 0.0
|
||||
(= n 1) @(Array.nth data 0)
|
||||
(let [x @(Array.nth data (/ n 2)) ; else
|
||||
(= n 1) @(Array.unsafe-nth data 0)
|
||||
(let [x @(Array.unsafe-nth data (/ n 2)) ; else
|
||||
l (- x (/ (from-int interval) 2.0))
|
||||
cf (Maybe.from (Array.index-of data &x) -1)
|
||||
f (Array.element-count data &x)]
|
||||
@ -119,7 +119,7 @@
|
||||
n 1.4826] ; taken from Rust and R, because that’s how it’s done apparently
|
||||
(do
|
||||
(for [i 0 (Array.length data)]
|
||||
(Array.aset! &abs-devs i (abs (- med @(Array.nth data i)))))
|
||||
(Array.aset! &abs-devs i (abs (- med @(Array.unsafe-nth data i)))))
|
||||
(* (median &abs-devs) n))))
|
||||
|
||||
(hidden median-abs-dev-pct)
|
||||
@ -132,15 +132,15 @@
|
||||
(Int.= 0 (Array.length sorted)) -1.0 ; should abort here
|
||||
(Double.< pct 0.0) -1.0 ; should abort here
|
||||
(Double.> pct 100.0) -1.0 ; should abort here
|
||||
(Int.= 1 (Array.length sorted)) @(Array.nth sorted 0)
|
||||
(Double.= 100.0 pct) @(Array.nth sorted (Int.dec (Array.length sorted)))
|
||||
(Int.= 1 (Array.length sorted)) @(Array.unsafe-nth sorted 0)
|
||||
(Double.= 100.0 pct) @(Array.unsafe-nth sorted (Int.dec (Array.length sorted)))
|
||||
(let [len (Int.dec (Array.length sorted))
|
||||
rank (Double.* (Double./ pct 100.0) (Double.from-int len))
|
||||
lrank (Double.floor rank)
|
||||
d (Double.- rank lrank)
|
||||
n (Double.to-int lrank)
|
||||
lo @(Array.nth sorted n)
|
||||
hi @(Array.nth sorted (Int.inc n))]
|
||||
lo @(Array.unsafe-nth sorted n)
|
||||
hi @(Array.unsafe-nth sorted (Int.inc n))]
|
||||
(Double.+ lo (Double.* d (Double.- hi lo))))))
|
||||
|
||||
(doc quartiles "Compute the quartiles of the samples data.")
|
||||
@ -157,7 +157,7 @@
|
||||
(doc iqr "Compute the interquartile range.")
|
||||
(defn iqr [data]
|
||||
(let [s &(quartiles data)]
|
||||
(the Double (- @(Array.nth s 2) @(Array.nth s 0)))))
|
||||
(the Double (- @(Array.unsafe-nth s 2) @(Array.unsafe-nth s 0)))))
|
||||
|
||||
(hidden winsorize)
|
||||
(defn winsorize [samples pct]
|
||||
@ -166,7 +166,7 @@
|
||||
hi (Statistics.percentile-of-sorted tmp (Double.- 100.0 pct))]
|
||||
(do
|
||||
(for [i 0 (Array.length tmp)]
|
||||
(let [samp @(Array.nth tmp i)]
|
||||
(let [samp @(Array.unsafe-nth tmp i)]
|
||||
(cond
|
||||
(> samp hi) (Array.aset! tmp i hi)
|
||||
(< samp lo) (Array.aset! tmp i lo)
|
||||
|
258
core/StdInt.carp
Normal file
258
core/StdInt.carp
Normal file
@ -0,0 +1,258 @@
|
||||
(relative-include "carp_stdint.h")
|
||||
|
||||
(register-type Uint8)
|
||||
(register-type Uint16)
|
||||
(register-type Uint32)
|
||||
(register-type Uint64)
|
||||
(register-type Int8)
|
||||
(register-type Int16)
|
||||
(register-type Int32)
|
||||
(register-type Int64)
|
||||
|
||||
(defmodule Int8
|
||||
(register = (λ [Int8 Int8] Bool))
|
||||
(register > (λ [Int8 Int8] Bool))
|
||||
(register < (λ [Int8 Int8] Bool))
|
||||
(register + (λ [Int8 Int8] Int8))
|
||||
(register - (λ [Int8 Int8] Int8))
|
||||
(register * (λ [Int8 Int8] Int8))
|
||||
(register / (λ [Int8 Int8] Int8))
|
||||
(register bit-shift-left (λ [Int8 Int8] Int8))
|
||||
(register bit-shift-right (λ [Int8 Int8] Int8))
|
||||
(register bit-or (λ [Int8 Int8] Int8))
|
||||
(register bit-and (λ [Int8 Int8] Int8))
|
||||
(register bit-not (λ [Int8] Int8))
|
||||
(register bit-xor (λ [Int8 Int8] Int8))
|
||||
(register to-long (λ [Int8] Long))
|
||||
(register from-long (λ [Long] Int8))
|
||||
(register str (λ [Int8] String))
|
||||
(register copy (Fn [&Int8] Int8))
|
||||
|
||||
(defn prn [a] (Int8.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int8)))
|
||||
)
|
||||
|
||||
(defmodule Int8Extra
|
||||
(defn prn [a] (Int8.prn @a))
|
||||
(defn str [a] (Int8.str @a))
|
||||
(defn = [a b] (Int8.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Int16
|
||||
(register = (λ [Int16 Int16] Bool))
|
||||
(register > (λ [Int16 Int16] Bool))
|
||||
(register < (λ [Int16 Int16] Bool))
|
||||
(register + (λ [Int16 Int16] Int16))
|
||||
(register - (λ [Int16 Int16] Int16))
|
||||
(register * (λ [Int16 Int16] Int16))
|
||||
(register / (λ [Int16 Int16] Int16))
|
||||
(register bit-shift-left (λ [Int16 Int16] Int16))
|
||||
(register bit-shift-right (λ [Int16 Int16] Int16))
|
||||
(register bit-or (λ [Int16 Int16] Int16))
|
||||
(register bit-and (λ [Int16 Int16] Int16))
|
||||
(register bit-not (λ [Int16] Int16))
|
||||
(register bit-xor (λ [Int16 Int16] Int16))
|
||||
(register to-long (λ [Int16] Long))
|
||||
(register from-long (λ [Long] Int16))
|
||||
(register str (λ [Int16] String))
|
||||
(register copy (Fn [&Int16] Int16))
|
||||
|
||||
(defn prn [a] (Int16.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int16)))
|
||||
)
|
||||
|
||||
(defmodule Int16Extra
|
||||
(defn prn [a] (Int16.prn @a))
|
||||
(defn str [a] (Int16.str @a))
|
||||
(defn = [a b] (Int16.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Int32
|
||||
(register = (λ [Int32 Int32] Bool))
|
||||
(register > (λ [Int32 Int32] Bool))
|
||||
(register < (λ [Int32 Int32] Bool))
|
||||
(register + (λ [Int32 Int32] Int32))
|
||||
(register - (λ [Int32 Int32] Int32))
|
||||
(register * (λ [Int32 Int32] Int32))
|
||||
(register / (λ [Int32 Int32] Int32))
|
||||
(register bit-shift-left (λ [Int32 Int32] Int32))
|
||||
(register bit-shift-right (λ [Int32 Int32] Int32))
|
||||
(register bit-or (λ [Int32 Int32] Int32))
|
||||
(register bit-and (λ [Int32 Int32] Int32))
|
||||
(register bit-not (λ [Int32] Int32))
|
||||
(register bit-xor (λ [Int32 Int32] Int32))
|
||||
(register to-long (λ [Int32] Long))
|
||||
(register from-long (λ [Long] Int32))
|
||||
(register str (λ [Int32] String))
|
||||
(register copy (Fn [&Int32] Int32))
|
||||
|
||||
(defn prn [a] (Int32.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int32)))
|
||||
)
|
||||
|
||||
(defmodule Int32Extra
|
||||
(defn prn [a] (Int32.prn @a))
|
||||
(defn str [a] (Int32.str @a))
|
||||
(defn = [a b] (Int32.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Int64
|
||||
(register = (λ [Int64 Int64] Bool))
|
||||
(register > (λ [Int64 Int64] Bool))
|
||||
(register < (λ [Int64 Int64] Bool))
|
||||
(register + (λ [Int64 Int64] Int64))
|
||||
(register - (λ [Int64 Int64] Int64))
|
||||
(register * (λ [Int64 Int64] Int64))
|
||||
(register / (λ [Int64 Int64] Int64))
|
||||
(register bit-shift-left (λ [Int64 Int64] Int64))
|
||||
(register bit-shift-right (λ [Int64 Int64] Int64))
|
||||
(register bit-or (λ [Int64 Int64] Int64))
|
||||
(register bit-and (λ [Int64 Int64] Int64))
|
||||
(register bit-not (λ [Int64] Int64))
|
||||
(register bit-xor (λ [Int64 Int64] Int64))
|
||||
(register to-long (λ [Int64] Long))
|
||||
(register from-long (λ [Long] Int64))
|
||||
(register str (λ [Int64] String))
|
||||
(register copy (Fn [&Int64] Int64))
|
||||
|
||||
(defn prn [a] (Int64.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Int64)))
|
||||
)
|
||||
|
||||
(defmodule Int64Extra
|
||||
(defn prn [a] (Int64.prn @a))
|
||||
(defn str [a] (Int64.str @a))
|
||||
(defn = [a b] (Int64.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Uint8
|
||||
(register = (λ [Uint8 Uint8] Bool))
|
||||
(register > (λ [Uint8 Uint8] Bool))
|
||||
(register < (λ [Uint8 Uint8] Bool))
|
||||
(register + (λ [Uint8 Uint8] Uint8))
|
||||
(register - (λ [Uint8 Uint8] Uint8))
|
||||
(register * (λ [Uint8 Uint8] Uint8))
|
||||
(register / (λ [Uint8 Uint8] Uint8))
|
||||
(register bit-shift-left (λ [Uint8 Uint8] Uint8))
|
||||
(register bit-shift-right (λ [Uint8 Uint8] Uint8))
|
||||
(register bit-or (λ [Uint8 Uint8] Uint8))
|
||||
(register bit-and (λ [Uint8 Uint8] Uint8))
|
||||
(register bit-not (λ [Uint8] Uint8))
|
||||
(register bit-xor (λ [Uint8 Uint8] Uint8))
|
||||
(register to-long (λ [Uint8] Long))
|
||||
(register from-long (λ [Long] Uint8))
|
||||
(register str (λ [Uint8] String))
|
||||
(register copy (Fn [&Uint8] Uint8))
|
||||
|
||||
(defn prn [a] (Uint8.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Uint8)))
|
||||
)
|
||||
|
||||
(defmodule Uint8Extra
|
||||
(defn prn [a] (Uint8.prn @a))
|
||||
(defn str [a] (Uint8.str @a))
|
||||
(defn = [a b] (Uint8.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Uint16
|
||||
(register = (λ [Uint16 Uint16] Bool))
|
||||
(register > (λ [Uint16 Uint16] Bool))
|
||||
(register < (λ [Uint16 Uint16] Bool))
|
||||
(register + (λ [Uint16 Uint16] Uint16))
|
||||
(register - (λ [Uint16 Uint16] Uint16))
|
||||
(register * (λ [Uint16 Uint16] Uint16))
|
||||
(register / (λ [Uint16 Uint16] Uint16))
|
||||
(register bit-shift-left (λ [Uint16 Uint16] Uint16))
|
||||
(register bit-shift-right (λ [Uint16 Uint16] Uint16))
|
||||
(register bit-or (λ [Uint16 Uint16] Uint16))
|
||||
(register bit-and (λ [Uint16 Uint16] Uint16))
|
||||
(register bit-not (λ [Uint16] Uint16))
|
||||
(register bit-xor (λ [Uint16 Uint16] Uint16))
|
||||
(register to-long (λ [Uint16] Long))
|
||||
(register from-long (λ [Long] Uint16))
|
||||
(register str (λ [Uint16] String))
|
||||
(register copy (Fn [&Uint16] Uint16))
|
||||
|
||||
(defn prn [a] (Uint16.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Uint16)))
|
||||
)
|
||||
|
||||
(defmodule Uint16Extra
|
||||
(defn prn [a] (Uint16.prn @a))
|
||||
(defn str [a] (Uint16.str @a))
|
||||
(defn = [a b] (Uint16.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Uint32
|
||||
(register = (λ [Uint32 Uint32] Bool))
|
||||
(register > (λ [Uint32 Uint32] Bool))
|
||||
(register < (λ [Uint32 Uint32] Bool))
|
||||
(register + (λ [Uint32 Uint32] Uint32))
|
||||
(register - (λ [Uint32 Uint32] Uint32))
|
||||
(register * (λ [Uint32 Uint32] Uint32))
|
||||
(register / (λ [Uint32 Uint32] Uint32))
|
||||
(register bit-shift-left (λ [Uint32 Uint32] Uint32))
|
||||
(register bit-shift-right (λ [Uint32 Uint32] Uint32))
|
||||
(register bit-or (λ [Uint32 Uint32] Uint32))
|
||||
(register bit-and (λ [Uint32 Uint32] Uint32))
|
||||
(register bit-not (λ [Uint32] Uint32))
|
||||
(register bit-xor (λ [Uint32 Uint32] Uint32))
|
||||
(register to-long (λ [Uint32] Long))
|
||||
(register from-long (λ [Long] Uint32))
|
||||
(register str (λ [Uint32] String))
|
||||
(register copy (Fn [&Uint32] Uint32))
|
||||
|
||||
(defn prn [a] (Uint32.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Uint32)))
|
||||
)
|
||||
|
||||
(defmodule Uint32Extra
|
||||
(defn prn [a] (Uint32.prn @a))
|
||||
(defn str [a] (Uint32.str @a))
|
||||
(defn = [a b] (Uint32.= @a @b))
|
||||
)
|
||||
|
||||
(defmodule Uint64
|
||||
(register = (λ [Uint64 Uint64] Bool))
|
||||
(register > (λ [Uint64 Uint64] Bool))
|
||||
(register < (λ [Uint64 Uint64] Bool))
|
||||
(register + (λ [Uint64 Uint64] Uint64))
|
||||
(register - (λ [Uint64 Uint64] Uint64))
|
||||
(register * (λ [Uint64 Uint64] Uint64))
|
||||
(register / (λ [Uint64 Uint64] Uint64))
|
||||
(register bit-shift-left (λ [Uint64 Uint64] Uint64))
|
||||
(register bit-shift-right (λ [Uint64 Uint64] Uint64))
|
||||
(register bit-or (λ [Uint64 Uint64] Uint64))
|
||||
(register bit-and (λ [Uint64 Uint64] Uint64))
|
||||
(register bit-not (λ [Uint64] Uint64))
|
||||
(register bit-xor (λ [Uint64 Uint64] Uint64))
|
||||
(register to-long (λ [Uint64] Long))
|
||||
(register from-long (λ [Long] Uint64))
|
||||
(register str (λ [Uint64] String))
|
||||
(register copy (Fn [&Uint64] Uint64))
|
||||
|
||||
(defn prn [a] (Uint64.str a))
|
||||
(defn zero [] (from-long 0l))
|
||||
|
||||
(register from-bytes (Fn [&(Array Byte)] (Array Uint64)))
|
||||
)
|
||||
|
||||
(defmodule Uint64Extra
|
||||
(defn prn [a] (Uint64.prn @a))
|
||||
(defn str [a] (Uint64.str @a))
|
||||
(defn = [a b] (Uint64.= @a @b))
|
||||
)
|
@ -10,6 +10,7 @@
|
||||
(register copy (Fn [&String] String))
|
||||
(register length (Fn [&String] Int))
|
||||
(register cstr (Fn [&String] (Ptr Char)))
|
||||
(register from-cstr (Fn [(Ptr Char)] String))
|
||||
(register str (Fn [&String] String))
|
||||
(register prn (Fn [&String] String))
|
||||
(register index-of (Fn [&String Char] Int))
|
||||
@ -23,19 +24,17 @@
|
||||
(register string-set-at! (Fn [&String Int &String] ()))
|
||||
(register allocate (Fn [Int Char] String))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= (the (Ref String) a) b)))
|
||||
|
||||
(doc head "Returns the character at start of string.")
|
||||
(defn head [s]
|
||||
(char-at s 0))
|
||||
|
||||
(doc repeat "Returns a new string which is `inpt` repeated `n` times.")
|
||||
(defn repeat [n inpt]
|
||||
(let [str @""]
|
||||
(let [l (length inpt)
|
||||
str (String.allocate (* n l) \0)]
|
||||
(do
|
||||
(for [i 0 n]
|
||||
(set! str (append &str inpt)))
|
||||
(string-set-at! &str (* i l) inpt))
|
||||
str)))
|
||||
|
||||
(doc pad-left "Pads the left of a string with len bytes using the padding pad.")
|
||||
@ -64,24 +63,27 @@
|
||||
(defn empty? [s]
|
||||
(Int.= (length s) 0))
|
||||
|
||||
(defn substring [s a b]
|
||||
(from-chars &(Array.subarray &(chars s) a b)))
|
||||
(defn slice [s a b]
|
||||
(from-chars &(Array.slice &(chars s) a b)))
|
||||
|
||||
(doc prefix-string "Return the first `a` characters of the string `s`.")
|
||||
(defn prefix-string [s a]
|
||||
(from-chars &(Array.subarray &(chars s) 0 a)))
|
||||
(doc prefix "Return the first `a` characters of the string `s`.")
|
||||
(defn prefix [s a]
|
||||
(from-chars &(Array.slice &(chars s) 0 a)))
|
||||
|
||||
(doc suffix-string "Return the last `b` characters of the string `s`.")
|
||||
(defn suffix-string [s b]
|
||||
(from-chars &(Array.subarray &(chars s) b (length s))))
|
||||
(doc suffix "Return the last `b` characters of the string `s`.")
|
||||
(defn suffix [s b]
|
||||
(from-chars &(Array.slice &(chars s) b (length s))))
|
||||
|
||||
(doc starts-with? "Check if the string `s` begins with the string `sub`.")
|
||||
(defn starts-with? [s sub]
|
||||
(= sub &(prefix-string s (length sub))))
|
||||
(let [ls (length sub)]
|
||||
(and (>= (length s) ls) (= sub &(prefix s ls)))))
|
||||
|
||||
(doc ends-with? "Check if the string `s` ends with the string `sub`.")
|
||||
(defn ends-with? [s sub]
|
||||
(= sub &(suffix-string s (- (length s) (length sub)))))
|
||||
(let [ls (length s)
|
||||
lsub (length sub)]
|
||||
(and (>= ls lsub) (= sub &(suffix s (- ls lsub))))))
|
||||
|
||||
(doc zero "The empty string.")
|
||||
(defn zero [] @"")
|
||||
@ -91,7 +93,7 @@
|
||||
(let-do [sum 0
|
||||
lstrings (Array.length strings)]
|
||||
(for [i 0 lstrings]
|
||||
(set! sum (+ sum (String.length (Array.nth strings i)))))
|
||||
(set! sum (+ sum (String.length (Array.unsafe-nth strings i)))))
|
||||
sum))
|
||||
|
||||
(doc concat "Returns a new string which is the concatenation of the provided `strings`.")
|
||||
@ -104,7 +106,7 @@
|
||||
lstrings (Array.length strings)
|
||||
result (String.allocate (sum-length strings) \ )]
|
||||
(for [i 0 lstrings]
|
||||
(let-do [str (Array.nth strings i)
|
||||
(let-do [str (Array.unsafe-nth strings i)
|
||||
len (String.length str)]
|
||||
(string-set-at! &result j str)
|
||||
(set! j (+ j len))))
|
||||
@ -114,16 +116,16 @@
|
||||
(defn join [sep strings]
|
||||
(let-do [j 0
|
||||
lstrings (Array.length strings)
|
||||
num-seps (- lstrings 1)
|
||||
sep-length (String.length &sep)
|
||||
num-seps (max 0 (- lstrings 1))
|
||||
sep-length (String.length sep)
|
||||
seps-size (* num-seps sep-length)
|
||||
result (String.allocate (+ seps-size (sum-length strings)) \ )]
|
||||
(for [i 0 lstrings]
|
||||
(let-do [str (Array.nth strings i)
|
||||
(let-do [str (Array.unsafe-nth strings i)
|
||||
len (String.length str)]
|
||||
(when (> i 0)
|
||||
(do
|
||||
(string-set-at! &result j &sep)
|
||||
(string-set-at! &result j sep)
|
||||
(set! j (+ j sep-length))))
|
||||
(string-set-at! &result j str)
|
||||
(set! j (+ j len))))
|
||||
@ -134,10 +136,10 @@
|
||||
;; (= (join-with-char \ ["Hello" "world"]) (join " " ["Hello" "world"]))
|
||||
(let-do [j 0
|
||||
lstrings (Array.length strings)
|
||||
sep-length (- lstrings 1)
|
||||
sep-length (max 0 (- lstrings 1))
|
||||
result (String.allocate (+ sep-length (sum-length strings)) \ )]
|
||||
(for [i 0 lstrings]
|
||||
(let-do [str (Array.nth strings i)
|
||||
(let-do [str (Array.unsafe-nth strings i)
|
||||
len (String.length str)]
|
||||
(when (> i 0)
|
||||
(do
|
||||
@ -157,9 +159,6 @@
|
||||
(defn = [a b]
|
||||
(String.= &a &b))
|
||||
|
||||
(defn /= [a b]
|
||||
(String./= &a &b))
|
||||
|
||||
(defn < [a b]
|
||||
(String.< &a &b))
|
||||
|
||||
@ -184,9 +183,16 @@
|
||||
(register from-string (λ [&String] Int))
|
||||
)
|
||||
|
||||
(defmodule Byte
|
||||
(register str (Fn [Byte] String))
|
||||
(register format (Fn [&String Byte] String))
|
||||
(register from-string (λ [&String] Byte))
|
||||
)
|
||||
|
||||
(defmodule Float
|
||||
(register str (Fn [Float] String))
|
||||
(register format (Fn [&String Float] String))
|
||||
(register from-string (λ [&String] Float))
|
||||
)
|
||||
|
||||
(defmodule Long
|
||||
@ -198,6 +204,7 @@
|
||||
(defmodule Double
|
||||
(register str (Fn [Double] String))
|
||||
(register format (Fn [&String Double] String))
|
||||
(register from-string (λ [&String] Double))
|
||||
)
|
||||
|
||||
(defmodule Char
|
||||
@ -207,6 +214,7 @@
|
||||
)
|
||||
|
||||
(defmodule Int (defn prn [x] (Int.str x)))
|
||||
(defmodule Byte (defn prn [x] (Byte.str x)))
|
||||
(defmodule IntRef
|
||||
(defn prn [x] (Int.str @x))
|
||||
(defn str [x] (Int.str @x))
|
||||
@ -216,6 +224,11 @@
|
||||
(defn prn [x] (Bool.str @x))
|
||||
(defn str [x] (Bool.str @x)))
|
||||
|
||||
(defmodule ByteRef
|
||||
(defn prn [x] (Byte.str @x))
|
||||
(defn str [x] (Byte.str @x))
|
||||
)
|
||||
|
||||
(defmodule Long (defn prn [x] (Long.str x)))
|
||||
(defmodule Float (defn prn [x] (Float.str x)))
|
||||
(defmodule Double (defn prn [x] (Double.str x)))
|
||||
|
@ -1,6 +1,9 @@
|
||||
(system-include "carp_system.h")
|
||||
(system-include "errno.h")
|
||||
|
||||
(defmodule System
|
||||
(doc carp-init-globals "Initializes all global variables (in correct order, based on interdependencies). Called automatically by `main` if the project is compiled as an executable. Client code needs to call this function manually when using a library written in Carp.")
|
||||
(register carp-init-globals (Fn [Int Int] ()) "carp_init_globals")
|
||||
(doc free "Frees an object. Should not be called except in direst circumstances.")
|
||||
(register free (Fn [t] ()))
|
||||
(doc time "Gets the current system time as an integer.")
|
||||
@ -27,5 +30,25 @@
|
||||
(register signal-int Int "SIGINT")
|
||||
(register signal-segv Int "SIGSEGV")
|
||||
(register signal-term Int "SIGTERM")
|
||||
)
|
||||
(register abort (Fn [] ()) "abort")
|
||||
|
||||
(register errno Int "errno")
|
||||
(register EACCES Int "EACCES")
|
||||
(register EEXIST Int "EEXIST")
|
||||
(register EINVAL Int "EINVAL")
|
||||
(register EIO Int "EIO")
|
||||
(register EISDIR Int "EISDIR")
|
||||
(register ELOOP Int "ELOOP")
|
||||
(register EMFILE Int "EMFILE")
|
||||
(register ENAMETOOLONG Int "ENAMETOOLONG")
|
||||
(register ENOENT Int "ENOENT")
|
||||
(register ENOMEM Int "EINVAL")
|
||||
(register ENOSPC Int "ENOSPC")
|
||||
(register ENOSR Int "ENOSR")
|
||||
(register ENOTDIR Int "ENOTDIR")
|
||||
(register ENXIO Int "ENXIO")
|
||||
(register EOVERFLOW Int "EOVERFLOW")
|
||||
(register EROFS Int "EROFS")
|
||||
(register EINTR Int "EINTR")
|
||||
|
||||
)
|
||||
|
@ -2,20 +2,20 @@
|
||||
|
||||
(defmodule Test
|
||||
(deftype State [passed Int, failed Int])
|
||||
|
||||
(use Color.Id)
|
||||
(hidden handler)
|
||||
(defn handler [state expected actual descr what op]
|
||||
(if (op expected actual)
|
||||
(do
|
||||
(IO.colorize "green" &(str* @"Test '" @descr @"' passed\n"))
|
||||
(IO.colorize (Green) &(str* @"Test '" @descr @"' passed\n"))
|
||||
(State.update-passed (State.copy state) &Int.inc))
|
||||
(do
|
||||
(IO.color "red")
|
||||
(IO.color (Red))
|
||||
(IO.println &(str* @"Test '" @descr @"' failed:"))
|
||||
(IO.print &(str* @"\tExpected " @what @": '"))
|
||||
(IO.print &(str expected))
|
||||
(IO.println &(str* @"', actual value: '" (str actual) @"'"))
|
||||
(IO.color "reset")
|
||||
(IO.color (Reset))
|
||||
(State.update-failed (State.copy state) &Int.inc))))
|
||||
|
||||
(doc assert-op "Assert that op returns true when given x and y.")
|
||||
@ -90,21 +90,21 @@
|
||||
(IO.println "Results:")
|
||||
(if (Int.> (Int.+ passed failed) 0)
|
||||
(do
|
||||
(IO.color "green")
|
||||
(if (Int.> passed 0) (IO.print &(String.append "\t|" &(String.repeat passed "="))) ())
|
||||
(if (Int.= failed 0) (IO.print "|") ())
|
||||
(IO.color "red")
|
||||
(if (Int.= passed 0) (IO.print "\t|") ())
|
||||
(if (Int.> failed 0) (IO.print &(String.append &(String.repeat failed "=") "|")) ())
|
||||
(IO.color (Green))
|
||||
(when (Int.> passed 0) (IO.print &(String.append "\t|" &(String.allocate passed \=))))
|
||||
(when (Int.= failed 0) (IO.print "|"))
|
||||
(IO.color (Red))
|
||||
(when (Int.= passed 0) (IO.print "\t|"))
|
||||
(when (Int.> failed 0) (IO.print &(String.append &(String.allocate failed \=) "|")))
|
||||
(IO.println ""))
|
||||
())
|
||||
(IO.color "green")
|
||||
(IO.color (Green))
|
||||
(IO.print "\tPassed: ")
|
||||
(IO.print &(Int.str passed))
|
||||
(IO.color "red")
|
||||
(IO.color (Red))
|
||||
(IO.print "\tFailed: ")
|
||||
(IO.println &(Int.str failed))
|
||||
(IO.color "reset")))))
|
||||
(IO.color (Reset))))))
|
||||
|
||||
(defndynamic with-test-internal [name forms]
|
||||
(if (= (length forms) 1)
|
||||
|
@ -5,9 +5,6 @@
|
||||
(and (= (Pair.a p1) (Pair.a p2))
|
||||
(= (Pair.b p1) (Pair.b p2))))
|
||||
|
||||
(defn /= [p1 p2]
|
||||
(not (PairRef.= p1 p2)))
|
||||
|
||||
(defn < [p1 p2]
|
||||
(if (= (Pair.a p1) (Pair.a p2))
|
||||
(< (Pair.b p1) (Pair.b p2))
|
||||
@ -24,9 +21,6 @@
|
||||
(and (= (Pair.a &p1) (Pair.a &p2))
|
||||
(= (Pair.b &p1) (Pair.b &p2))))
|
||||
|
||||
(defn /= [p1 p2]
|
||||
(not (Pair.= p1 p2)))
|
||||
|
||||
(defn < [p1 p2]
|
||||
(PairRef.< &p1 &p2))
|
||||
|
||||
|
236
core/Vector.carp
236
core/Vector.carp
@ -1,19 +1,28 @@
|
||||
(deftype (Vector2 a) [x a, y a])
|
||||
(deftype (Vector2 f) [x f, y f])
|
||||
|
||||
(defmodule Vector2
|
||||
(defn map [f v]
|
||||
(init (f @(x v))
|
||||
(f @(y v))))
|
||||
|
||||
(defn zip [f a b]
|
||||
(init (f @(x a) @(x b))
|
||||
(f @(y a) @(y b))))
|
||||
|
||||
(defn vreduce [f i v]
|
||||
(f (f i @(x v)) @(y v)))
|
||||
|
||||
(defn zero []
|
||||
(init 0.0 0.0))
|
||||
(init (zero) (zero)))
|
||||
|
||||
(defn random []
|
||||
(init (random-between 0.0 1.0) (random-between 0.0 1.0)))
|
||||
(init (random-0-1) (random-0-1)))
|
||||
|
||||
(defn add [a b]
|
||||
(init (+ @(x a) @(x b))
|
||||
(+ @(y a) @(y b))))
|
||||
(zip + a b))
|
||||
|
||||
(defn sub [a b]
|
||||
(init (- @(x a) @(x b))
|
||||
(- @(y a) @(y b))))
|
||||
(zip - a b))
|
||||
|
||||
(defn mul [a n]
|
||||
(init (* @(x a) n)
|
||||
@ -24,31 +33,31 @@
|
||||
(/ @(y a) n)))
|
||||
|
||||
(defn = [a b]
|
||||
(and (Double.= @(x a) @(x b))
|
||||
(Double.= @(y a) @(y b))))
|
||||
(vreduce (fn [i v] (and i v)) true &(zip = a b)))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= a b)))
|
||||
(doc vapprox "Check whether the vectors a and b are approximately equal.")
|
||||
(defn vapprox [a b]
|
||||
(vreduce (fn [i v] (and i v)) true &(zip Generics.approx a b)))
|
||||
|
||||
(doc approx "Check whether the vectors a and b are approximately equal.")
|
||||
(defn approx [a b]
|
||||
(and (Double.approx @(x a) @(x b))
|
||||
(Double.approx @(y a) @(y b))))
|
||||
(defn sum [o]
|
||||
(vreduce + (zero) o))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [a b]
|
||||
(sum &(zip * a b)))
|
||||
|
||||
(doc mag-sq "Get the squared magnitude of a vector.")
|
||||
(defn mag-sq [o]
|
||||
(let [x @(x o)
|
||||
y @(y o)]
|
||||
(+ (* x x) (* y y))))
|
||||
(dot o o))
|
||||
|
||||
(doc mag "Get the magnitude of a vector.")
|
||||
(defn mag [o]
|
||||
(Double.sqrt (mag-sq o)))
|
||||
(sqrt (mag-sq o)))
|
||||
|
||||
(doc normalize "Normalize a vector.")
|
||||
(defn normalize [o]
|
||||
(let [m (mag o)]
|
||||
(if (= m 0.0)
|
||||
(if (zero? m)
|
||||
@o
|
||||
(div o m))))
|
||||
|
||||
@ -59,97 +68,110 @@
|
||||
|
||||
(doc heading "Get the heading of the vector a.")
|
||||
(defn heading [a]
|
||||
(Double.atan2 @(y a) @(x a)))
|
||||
(atan2 @(y a) @(x a)))
|
||||
|
||||
(doc rotate "Rotate the vector a by the radians n.")
|
||||
(defn rotate [a n]
|
||||
(let [h (+ (heading a) n)
|
||||
m (mag a)]
|
||||
(init (* (Double.cos h) m) (* (Double.sin h) m))))
|
||||
(init (* (cos h) m) (* (sin h) m))))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [a b]
|
||||
(+ (* @(x a) @(x b))
|
||||
(* @(y a) @(y b))))
|
||||
|
||||
(doc angle-between "Get the angle between to vectors a and b.")
|
||||
(doc angle-between "Get the angle between two vectors a and b.")
|
||||
(defn angle-between [a b]
|
||||
(let [dmm (/ (dot a b) (* (mag a) (mag b)))]
|
||||
(Double.acos (Double.clamp -1.0 1.0 dmm))))
|
||||
(acos (clamp--1-1 dmm))))
|
||||
|
||||
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
|
||||
(defn anti-parallel? [a b]
|
||||
(= (angle-between a b) Double.pi))
|
||||
(= (angle-between a b) pi))
|
||||
|
||||
(doc parallel? "Check whether the two vectors a and b are parallel.")
|
||||
(defn parallel? [a b]
|
||||
(= (angle-between a b) 0.0))
|
||||
(zero? (angle-between a b)))
|
||||
|
||||
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
|
||||
(defn perpendicular? [a b]
|
||||
(= (angle-between a b) (/ Double.pi 2.0)))
|
||||
(= (angle-between a b) (Generics.half-pi)))
|
||||
|
||||
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn lerp [a b amnt]
|
||||
(init (* (- @(x b) @(x a)) amnt)
|
||||
(* (- @(y b) @(y a)) amnt)))
|
||||
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn vlerp [a b amnt]
|
||||
(zip (fn [a b] (lerp a b amnt)) a b))
|
||||
)
|
||||
|
||||
(deftype (Vector3 a) [x a, y a, z a])
|
||||
(deftype (Vector3 f) [x f, y f, z f])
|
||||
|
||||
(defmodule Vector3
|
||||
(defn map [f v]
|
||||
(init (f @(x v))
|
||||
(f @(y v))
|
||||
(f @(z v))))
|
||||
|
||||
(defn zip [f a b]
|
||||
(init (f @(x a) @(x b))
|
||||
(f @(y a) @(y b))
|
||||
(f @(z a) @(z b))))
|
||||
|
||||
(defn vreduce [f i v]
|
||||
(f (f (f i @(x v)) @(y v)) @(z v)))
|
||||
|
||||
(defn zero []
|
||||
(init 0.0 0.0 0.0))
|
||||
(init (zero) (zero) (zero)))
|
||||
|
||||
(defn random []
|
||||
(init (random-between 0.0 1.0) (random-between 0.0 1.0) (random-between 0.0 1.0)))
|
||||
(init (random-0-1) (random-0-1) (random-0-1)))
|
||||
|
||||
(defn = [a b]
|
||||
(and (Double.= @(x a) @(x b))
|
||||
(and (Double.= @(y a) @(y b))
|
||||
(Double.= @(z a) @(z b)))))
|
||||
(vreduce (fn [i v] (and i v)) true &(zip = a b)))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= a b)))
|
||||
(doc vapprox "Check whether the vectors a and b are approximately equal.")
|
||||
(defn vapprox [a b]
|
||||
(vreduce (fn [i v] (and i v)) true &(zip Generics.approx a b)))
|
||||
|
||||
(defn add [a b]
|
||||
(init (+ @(x a) @(x b))
|
||||
(+ @(y a) @(y b))
|
||||
(+ @(z a) @(z b))))
|
||||
(zip + a b))
|
||||
|
||||
(defn sub [a b]
|
||||
(init (- @(x a) @(x b))
|
||||
(- @(y a) @(y b))
|
||||
(- @(z a) @(z b))))
|
||||
(zip - a b))
|
||||
|
||||
(defn mul [a n]
|
||||
(init (* @(x a) n)
|
||||
(* @(y a) n)
|
||||
(* @(z a) n)))
|
||||
(defn cmul [a b]
|
||||
(zip * a b))
|
||||
|
||||
(defn div [a n]
|
||||
(init (/ @(x a) n)
|
||||
(/ @(y a) n)
|
||||
(/ @(z a) n)))
|
||||
(defn neg [a]
|
||||
(map neg a))
|
||||
|
||||
(defn mul [v n]
|
||||
(map (fn [c] (* n c)) v))
|
||||
|
||||
(defn div [v n]
|
||||
(map (fn [c] (/ c n)) v))
|
||||
|
||||
(defn sum [o]
|
||||
(vreduce + (zero) o))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [a b]
|
||||
(sum &(zip * a b)))
|
||||
|
||||
(doc mag-sq "Get the squared magnitude of a vector.")
|
||||
(defn mag-sq [o]
|
||||
(let [x @(x o)
|
||||
y @(y o)
|
||||
z @(z o)]
|
||||
(+ (* x x) (+ (* y y) (* z z)))))
|
||||
(dot o o))
|
||||
|
||||
(doc mag "Get the magnitude of a vector.")
|
||||
(defn mag [o]
|
||||
(Double.sqrt (mag-sq o)))
|
||||
(sqrt (mag-sq o)))
|
||||
|
||||
(doc normalize "Normalize a vector.")
|
||||
(defn normalize [o]
|
||||
(let [m (mag o)]
|
||||
(if (= m 0.0)
|
||||
(if (= m (zero))
|
||||
@o
|
||||
(div o m))))
|
||||
|
||||
(doc dist "Get the distance between the vectors a and b.")
|
||||
(defn dist [a b]
|
||||
(let [s (sub b a)]
|
||||
(mag &s)))
|
||||
|
||||
(doc cross "Compute the cross product of the two vectors x and y.")
|
||||
(defn cross [a b]
|
||||
(init
|
||||
@ -160,57 +182,45 @@
|
||||
(- (* @(x a) @(y b))
|
||||
(* @(y a) @(x b)))))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [a b]
|
||||
(+ (* @(x a) @(x b))
|
||||
(+ (* @(y a) @(y b))
|
||||
(* @(z a) @(z b)))))
|
||||
|
||||
(doc angle-between "Get the angle between to vectors a and b.")
|
||||
(doc angle-between "Get the angle between two vectors a and b.")
|
||||
(defn angle-between [a b]
|
||||
(let [dmm (/ (dot a b) (* (mag a) (mag b)))]
|
||||
(Double.acos (Double.clamp -1.0 1.0 dmm))))
|
||||
(acos (clamp--1-1 dmm))))
|
||||
|
||||
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
|
||||
(defn anti-parallel? [a b]
|
||||
(= (angle-between a b) Double.pi))
|
||||
(= (angle-between a b) pi))
|
||||
|
||||
(doc parallel? "Check whether the two vectors a and b are parallel.")
|
||||
(defn parallel? [a b]
|
||||
(= (angle-between a b) 0.0))
|
||||
(zero? (angle-between a b)))
|
||||
|
||||
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
|
||||
(defn perpendicular? [a b]
|
||||
(= (angle-between a b) (/ Double.pi 2.0)))
|
||||
(= (angle-between a b) (Generics.half-pi)))
|
||||
|
||||
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn lerp [a b amnt]
|
||||
(init (* (- @(x b) @(x a)) amnt)
|
||||
(* (- @(y b) @(y a)) amnt)
|
||||
(* (- @(z b) @(z a)) amnt)))
|
||||
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn vlerp [a b amnt]
|
||||
(zip (fn [a b] (lerp a b amnt)) a b))
|
||||
)
|
||||
|
||||
(deftype (VectorN a) [n Int, v (Array a)])
|
||||
|
||||
(deftype (VectorN f) [n Int, v (Array f)])
|
||||
|
||||
(defmodule VectorN
|
||||
(defn zero-sized [n]
|
||||
(let [z 0.0]
|
||||
(let [z (zero)]
|
||||
(init n (Array.replicate n &z))))
|
||||
|
||||
(private unit-random)
|
||||
(hidden unit-random)
|
||||
(defn unit-random []
|
||||
(random-between 0.0 1.0))
|
||||
|
||||
(defn random-sized [n]
|
||||
(init n (Array.repeat n &unit-random)))
|
||||
(init n (Array.repeat n &random-0-1)))
|
||||
|
||||
(defn zip- [f a b]
|
||||
(let [total (Array.allocate (Array.length a))]
|
||||
(do
|
||||
(for [i 0 (Array.length a)]
|
||||
(Array.aset-uninitialized! &total i (f @(Array.nth a i)
|
||||
@(Array.nth b i))))
|
||||
(Array.aset-uninitialized! &total i (f @(Array.unsafe-nth a i)
|
||||
@(Array.unsafe-nth b i))))
|
||||
(init (Array.length a) total))))
|
||||
|
||||
(defn zip [f a b]
|
||||
@ -222,9 +232,6 @@
|
||||
(and (Int.= @(n a) @(n b))
|
||||
(Array.= (v a) (v b))))
|
||||
|
||||
(defn /= [a b]
|
||||
(not (= a b)))
|
||||
|
||||
(defn add [a b]
|
||||
(zip + a b))
|
||||
|
||||
@ -237,53 +244,50 @@
|
||||
(defn div [a n]
|
||||
(zip- / (v a) &(Array.replicate @(VectorN.n a) &n)))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [x y]
|
||||
(Maybe.apply (zip * x y)
|
||||
&(fn [x] (Array.reduce &(fn [x y] (+ x @y)) (zero) (v &x)))))
|
||||
|
||||
(doc mag-sq "Get the squared magnitude of a vector.")
|
||||
(defn mag-sq [o]
|
||||
(Array.reduce &(fn [x y] (+ x @y)) 0.0
|
||||
&(Array.copy-map &(fn [x] (* @x @x)) (v o))))
|
||||
(Maybe.unsafe-from (dot o o)))
|
||||
|
||||
(doc mag "Get the magnitude of a vector.")
|
||||
(defn mag [o]
|
||||
(Double.sqrt (mag-sq o)))
|
||||
(sqrt (mag-sq o)))
|
||||
|
||||
(doc dist "Get the distance between the vectors a and b.")
|
||||
(defn dist [a b]
|
||||
(Maybe.apply (sub b a) (fn [s] (mag &s))))
|
||||
(Maybe.apply (sub b a) &(fn [s] (mag &s))))
|
||||
|
||||
(doc normalize "Normalize a vector.")
|
||||
(defn normalize [o]
|
||||
(let [m (mag o)]
|
||||
(if (= m 0.0)
|
||||
(if (zero? m)
|
||||
@o
|
||||
(div o m))))
|
||||
|
||||
(doc dot "Get the dot product of the two vectors x and y.")
|
||||
(defn dot [x y]
|
||||
(Maybe.apply (zip * x y)
|
||||
(fn [x] (Array.reduce &(fn [x y] (+ x @y)) 0.0 (v &x)))))
|
||||
|
||||
(doc angle-between "Get the angle between to vectors a and b.")
|
||||
(doc angle-between "Get the angle between two vectors a and b.")
|
||||
(defn angle-between [a b]
|
||||
(Maybe.apply (dot a b)
|
||||
(fn [x]
|
||||
(let [dmm (/ x (* (mag a) (mag b)))]
|
||||
(Double.acos (Double.clamp -1.0 1.0 dmm))))))
|
||||
(Maybe.apply (VectorN.dot a b)
|
||||
&(fn [x]
|
||||
(let [dmm (/ x (* (VectorN.mag a) (VectorN.mag b)))]
|
||||
(acos (clamp--1-1 dmm))))))
|
||||
|
||||
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
|
||||
(defn anti-parallel? [a b]
|
||||
(Maybe.apply (angle-between a b) (fn [x] (= x Double.pi))))
|
||||
(Maybe.apply (angle-between a b) &(fn [x] (= x pi))))
|
||||
|
||||
(doc parallel? "Check whether the two vectors a and b are parallel.")
|
||||
(defn parallel? [a b]
|
||||
(Maybe.apply (angle-between a b) (fn [x] (= x 0.0))))
|
||||
(Maybe.apply (angle-between a b) &(fn [x] (zero? x))))
|
||||
|
||||
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
|
||||
(defn perpendicular? [a b]
|
||||
(Maybe.apply (angle-between a b) (fn [x] (= x (/ Double.pi 2.0)))))
|
||||
(Maybe.apply (angle-between a b) &(fn [x] (= x (Generics.half-pi)))))
|
||||
|
||||
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn lerp [a b amnt]
|
||||
(Maybe.apply (zip - b a)
|
||||
(fn [x] (init @(n a) @(v &(zip- * &(Array.replicate @(n a) &amnt)
|
||||
(v &x)))))))
|
||||
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
|
||||
(defn vlerp [a b amnt]
|
||||
(zip (fn [a b] (lerp a b amnt)) a b))
|
||||
)
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include <time.h>
|
||||
|
||||
double get_MINUS_time_MINUS_elapsed() {
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
double get_time_elapsed() {
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
}
|
||||
|
42
core/carp_binary.h
Normal file
42
core/carp_binary.h
Normal file
@ -0,0 +1,42 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint16_t Binary_to_MINUS_int16(uint8_t b1, uint8_t b2) {
|
||||
return (uint16_t)(b2 << 8) | b1;
|
||||
}
|
||||
|
||||
uint32_t Binary_to_MINUS_int32(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4) {
|
||||
return (uint32_t)b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
|
||||
}
|
||||
|
||||
uint64_t Binary_to_MINUS_int64(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b4,
|
||||
uint8_t b5, uint8_t b6, uint8_t b7, uint8_t b8) {
|
||||
return (uint64_t)b1 | (b2 << 8) | (b3 << 16) | (b4 << 24) |
|
||||
((uint64_t)b5 << 32) | ((uint64_t)b6 << 40) | ((uint64_t)b7 << 48) |
|
||||
((uint64_t)b8 << 56);
|
||||
}
|
||||
|
||||
uint8_t Binary_int16_MINUS_to_MINUS_byte(uint16_t *x) {
|
||||
return *x & 0xff;
|
||||
}
|
||||
|
||||
uint8_t Binary_int32_MINUS_to_MINUS_byte(uint32_t *x) {
|
||||
return *x & 0xff;
|
||||
}
|
||||
|
||||
uint8_t Binary_int64_MINUS_to_MINUS_byte(uint64_t *x) {
|
||||
return *x & 0xff;
|
||||
}
|
||||
|
||||
int Binary_system_MINUS_endianness_MINUS_internal() {
|
||||
// The int type is always >= 16 bits, two bytes, according to The C
|
||||
// Programming Language, Second Edition. Contrarily, char is always a single
|
||||
// byte.
|
||||
//
|
||||
// Allocating 1 and converting to char will leave us with the first byte
|
||||
// used to represent the int. On a little endian machine, we're left with 1
|
||||
// on a big endian machine, we're left with 0.
|
||||
unsigned int i = 1;
|
||||
// Conversion to char lets us access bytes individually.
|
||||
// We return the first byte.
|
||||
return (int)((char *)&i)[0];
|
||||
}
|
@ -1,14 +1,20 @@
|
||||
#include "carp_stdbool.h"
|
||||
|
||||
// Bool
|
||||
bool Bool_copy(const bool* b) {
|
||||
return *b;
|
||||
return *b;
|
||||
}
|
||||
|
||||
bool Bool__EQ_(bool a, bool b) {
|
||||
return a == b;
|
||||
return a == b;
|
||||
}
|
||||
|
||||
bool Bool__DIV__EQ_(bool a, bool b) {
|
||||
return a != b;
|
||||
bool Bool_not(bool a) {
|
||||
return !a;
|
||||
}
|
||||
|
||||
bool Bool_and(bool a, bool b) {
|
||||
return a && b;
|
||||
}
|
||||
|
||||
bool Bool_or(bool a, bool b) {
|
||||
return a && b;
|
||||
}
|
||||
|
68
core/carp_byte.h
Normal file
68
core/carp_byte.h
Normal file
@ -0,0 +1,68 @@
|
||||
typedef uint8_t byte;
|
||||
|
||||
uint8_t Byte__PLUS_(uint8_t x, uint8_t y) {
|
||||
return x + y;
|
||||
}
|
||||
uint8_t Byte__MINUS_(uint8_t x, uint8_t y) {
|
||||
return x - y;
|
||||
}
|
||||
uint8_t Byte__MUL_(uint8_t x, uint8_t y) {
|
||||
return x * y;
|
||||
}
|
||||
uint8_t Byte__DIV_(uint8_t x, uint8_t y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Byte__EQ_(uint8_t x, uint8_t y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Byte__LT_(uint8_t x, uint8_t y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Byte__GT_(uint8_t x, uint8_t y) {
|
||||
return x > y;
|
||||
}
|
||||
|
||||
uint8_t Byte_inc(uint8_t x) {
|
||||
return x + 1;
|
||||
}
|
||||
uint8_t Byte_dec(uint8_t x) {
|
||||
return x - 1;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_shift_MINUS_left(uint8_t x, uint8_t y) {
|
||||
return x << y;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_shift_MINUS_right(uint8_t x, uint8_t y) {
|
||||
return x >> y;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_and(uint8_t x, uint8_t y) {
|
||||
return x & y;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_or(uint8_t x, uint8_t y) {
|
||||
return x | y;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_xor(uint8_t x, uint8_t y) {
|
||||
return x ^ y;
|
||||
}
|
||||
uint8_t Byte_bit_MINUS_not(uint8_t x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
uint8_t Byte_copy(const uint8_t *x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
uint8_t Byte_mod(uint8_t x, uint8_t divider) {
|
||||
return x % divider;
|
||||
}
|
||||
|
||||
bool Byte_mask(uint8_t a, uint8_t b) {
|
||||
return a & b;
|
||||
}
|
||||
|
||||
int Byte_to_MINUS_int(uint8_t a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
uint8_t Byte_from_MINUS_int(int a) {
|
||||
return a;
|
||||
}
|
@ -1,31 +1,29 @@
|
||||
#include "carp_stdbool.h"
|
||||
|
||||
bool Char__EQ_(char a, char b) {
|
||||
return a == b;
|
||||
return a == b;
|
||||
}
|
||||
|
||||
bool Char__LT_(char a, char b) {
|
||||
return a < b;
|
||||
return a < b;
|
||||
}
|
||||
|
||||
bool Char__GT_(char a, char b) {
|
||||
return a > b;
|
||||
return a > b;
|
||||
}
|
||||
|
||||
int Char_to_MINUS_int(char c) {
|
||||
return (int)(unsigned char)c;
|
||||
return (int)(unsigned char)c;
|
||||
}
|
||||
|
||||
char Char_from_MINUS_int(int i) {
|
||||
return (char)i;
|
||||
return (char)i;
|
||||
}
|
||||
|
||||
char Char_copy(const char *c) {
|
||||
return *c;
|
||||
return *c;
|
||||
}
|
||||
|
||||
String PtrChar_str(const char *c) {
|
||||
size_t len = strlen(c) + 1;
|
||||
String ptr = CARP_MALLOC(len);
|
||||
return (String) memcpy(ptr, c, len);
|
||||
return (String)memcpy(ptr, c, len);
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include "core.h"
|
||||
|
||||
void Debug_leak_MINUS_array(Array a) {
|
||||
// Leaked!
|
||||
}
|
||||
|
@ -1,17 +1,33 @@
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "carp_stdbool.h"
|
||||
const double CARP_DBL_MAX = DBL_MAX;
|
||||
|
||||
double Double__PLUS_(double x, double y) { return x + y; }
|
||||
double Double__MINUS_(double x, double y) { return x - y; }
|
||||
double Double__MUL_(double x, double y) { return x * y; }
|
||||
double Double__DIV_(double x, double y) { return x / y; }
|
||||
bool Double__LT_(double x, double y) { return x < y; }
|
||||
bool Double__GT_(double x, double y) { return x > y; }
|
||||
bool Double__EQ_(double x, double y) { return x == y; }
|
||||
double Double_neg(double x) { return -x; }
|
||||
double Double__PLUS_(double x, double y) {
|
||||
return x + y;
|
||||
}
|
||||
double Double__MINUS_(double x, double y) {
|
||||
return x - y;
|
||||
}
|
||||
double Double__MUL_(double x, double y) {
|
||||
return x * y;
|
||||
}
|
||||
double Double__DIV_(double x, double y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Double__LT_(double x, double y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Double__GT_(double x, double y) {
|
||||
return x > y;
|
||||
}
|
||||
bool Double__EQ_(double x, double y) {
|
||||
return x == y;
|
||||
}
|
||||
double Double_neg(double x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
double Double_copy(const double *x) { return *x; }
|
||||
double Double_copy(const double* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
// Double.toInt : Double -> Int
|
||||
int Double_to_MINUS_int(double x) {
|
||||
|
@ -1,17 +1,33 @@
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "carp_stdbool.h"
|
||||
const float CARP_FLT_MAX = FLT_MAX;
|
||||
|
||||
float Float__PLUS_(float x, float y) { return x + y; }
|
||||
float Float__MINUS_(float x, float y) { return x - y; }
|
||||
float Float__MUL_(float x, float y) { return x * y; }
|
||||
float Float__DIV_(float x, float y) { return x / y; }
|
||||
bool Float__LT_(float x, float y) { return x < y; }
|
||||
bool Float__GT_(float x, float y) { return x > y; }
|
||||
bool Float__EQ_(float x, float y) { return x == y; }
|
||||
float Float_neg(float x) { return -x; }
|
||||
float Float__PLUS_(float x, float y) {
|
||||
return x + y;
|
||||
}
|
||||
float Float__MINUS_(float x, float y) {
|
||||
return x - y;
|
||||
}
|
||||
float Float__MUL_(float x, float y) {
|
||||
return x * y;
|
||||
}
|
||||
float Float__DIV_(float x, float y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Float__LT_(float x, float y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Float__GT_(float x, float y) {
|
||||
return x > y;
|
||||
}
|
||||
bool Float__EQ_(float x, float y) {
|
||||
return x == y;
|
||||
}
|
||||
float Float_neg(float x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
float Float_copy(const float *x) { return *x; }
|
||||
float Float_copy(const float* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
int Float_to_MINUS_int(float x) {
|
||||
return (int)x;
|
||||
@ -28,47 +44,51 @@ int Float_to_MINUS_bytes(float x) {
|
||||
}
|
||||
|
||||
float Float_abs(float x) {
|
||||
return fabs(x);
|
||||
return fabsf(x);
|
||||
}
|
||||
|
||||
float Float_acos(float x) {
|
||||
return acos(x);
|
||||
return acosf(x);
|
||||
}
|
||||
|
||||
float Float_asin(float x) {
|
||||
return asin(x);
|
||||
return asinf(x);
|
||||
}
|
||||
|
||||
float Float_atan(float x) {
|
||||
return atan(x);
|
||||
return atanf(x);
|
||||
}
|
||||
|
||||
float Float_atan2(float y, float x) {
|
||||
return atan2(y, x);
|
||||
return atan2f(y, x);
|
||||
}
|
||||
|
||||
float Float_cos(float x) {
|
||||
return cos(x);
|
||||
return cosf(x);
|
||||
}
|
||||
|
||||
float Float_cosh(float x) {
|
||||
return cosh(x);
|
||||
return coshf(x);
|
||||
}
|
||||
|
||||
float Float_sin(float x) {
|
||||
return sin(x);
|
||||
return sinf(x);
|
||||
}
|
||||
|
||||
float Float_sinh(float x) {
|
||||
return sinh(x);
|
||||
return sinhf(x);
|
||||
}
|
||||
|
||||
float Float_tan(float x) {
|
||||
return tanf(x);
|
||||
}
|
||||
|
||||
float Float_tanh(float x) {
|
||||
return tanh(x);
|
||||
return tanhf(x);
|
||||
}
|
||||
|
||||
float Float_exp(float x) {
|
||||
return exp(x);
|
||||
return expf(x);
|
||||
}
|
||||
|
||||
float Float_frexp(float x, int* exponent) {
|
||||
@ -76,37 +96,37 @@ float Float_frexp(float x, int* exponent) {
|
||||
}
|
||||
|
||||
float Float_ldexp(float x, int exponent) {
|
||||
return ldexp(x, exponent);
|
||||
return ldexpf(x, exponent);
|
||||
}
|
||||
|
||||
float Float_log(float x) {
|
||||
return log(x);
|
||||
return logf(x);
|
||||
}
|
||||
|
||||
float Float_log10(float x) {
|
||||
return log10(x);
|
||||
return log10f(x);
|
||||
}
|
||||
|
||||
float Float_modf(float x, float * integer) {
|
||||
float Float_modf(float x, float* integer) {
|
||||
return modff(x, integer);
|
||||
}
|
||||
|
||||
float Float_pow(float x, float y) {
|
||||
return pow(x, y);
|
||||
return powf(x, y);
|
||||
}
|
||||
|
||||
float Float_sqrt(float x) {
|
||||
return sqrt(x);
|
||||
return sqrtf(x);
|
||||
}
|
||||
|
||||
float Float_ceil(float x) {
|
||||
return ceil(x);
|
||||
return ceilf(x);
|
||||
}
|
||||
|
||||
float Float_floor(float x) {
|
||||
return floor(x);
|
||||
return floorf(x);
|
||||
}
|
||||
|
||||
float Float_mod(float x, float y) {
|
||||
return fmod(x, y);
|
||||
return fmodf(x, y);
|
||||
}
|
||||
|
@ -1,30 +1,62 @@
|
||||
#include <limits.h>
|
||||
#include "carp_stdbool.h"
|
||||
|
||||
int CARP_INT_MAX = INT_MAX;
|
||||
int CARP_INT_MIN = INT_MIN;
|
||||
|
||||
int Int__PLUS_(int x, int y) { return x + y; }
|
||||
int Int__MINUS_(int x, int y) { return x - y; }
|
||||
int Int__MUL_(int x, int y) { return x * y; }
|
||||
int Int__DIV_(int x, int y) { return x / y; }
|
||||
bool Int__EQ_(int x, int y) { return x == y; }
|
||||
bool Int__DIV__EQ_(int x, int y) { return x != y; }
|
||||
bool Int__LT_(int x, int y) { return x < y; }
|
||||
bool Int__GT_(int x, int y) { return x > y; }
|
||||
int Int_neg(int x) { return -x; }
|
||||
int Int__PLUS_(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
int Int__MINUS_(int x, int y) {
|
||||
return x - y;
|
||||
}
|
||||
int Int__MUL_(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
int Int__DIV_(int x, int y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int__EQ_(int x, int y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int__LT_(int x, int y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int__GT_(int x, int y) {
|
||||
return x > y;
|
||||
}
|
||||
int Int_neg(int x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
int Int_inc(int x) { return x + 1; }
|
||||
int Int_dec(int x) { return x - 1; }
|
||||
int Int_abs(int x) { return x > 0 ? x : -x; }
|
||||
int Int_bit_MINUS_shift_MINUS_left(int x, int y) { return x << y; }
|
||||
int Int_bit_MINUS_shift_MINUS_right(int x, int y) { return x >> y; }
|
||||
int Int_bit_MINUS_and(int x, int y) { return x & y; }
|
||||
int Int_bit_MINUS_or(int x, int y) { return x | y; }
|
||||
int Int_bit_MINUS_xor(int x, int y) { return x ^ y; }
|
||||
int Int_bit_MINUS_not(int x) { return ~x; }
|
||||
int Int_inc(int x) {
|
||||
return x + 1;
|
||||
}
|
||||
int Int_dec(int x) {
|
||||
return x - 1;
|
||||
}
|
||||
int Int_abs(int x) {
|
||||
return x > 0 ? x : -x;
|
||||
}
|
||||
int Int_bit_MINUS_shift_MINUS_left(int x, int y) {
|
||||
return x << y;
|
||||
}
|
||||
int Int_bit_MINUS_shift_MINUS_right(int x, int y) {
|
||||
return x >> y;
|
||||
}
|
||||
int Int_bit_MINUS_and(int x, int y) {
|
||||
return x & y;
|
||||
}
|
||||
int Int_bit_MINUS_or(int x, int y) {
|
||||
return x | y;
|
||||
}
|
||||
int Int_bit_MINUS_xor(int x, int y) {
|
||||
return x ^ y;
|
||||
}
|
||||
int Int_bit_MINUS_not(int x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
int Int_copy(const int *x) { return *x; }
|
||||
int Int_copy(const int *x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
int Int_mod(int x, int divider) {
|
||||
return x % divider;
|
||||
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
#include <stdio.h>
|
||||
void IO_println(String *s) {
|
||||
puts(*s);
|
||||
}
|
||||
void IO_print(String *s) {
|
||||
printf("%s", *s);
|
||||
}
|
||||
|
||||
#include <carp_string.h>
|
||||
void IO_errorln(String *s) {
|
||||
fprintf(stderr, "%s\n", *s);
|
||||
}
|
||||
void IO_error(String *s) {
|
||||
fprintf(stderr, "%s", *s);
|
||||
}
|
||||
|
||||
void IO_println(String *s) { puts(*s); }
|
||||
void IO_print(String *s) { printf("%s", *s); }
|
||||
|
||||
void IO_errorln(String *s) { fprintf(stderr, "%s\n", *s); }
|
||||
void IO_error(String *s) { fprintf(stderr, "%s", *s); }
|
||||
|
||||
char IO_EOF = (char) EOF;
|
||||
char IO_EOF = (char)EOF;
|
||||
|
||||
#ifdef _WIN32
|
||||
// getline isn't a C standard library function so it's missing on windows
|
||||
@ -37,13 +40,13 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
}
|
||||
|
||||
pos = 0;
|
||||
while(c != EOF) {
|
||||
while (c != EOF) {
|
||||
if (pos + 1 >= *n) {
|
||||
size_t new_size = *n + (*n >> 2);
|
||||
if (new_size < 128) {
|
||||
new_size = 128;
|
||||
}
|
||||
char *new_ptr = realloc(*lineptr, new_size);
|
||||
char *new_ptr = CARP_REALLOC(*lineptr, new_size);
|
||||
if (new_ptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@ -51,7 +54,7 @@ size_t getline(char **lineptr, size_t *n, FILE *stream) {
|
||||
*lineptr = new_ptr;
|
||||
}
|
||||
|
||||
((unsigned char *)(*lineptr))[pos ++] = c;
|
||||
((unsigned char *)(*lineptr))[pos++] = c;
|
||||
if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
@ -75,30 +78,29 @@ String IO_read_MINUS_file(const String *filename) {
|
||||
long length;
|
||||
FILE *f = fopen(*filename, "rb");
|
||||
|
||||
if(f) {
|
||||
fseek (f, 0, SEEK_END);
|
||||
length = ftell (f);
|
||||
fseek (f, 0, SEEK_SET);
|
||||
buffer = CARP_MALLOC (length + 1);
|
||||
if (buffer) {
|
||||
fread (buffer, 1, length, f);
|
||||
if (f) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
length = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buffer = CARP_MALLOC(length + 1);
|
||||
if (buffer) {
|
||||
fread(buffer, 1, length, f);
|
||||
buffer[length] = '\0';
|
||||
} else {
|
||||
printf("Failed to open buffer from file: %s\n", *filename);
|
||||
buffer = String_empty();
|
||||
}
|
||||
fclose (f);
|
||||
fclose(f);
|
||||
} else {
|
||||
printf("Failed to open file: %s\n", *filename);
|
||||
buffer = String_empty();
|
||||
}
|
||||
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char IO_fgetc(FILE *f) {
|
||||
return (char) fgetc(f);
|
||||
return (char)fgetc(f);
|
||||
}
|
||||
|
||||
void IO_fclose(FILE *f) {
|
||||
|
@ -1,31 +1,70 @@
|
||||
#include <math.h>
|
||||
#include "carp_stdbool.h"
|
||||
|
||||
long Long__PLUS_(long x, long y) { return x + y; }
|
||||
long Long__MINUS_(long x, long y) { return x - y; }
|
||||
long Long__MUL_(long x, long y) { return x * y; }
|
||||
long Long__DIV_(long x, long y) { return x / y; }
|
||||
long Long__PLUS_(long x, long y) {
|
||||
return x + y;
|
||||
}
|
||||
long Long__MINUS_(long x, long y) {
|
||||
return x - y;
|
||||
}
|
||||
long Long__MUL_(long x, long y) {
|
||||
return x * y;
|
||||
}
|
||||
long Long__DIV_(long x, long y) {
|
||||
return x / y;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
bool Long_safe_MINUS_add(long x, long y, long* res) { return __builtin_saddl_overflow(x, y, res); }
|
||||
bool Long_safe_MINUS_sub(long x, long y, long* res) { return __builtin_ssubl_overflow(x, y, res); }
|
||||
bool Long_safe_MINUS_mul(long x, long y, long* res) { return __builtin_smull_overflow(x, y, res); }
|
||||
bool Long_safe_MINUS_add(long x, long y, long* res) {
|
||||
return __builtin_saddl_overflow(x, y, res);
|
||||
}
|
||||
bool Long_safe_MINUS_sub(long x, long y, long* res) {
|
||||
return __builtin_ssubl_overflow(x, y, res);
|
||||
}
|
||||
bool Long_safe_MINUS_mul(long x, long y, long* res) {
|
||||
return __builtin_smull_overflow(x, y, res);
|
||||
}
|
||||
#endif
|
||||
bool Long__EQ_(long x, long y) { return x == y; }
|
||||
bool Long__LT_(long x, long y) { return x < y; }
|
||||
bool Long__GT_(long x, long y) { return x > y; }
|
||||
long Long_neg(long x) { return -x; }
|
||||
bool Long__EQ_(long x, long y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Long__LT_(long x, long y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Long__GT_(long x, long y) {
|
||||
return x > y;
|
||||
}
|
||||
long Long_neg(long x) {
|
||||
return -x;
|
||||
}
|
||||
|
||||
long Long_inc(long x) { return x + 1; }
|
||||
long Long_dec(long x) { return x - 1; }
|
||||
long Long_abs(long x) { return x > 0 ? x : -x; }
|
||||
long Long_bit_MINUS_shift_MINUS_left(long x, long y) { return x << y; }
|
||||
long Long_bit_MINUS_shift_MINUS_right(long x, long y) { return x >> y; }
|
||||
long Long_bit_MINUS_and(long x, long y) { return x & y; }
|
||||
long Long_bit_MINUS_or(long x, long y) { return x | y; }
|
||||
long Long_bit_MINUS_xor(long x, long y) { return x ^ y; }
|
||||
long Long_bit_MINUS_not(long x) { return ~x; }
|
||||
long Long_inc(long x) {
|
||||
return x + 1;
|
||||
}
|
||||
long Long_dec(long x) {
|
||||
return x - 1;
|
||||
}
|
||||
long Long_abs(long x) {
|
||||
return x > 0 ? x : -x;
|
||||
}
|
||||
long Long_bit_MINUS_shift_MINUS_left(long x, long y) {
|
||||
return x << y;
|
||||
}
|
||||
long Long_bit_MINUS_shift_MINUS_right(long x, long y) {
|
||||
return x >> y;
|
||||
}
|
||||
long Long_bit_MINUS_and(long x, long y) {
|
||||
return x & y;
|
||||
}
|
||||
long Long_bit_MINUS_or(long x, long y) {
|
||||
return x | y;
|
||||
}
|
||||
long Long_bit_MINUS_xor(long x, long y) {
|
||||
return x ^ y;
|
||||
}
|
||||
long Long_bit_MINUS_not(long x) {
|
||||
return ~x;
|
||||
}
|
||||
|
||||
long Long_copy(const long *x) { return *x; }
|
||||
long Long_copy(const long* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
long Long_mod(long x, long divider) {
|
||||
return x % divider;
|
||||
@ -40,9 +79,9 @@ bool Long_mask(long a, long b) {
|
||||
}
|
||||
|
||||
int Long_to_MINUS_int(long a) {
|
||||
return (int) a;
|
||||
return (int)a;
|
||||
}
|
||||
|
||||
long Long_from_MINUS_int(int a) {
|
||||
return (long) a;
|
||||
return (long)a;
|
||||
}
|
||||
|
@ -1,17 +1,11 @@
|
||||
#pragma once
|
||||
#include "carp_stdbool.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef LOG_MEMORY
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
long malloc_balance_counter = 0;
|
||||
bool log_memory_balance = false;
|
||||
|
||||
void *logged_malloc(size_t size) {
|
||||
void *ptr = malloc(size);
|
||||
if(log_memory_balance) {
|
||||
if (log_memory_balance) {
|
||||
printf("MALLOC: %p (%ld bytes)\n", ptr, size);
|
||||
}
|
||||
malloc_balance_counter++;
|
||||
@ -19,13 +13,14 @@ void *logged_malloc(size_t size) {
|
||||
}
|
||||
|
||||
void logged_free(void *ptr) {
|
||||
if(log_memory_balance) {
|
||||
if (log_memory_balance) {
|
||||
printf("FREE: %p\n", ptr);
|
||||
}
|
||||
free(ptr);
|
||||
malloc_balance_counter--;
|
||||
/* if(malloc_balance_counter == 0) { */
|
||||
/* printf("malloc is balanced! (this should be the last thing you see)\n"); */
|
||||
/* printf("malloc is balanced! (this should be the last thing you
|
||||
* see)\n"); */
|
||||
/* } */
|
||||
/* else if(malloc_balance_counter < 0) { */
|
||||
/* printf("malloc is %ld, that is bad!\n", malloc_balance_counter); */
|
||||
@ -38,6 +33,7 @@ void Debug_log_MINUS_memory_MINUS_balance_BANG_(bool value) {
|
||||
|
||||
#define CARP_MALLOC(size) logged_malloc(size)
|
||||
#define CARP_FREE(ptr) logged_free(ptr)
|
||||
#define CARP_REALLOC(ptr, size) realloc(ptr, size)
|
||||
|
||||
long Debug_memory_MINUS_balance() {
|
||||
return malloc_balance_counter;
|
||||
@ -51,31 +47,41 @@ void Debug_reset_MINUS_memory_MINUS_balance_BANG_() {
|
||||
|
||||
#ifdef CHECK_ALLOCATIONS
|
||||
void* CARP_MALLOC(size_t size) {
|
||||
void* res = malloc(size);
|
||||
if (!res) abort();
|
||||
return res;
|
||||
void* res = malloc(size);
|
||||
if (!res) abort();
|
||||
return res;
|
||||
}
|
||||
void* CARP_REALLOC(void* ptr, size_t size) {
|
||||
void* res = realloc(ptr, size);
|
||||
if (!res) abort();
|
||||
return res;
|
||||
}
|
||||
#else
|
||||
#define CARP_MALLOC(size) malloc(size)
|
||||
#define CARP_REALLOC(ptr, size) realloc(ptr, size)
|
||||
#endif
|
||||
|
||||
#define CARP_FREE(ptr) free(ptr)
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
long Debug_memory_MINUS_balance() {
|
||||
printf("Error - calling 'memory-balance' without compiling with LOG_MEMORY enabled (--log-memory).\n");
|
||||
printf(
|
||||
"Error - calling 'memory-balance' without compiling with LOG_MEMORY "
|
||||
"enabled (--log-memory).\n");
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Debug_reset_MINUS_memory_MINUS_balance_BANG_() {
|
||||
printf("Error - calling 'reset-memory-balance!' without compiling with LOG_MEMORY enabled (--log-memory).\n");
|
||||
printf(
|
||||
"Error - calling 'reset-memory-balance!' without compiling with "
|
||||
"LOG_MEMORY enabled (--log-memory).\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Debug_log_MINUS_memory_MINUS_balance_BANG_(bool value) {
|
||||
printf("Error - calling 'log-memory-balance!' without compiling with LOG_MEMORY enabled (--log-memory).\n");
|
||||
printf(
|
||||
"Error - calling 'log-memory-balance!' without compiling with "
|
||||
"LOG_MEMORY enabled (--log-memory).\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
1091
core/carp_pattern.h
1091
core/carp_pattern.h
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,9 @@
|
||||
#include <math.h>
|
||||
#include "carp_stdbool.h"
|
||||
|
||||
bool Int_safe_MINUS_add(int x, int y, int* res) { return __builtin_sadd_overflow(x, y, res); }
|
||||
bool Int_safe_MINUS_sub(int x, int y, int* res) { return __builtin_ssub_overflow(x, y, res); }
|
||||
bool Int_safe_MINUS_mul(int x, int y, int* res) { return __builtin_smul_overflow(x, y, res); }
|
||||
bool Int_safe_MINUS_add(int x, int y, int* res) {
|
||||
return __builtin_sadd_overflow(x, y, res);
|
||||
}
|
||||
bool Int_safe_MINUS_sub(int x, int y, int* res) {
|
||||
return __builtin_ssub_overflow(x, y, res);
|
||||
}
|
||||
bool Int_safe_MINUS_mul(int x, int y, int* res) {
|
||||
return __builtin_smul_overflow(x, y, res);
|
||||
}
|
||||
|
544
core/carp_stdint.h
Normal file
544
core/carp_stdint.h
Normal file
@ -0,0 +1,544 @@
|
||||
typedef uint8_t Uint8;
|
||||
typedef uint16_t Uint16;
|
||||
typedef uint32_t Uint32;
|
||||
typedef uint64_t Uint64;
|
||||
typedef int8_t Int8;
|
||||
typedef int16_t Int16;
|
||||
typedef int32_t Int32;
|
||||
typedef int64_t Int64;
|
||||
|
||||
Uint8 Uint8__PLUS_(Uint8 x, Uint8 y) {
|
||||
return x + y;
|
||||
}
|
||||
Uint8 Uint8__MINUS_(Uint8 x, Uint8 y) {
|
||||
return x - y;
|
||||
}
|
||||
Uint8 Uint8__MUL_(Uint8 x, Uint8 y) {
|
||||
return x * y;
|
||||
}
|
||||
Uint8 Uint8__DIV_(Uint8 x, Uint8 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Uint8__EQ_(Uint8 x, Uint8 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Uint8__LT_(Uint8 x, Uint8 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Uint8__GT_(Uint8 x, Uint8 y) {
|
||||
return x > y;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_shift_MINUS_left(Uint8 x, Uint8 y) {
|
||||
return x << y;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_shift_MINUS_right(Uint8 x, Uint8 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_or(Uint8 x, Uint8 y) {
|
||||
return x | y;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_and(Uint8 x, Uint8 y) {
|
||||
return x & y;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_not(Uint8 x) {
|
||||
return ~x;
|
||||
}
|
||||
Uint8 Uint8_bit_MINUS_xor(Uint8 x, Uint8 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Uint8_str(Uint8 x) {
|
||||
int size = snprintf(NULL, 0, "Uint8(%" PRIu8 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Uint8(%" PRIu8 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Uint8 Uint8_from_MINUS_long(long x) {
|
||||
return (Uint8)x;
|
||||
}
|
||||
long Uint8_to_MINUS_long(Uint8 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Uint8 Uint8_copy(Uint8* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Uint8_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len;
|
||||
x.capacity = a->capacity;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Uint16 Uint16__PLUS_(Uint16 x, Uint16 y) {
|
||||
return x + y;
|
||||
}
|
||||
Uint16 Uint16__MINUS_(Uint16 x, Uint16 y) {
|
||||
return x - y;
|
||||
}
|
||||
Uint16 Uint16__MUL_(Uint16 x, Uint16 y) {
|
||||
return x * y;
|
||||
}
|
||||
Uint16 Uint16__DIV_(Uint16 x, Uint16 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Uint16__EQ_(Uint16 x, Uint16 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Uint16__LT_(Uint16 x, Uint16 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Uint16__GT_(Uint16 x, Uint16 y) {
|
||||
return x > y;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_shift_MINUS_left(Uint16 x, Uint16 y) {
|
||||
return x << y;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_shift_MINUS_right(Uint16 x, Uint16 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_or(Uint16 x, Uint16 y) {
|
||||
return x | y;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_and(Uint16 x, Uint16 y) {
|
||||
return x & y;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_not(Uint16 x) {
|
||||
return ~x;
|
||||
}
|
||||
Uint16 Uint16_bit_MINUS_xor(Uint16 x, Uint16 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Uint16_str(Uint16 x) {
|
||||
int size = snprintf(NULL, 0, "Uint16(%" PRIu16 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Uint16(%" PRIu16 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Uint16 Uint16_from_MINUS_long(long x) {
|
||||
return (Uint16)x;
|
||||
}
|
||||
long Uint16_to_MINUS_long(Uint16 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Uint16 Uint16_copy(Uint16* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Uint16_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len / 2;
|
||||
x.capacity = a->capacity / 2;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Uint32 Uint32__PLUS_(Uint32 x, Uint32 y) {
|
||||
return x + y;
|
||||
}
|
||||
Uint32 Uint32__MINUS_(Uint32 x, Uint32 y) {
|
||||
return x - y;
|
||||
}
|
||||
Uint32 Uint32__MUL_(Uint32 x, Uint32 y) {
|
||||
return x * y;
|
||||
}
|
||||
Uint32 Uint32__DIV_(Uint32 x, Uint32 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Uint32__EQ_(Uint32 x, Uint32 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Uint32__LT_(Uint32 x, Uint32 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Uint32__GT_(Uint32 x, Uint32 y) {
|
||||
return x > y;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_shift_MINUS_left(Uint32 x, Uint32 y) {
|
||||
return x << y;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_shift_MINUS_right(Uint32 x, Uint32 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_or(Uint32 x, Uint32 y) {
|
||||
return x | y;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_and(Uint32 x, Uint32 y) {
|
||||
return x & y;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_not(Uint32 x) {
|
||||
return ~x;
|
||||
}
|
||||
Uint32 Uint32_bit_MINUS_xor(Uint32 x, Uint32 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Uint32_str(Uint32 x) {
|
||||
int size = snprintf(NULL, 0, "Uint32(%" PRIu32 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Uint32(%" PRIu32 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Uint32 Uint32_from_MINUS_long(long x) {
|
||||
return (Uint32)x;
|
||||
}
|
||||
long Uint32_to_MINUS_long(Uint32 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Uint32 Uint32_copy(Uint32* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Uint32_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len / 4;
|
||||
x.capacity = a->capacity / 4;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Uint64 Uint64__PLUS_(Uint64 x, Uint64 y) {
|
||||
return x + y;
|
||||
}
|
||||
Uint64 Uint64__MINUS_(Uint64 x, Uint64 y) {
|
||||
return x - y;
|
||||
}
|
||||
Uint64 Uint64__MUL_(Uint64 x, Uint64 y) {
|
||||
return x * y;
|
||||
}
|
||||
Uint64 Uint64__DIV_(Uint64 x, Uint64 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Uint64__EQ_(Uint64 x, Uint64 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Uint64__LT_(Uint64 x, Uint64 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Uint64__GT_(Uint64 x, Uint64 y) {
|
||||
return x > y;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_shift_MINUS_left(Uint64 x, Uint64 y) {
|
||||
return x << y;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_shift_MINUS_right(Uint64 x, Uint64 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_or(Uint64 x, Uint64 y) {
|
||||
return x | y;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_and(Uint64 x, Uint64 y) {
|
||||
return x & y;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_not(Uint64 x) {
|
||||
return ~x;
|
||||
}
|
||||
Uint64 Uint64_bit_MINUS_xor(Uint64 x, Uint64 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Uint64_str(Uint64 x) {
|
||||
int size = snprintf(NULL, 0, "Uint64(%" PRIu64 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Uint64(%" PRIu64 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Uint64 Uint64_from_MINUS_long(long x) {
|
||||
return (Uint64)x;
|
||||
}
|
||||
long Uint64_to_MINUS_long(Uint64 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Uint64 Uint64_copy(Uint64* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Uint64_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len / 2;
|
||||
x.capacity = a->capacity / 2;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Int8 Int8__PLUS_(Int8 x, Int8 y) {
|
||||
return x + y;
|
||||
}
|
||||
Int8 Int8__MINUS_(Int8 x, Int8 y) {
|
||||
return x - y;
|
||||
}
|
||||
Int8 Int8__MUL_(Int8 x, Int8 y) {
|
||||
return x * y;
|
||||
}
|
||||
Int8 Int8__DIV_(Int8 x, Int8 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int8__EQ_(Int8 x, Int8 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int8__LT_(Int8 x, Int8 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int8__GT_(Int8 x, Int8 y) {
|
||||
return x > y;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_shift_MINUS_left(Int8 x, Int8 y) {
|
||||
return x << y;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_shift_MINUS_right(Int8 x, Int8 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_or(Int8 x, Int8 y) {
|
||||
return x | y;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_and(Int8 x, Int8 y) {
|
||||
return x & y;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_not(Int8 x) {
|
||||
return ~x;
|
||||
}
|
||||
Int8 Int8_bit_MINUS_xor(Int8 x, Int8 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Int8_str(Int8 x) {
|
||||
int size = snprintf(NULL, 0, "Int8(%" PRId8 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Int8(%" PRId8 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Int8 Int8_from_MINUS_long(long x) {
|
||||
return (Int8)x;
|
||||
}
|
||||
long Int8_to_MINUS_long(Int8 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Int8 Int8_copy(Int8* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Int8_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
int8_t* d = (int8_t*)a->data;
|
||||
x.len = a->len;
|
||||
x.capacity = a->capacity;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Int16 Int16__PLUS_(Int16 x, Int16 y) {
|
||||
return x + y;
|
||||
}
|
||||
Int16 Int16__MINUS_(Int16 x, Int16 y) {
|
||||
return x - y;
|
||||
}
|
||||
Int16 Int16__MUL_(Int16 x, Int16 y) {
|
||||
return x * y;
|
||||
}
|
||||
Int16 Int16__DIV_(Int16 x, Int16 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int16__EQ_(Int16 x, Int16 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int16__LT_(Int16 x, Int16 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int16__GT_(Int16 x, Int16 y) {
|
||||
return x > y;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_shift_MINUS_left(Int16 x, Int16 y) {
|
||||
return x << y;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_shift_MINUS_right(Int16 x, Int16 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_or(Int16 x, Int16 y) {
|
||||
return x | y;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_and(Int16 x, Int16 y) {
|
||||
return x & y;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_not(Int16 x) {
|
||||
return ~x;
|
||||
}
|
||||
Int16 Int16_bit_MINUS_xor(Int16 x, Int16 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Int16_str(Int16 x) {
|
||||
int size = snprintf(NULL, 0, "Int16(%" PRId16 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Int16(%" PRId16 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Int16 Int16_from_MINUS_long(long x) {
|
||||
return (Int16)x;
|
||||
}
|
||||
long Int16_to_MINUS_long(Int16 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Int16 Int16_copy(Int16* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Int16_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len;
|
||||
x.capacity = a->capacity;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Int32 Int32__PLUS_(Int32 x, Int32 y) {
|
||||
return x + y;
|
||||
}
|
||||
Int32 Int32__MINUS_(Int32 x, Int32 y) {
|
||||
return x - y;
|
||||
}
|
||||
Int32 Int32__MUL_(Int32 x, Int32 y) {
|
||||
return x * y;
|
||||
}
|
||||
Int32 Int32__DIV_(Int32 x, Int32 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int32__EQ_(Int32 x, Int32 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int32__LT_(Int32 x, Int32 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int32__GT_(Int32 x, Int32 y) {
|
||||
return x > y;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_shift_MINUS_left(Int32 x, Int32 y) {
|
||||
return x << y;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_shift_MINUS_right(Int32 x, Int32 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_or(Int32 x, Int32 y) {
|
||||
return x | y;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_and(Int32 x, Int32 y) {
|
||||
return x & y;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_not(Int32 x) {
|
||||
return ~x;
|
||||
}
|
||||
Int32 Int32_bit_MINUS_xor(Int32 x, Int32 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Int32_str(Int32 x) {
|
||||
int size = snprintf(NULL, 0, "Int32(%" PRId32 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Int32(%" PRId32 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Int32 Int32_from_MINUS_long(long x) {
|
||||
return (Int32)x;
|
||||
}
|
||||
long Int32_to_MINUS_long(Int32 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Int32 Int32_copy(Int32* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Int32_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len / 4;
|
||||
x.capacity = a->capacity / 4;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
Int64 Int64__PLUS_(Int64 x, Int64 y) {
|
||||
return x + y;
|
||||
}
|
||||
Int64 Int64__MINUS_(Int64 x, Int64 y) {
|
||||
return x - y;
|
||||
}
|
||||
Int64 Int64__MUL_(Int64 x, Int64 y) {
|
||||
return x * y;
|
||||
}
|
||||
Int64 Int64__DIV_(Int64 x, Int64 y) {
|
||||
return x / y;
|
||||
}
|
||||
bool Int64__EQ_(Int64 x, Int64 y) {
|
||||
return x == y;
|
||||
}
|
||||
bool Int64__LT_(Int64 x, Int64 y) {
|
||||
return x < y;
|
||||
}
|
||||
bool Int64__GT_(Int64 x, Int64 y) {
|
||||
return x > y;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_shift_MINUS_left(Int64 x, Int64 y) {
|
||||
return x << y;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_shift_MINUS_right(Int64 x, Int64 y) {
|
||||
return x >> y;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_or(Int64 x, Int64 y) {
|
||||
return x | y;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_and(Int64 x, Int64 y) {
|
||||
return x & y;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_not(Int64 x) {
|
||||
return ~x;
|
||||
}
|
||||
Int64 Int64_bit_MINUS_xor(Int64 x, Int64 y) {
|
||||
return x ^ y;
|
||||
}
|
||||
String Int64_str(Int64 x) {
|
||||
int size = snprintf(NULL, 0, "Int64(%" PRId64 ")", x) + 1;
|
||||
char* buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "Int64(%" PRId64 ")", x);
|
||||
return buffer;
|
||||
}
|
||||
Int64 Int64_from_MINUS_long(long x) {
|
||||
return (Int64)x;
|
||||
}
|
||||
long Int64_to_MINUS_long(Int64 x) {
|
||||
return (long)x;
|
||||
}
|
||||
Int64 Int64_copy(Int64* x) {
|
||||
return *x;
|
||||
}
|
||||
|
||||
Array Int64_from_MINUS_bytes(Array* a) {
|
||||
int i;
|
||||
Array x;
|
||||
uint8_t* d = (uint8_t*)a->data;
|
||||
x.len = a->len / 2;
|
||||
x.capacity = a->capacity / 2;
|
||||
x.data = malloc(x.len);
|
||||
memcpy(x.data, a->data, x.len);
|
||||
|
||||
return x;
|
||||
}
|
@ -1,9 +1,3 @@
|
||||
#pragma once
|
||||
#include <string.h>
|
||||
|
||||
#include <carp_memory.h>
|
||||
#include <core.h>
|
||||
|
||||
String String_allocate(int len, char byte) {
|
||||
/* Allocate a string of length 'len + 1'
|
||||
* setting the first len bytes to byte
|
||||
@ -11,7 +5,7 @@ String String_allocate(int len, char byte) {
|
||||
*
|
||||
* String_alloc(10, "a") == "aaaaaaaaaa"
|
||||
*/
|
||||
String ptr = CARP_MALLOC(len+1);
|
||||
String ptr = CARP_MALLOC(len + 1);
|
||||
memset(ptr, byte, len);
|
||||
ptr[len] = '\0';
|
||||
return ptr;
|
||||
@ -22,21 +16,15 @@ void String_delete(String s) {
|
||||
}
|
||||
|
||||
void String_string_MINUS_set_BANG_(String *s, int i, char ch) {
|
||||
int l = strlen(*s);
|
||||
(void)l;
|
||||
assert(i >= 0);
|
||||
assert(i < l);
|
||||
CHK_INDEX(i, strlen(*s));
|
||||
(*s)[i] = ch;
|
||||
}
|
||||
|
||||
void String_string_MINUS_set_MINUS_at_BANG_(String *into, int i, const String *src) {
|
||||
void String_string_MINUS_set_MINUS_at_BANG_(String *into, int i,
|
||||
const String *src) {
|
||||
char *dest = (*into) + i;
|
||||
int lsrc = strlen(*src);
|
||||
|
||||
int linto = strlen(*into);
|
||||
(void)linto;
|
||||
assert(i >= 0);
|
||||
/* given a string and indicies
|
||||
/* given a string and indices
|
||||
*
|
||||
* 0 1 2 3 4 5 6 7 8 9
|
||||
* "a b c d e f g h i j"
|
||||
@ -46,7 +34,7 @@ void String_string_MINUS_set_MINUS_at_BANG_(String *into, int i, const String *s
|
||||
*
|
||||
* 0 1 2 3
|
||||
* "w x y z"
|
||||
* ldest = strlen(...) = 4
|
||||
* lsrc = strlen(...) = 4
|
||||
*
|
||||
* we need to make sure that the new string will not grow the first
|
||||
*
|
||||
@ -58,23 +46,21 @@ void String_string_MINUS_set_MINUS_at_BANG_(String *into, int i, const String *s
|
||||
* "w x y z"
|
||||
*
|
||||
* we check this by
|
||||
* (i + ldest - 1) < linto
|
||||
* (6 + 4 - 1) < 10
|
||||
* (10 - 1) < 10
|
||||
* 9 < 10
|
||||
* (i + lsrc) < (linto + 1)
|
||||
* (6 + 4) < (10 + 1)
|
||||
* 10 < 11
|
||||
* true
|
||||
*
|
||||
* so this write is safe
|
||||
*/
|
||||
assert((i+lsrc-1) < linto);
|
||||
|
||||
strncpy(dest, *src, lsrc);
|
||||
CHK_INDEX(i + lsrc, strlen(*into) + 1);
|
||||
memcpy(dest, *src, lsrc);
|
||||
}
|
||||
|
||||
String String_copy(const String *s) {
|
||||
size_t len = strlen(*s) + 1;
|
||||
String ptr = CARP_MALLOC(len);
|
||||
return (String) memcpy(ptr, *s, len);
|
||||
return (String)memcpy(ptr, *s, len);
|
||||
}
|
||||
|
||||
bool String__EQ_(const String *a, const String *b) {
|
||||
@ -94,7 +80,9 @@ String String_append(const String *a, const String *b) {
|
||||
int lb = strlen(*b);
|
||||
int total = la + lb + 1;
|
||||
String buffer = CARP_MALLOC(total);
|
||||
snprintf(buffer, total, "%s%s", *a, *b);
|
||||
memcpy(buffer, *a, la);
|
||||
memcpy(buffer + la, *b, lb);
|
||||
buffer[la + lb] = '\0';
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -102,10 +90,14 @@ int String_length(const String *s) {
|
||||
return strlen(*s);
|
||||
}
|
||||
|
||||
char* String_cstr(const String *s) {
|
||||
char *String_cstr(const String *s) {
|
||||
return *s;
|
||||
}
|
||||
|
||||
String String_from_MINUS_cstr(char *s) {
|
||||
return String_copy(&s);
|
||||
}
|
||||
|
||||
String String_str(const String *s) {
|
||||
return String_copy(s);
|
||||
}
|
||||
@ -113,18 +105,18 @@ String String_str(const String *s) {
|
||||
String String_prn(const String *s) {
|
||||
int n = strlen(*s) + 4;
|
||||
String buffer = CARP_MALLOC(n);
|
||||
snprintf(buffer, n, "@\"%s\"", *s);
|
||||
sprintf(buffer, "@\"%s\"", *s);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
char String_char_MINUS_at(const String* s, int i) {
|
||||
return (*s)[i];
|
||||
char String_char_MINUS_at(const String *s, int i) {
|
||||
return (*s)[i];
|
||||
}
|
||||
|
||||
String String_format(const String *str, const String *s) {
|
||||
int size = snprintf(NULL, 0, *str, *s)+1;
|
||||
int size = snprintf(NULL, 0, *str, *s) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, *s);
|
||||
sprintf(buffer, *str, *s);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -137,17 +129,17 @@ Array String_chars(const String *s) {
|
||||
}
|
||||
|
||||
String String_from_MINUS_chars(const Array *a) {
|
||||
String s = CARP_MALLOC(a->len+1);
|
||||
String s = CARP_MALLOC(a->len + 1);
|
||||
memcpy(s, a->data, a->len);
|
||||
s[a->len] = '\0';
|
||||
return s;
|
||||
}
|
||||
|
||||
String String_tail(const String* s) {
|
||||
String String_tail(const String *s) {
|
||||
int len = strlen(*s);
|
||||
String news = CARP_MALLOC(len);
|
||||
memcpy(news, (*s)+1, len-1);
|
||||
news[len-1] = '\0';
|
||||
memcpy(news, (*s) + 1, len - 1);
|
||||
news[len - 1] = '\0';
|
||||
return news;
|
||||
}
|
||||
|
||||
@ -160,78 +152,86 @@ String String_empty() {
|
||||
String Bool_str(bool b) {
|
||||
const String true_str = "true";
|
||||
const String false_str = "false";
|
||||
if(b) {
|
||||
if (b) {
|
||||
return String_copy(&true_str);
|
||||
} else {
|
||||
return String_copy(&false_str);
|
||||
}
|
||||
}
|
||||
|
||||
String Bool_format(const String* str, bool b) {
|
||||
int size = snprintf(NULL, 0, *str, b)+1;
|
||||
String Bool_format(const String *str, bool b) {
|
||||
int size = snprintf(NULL, 0, *str, b) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, b);
|
||||
sprintf(buffer, *str, b);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Char_str(char c) {
|
||||
String buffer = CARP_MALLOC(2);
|
||||
snprintf(buffer, 2, "%c", c);
|
||||
sprintf(buffer, "%c", c);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Char_prn(char c) {
|
||||
String buffer = CARP_MALLOC(3);
|
||||
snprintf(buffer, 3, "\\%c", c);
|
||||
sprintf(buffer, "\\%c", c);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Char_format(const String* str, char b) {
|
||||
int size = snprintf(NULL, 0, *str, b)+1;
|
||||
String Char_format(const String *str, char b) {
|
||||
int size = snprintf(NULL, 0, *str, b) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, b);
|
||||
sprintf(buffer, *str, b);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Double_str(double x) {
|
||||
int size = snprintf(NULL, 0, "%g", x)+1;
|
||||
int size = snprintf(NULL, 0, "%g", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "%g", x);
|
||||
sprintf(buffer, "%g", x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Double_format(const String* s, double x) {
|
||||
int size = snprintf(NULL, 0, *s, x)+1;
|
||||
String Double_format(const String *s, double x) {
|
||||
int size = snprintf(NULL, 0, *s, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *s, x);
|
||||
sprintf(buffer, *s, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
double Double_from_MINUS_string(const String *s) {
|
||||
return strtod(*s, NULL);
|
||||
}
|
||||
|
||||
String Float_str(float x) {
|
||||
int size = snprintf(NULL, 0, "%gf", x)+1;
|
||||
int size = snprintf(NULL, 0, "%gf", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "%gf", x);
|
||||
sprintf(buffer, "%gf", x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Float_format(const String* str, float x) {
|
||||
int size = snprintf(NULL, 0, *str, x)+1;
|
||||
String Float_format(const String *str, float x) {
|
||||
int size = snprintf(NULL, 0, *str, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, x);
|
||||
sprintf(buffer, *str, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
float Float_from_MINUS_string(const String *s) {
|
||||
return strtof(*s, NULL);
|
||||
}
|
||||
|
||||
String Int_str(int x) {
|
||||
int size = snprintf(NULL, 0, "%d", x)+1;
|
||||
int size = snprintf(NULL, 0, "%d", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "%d", x);
|
||||
sprintf(buffer, "%d", x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Int_format(const String* str, int x) {
|
||||
int size = snprintf(NULL, 0, *str, x)+1;
|
||||
String Int_format(const String *str, int x) {
|
||||
int size = snprintf(NULL, 0, *str, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, x);
|
||||
sprintf(buffer, *str, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -240,16 +240,16 @@ int Int_from_MINUS_string(const String *s) {
|
||||
}
|
||||
|
||||
String Long_str(long x) {
|
||||
int size = snprintf(NULL, 0, "%ldl", x)+1;
|
||||
int size = snprintf(NULL, 0, "%ldl", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, "%ldl", x);
|
||||
sprintf(buffer, "%ldl", x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Long_format(const String* str, long x) {
|
||||
int size = snprintf(NULL, 0, *str, x)+1;
|
||||
String Long_format(const String *str, long x) {
|
||||
int size = snprintf(NULL, 0, *str, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
snprintf(buffer, size, *str, x);
|
||||
sprintf(buffer, *str, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -257,16 +257,34 @@ long Long_from_MINUS_string(const String *s) {
|
||||
return atol(*s);
|
||||
}
|
||||
|
||||
String Byte_str(uint8_t x) {
|
||||
int size = snprintf(NULL, 0, "%ub", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
sprintf(buffer, "%ub", x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
String Byte_format(const String *str, uint8_t x) {
|
||||
int size = snprintf(NULL, 0, *str, x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
sprintf(buffer, *str, x);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
uint8_t Byte_from_MINUS_string(const String *s) {
|
||||
return atoi(*s);
|
||||
}
|
||||
|
||||
int String_index_MINUS_of_MINUS_from(const String *s, char c, int i) {
|
||||
/* Return index of first occurrence of `c` in `s` AFTER index i
|
||||
* Returns -1 if not found
|
||||
*/
|
||||
++i; // skip first character as we want AFTER i
|
||||
++i; // skip first character as we want AFTER i
|
||||
int len = strlen(*s);
|
||||
for (; i<len; ++i) {
|
||||
if (c == (*s)[i]) {
|
||||
return i;
|
||||
}
|
||||
for (; i < len; ++i) {
|
||||
if (c == (*s)[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,11 +1,3 @@
|
||||
#include <time.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <carp_memory.h>
|
||||
#include <carp_string.h>
|
||||
|
||||
void System_free(void *p) {
|
||||
CARP_FREE(p);
|
||||
@ -37,9 +29,9 @@ void System_sleep_MINUS_micros(int t) {
|
||||
}
|
||||
|
||||
double System_nanotime() {
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
struct timespec tv;
|
||||
clock_gettime(CLOCK_REALTIME, &tv);
|
||||
return 1000000000 * tv.tv_sec + tv.tv_nsec;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -49,9 +41,9 @@ void System_system(const String *command) {
|
||||
|
||||
Array System_args;
|
||||
|
||||
String* System_get_MINUS_arg(int idx) {
|
||||
String *System_get_MINUS_arg(int idx) {
|
||||
assert(idx < System_args.len);
|
||||
return &(((String*)System_args.data)[idx]);
|
||||
return &(((String *)System_args.data)[idx]);
|
||||
}
|
||||
|
||||
int System_get_MINUS_args_MINUS_len() {
|
||||
|
53
core/core.h
53
core/core.h
@ -1,15 +1,39 @@
|
||||
#ifndef PRELUDE_H
|
||||
#define PRELUDE_H
|
||||
|
||||
#include <assert.h>
|
||||
#include "carp_stdbool.h"
|
||||
#include <stddef.h>
|
||||
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#if defined(WIN32) || defined(_WIN32) || \
|
||||
defined(__WIN32) && !defined(__CYGWIN__)
|
||||
#include <BaseTsd.h>
|
||||
#include <windows.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#endif
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
typedef char* String;
|
||||
typedef char* Pattern;
|
||||
typedef char *String;
|
||||
typedef char *Pattern;
|
||||
|
||||
#if defined NDEBUG
|
||||
#define CHK_INDEX(i, n)
|
||||
#else
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32) || \
|
||||
defined(__WIN32) && !defined(__CYGWIN__)
|
||||
// The %zd format flag doesn't seem to work on Windows?
|
||||
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %ld < %ld\n"
|
||||
#else
|
||||
#define CHK_INDEX_FORMAT_STRING ":%u: bad index: %zd < %zd\n"
|
||||
#endif
|
||||
|
||||
#define CHK_INDEX(i, n) \
|
||||
do { \
|
||||
size_t __si = (size_t)i; \
|
||||
size_t __ni = (size_t)n; \
|
||||
if (!(__si < __ni)) { \
|
||||
printf(__FILE__ CHK_INDEX_FORMAT_STRING, __LINE__, (ssize_t)i, \
|
||||
(ssize_t)n); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
// Array
|
||||
typedef struct {
|
||||
@ -26,13 +50,4 @@ typedef struct {
|
||||
void *copy;
|
||||
} Lambda;
|
||||
|
||||
typedef void* LambdaEnv;
|
||||
|
||||
bool not(bool b) {
|
||||
return !b;
|
||||
}
|
||||
|
||||
bool and(bool x, bool y) { return x && y; }
|
||||
bool or(bool x, bool y) { return x || y; }
|
||||
|
||||
#endif
|
||||
typedef void *LambdaEnv;
|
||||
|
59
default.nix
Normal file
59
default.nix
Normal file
@ -0,0 +1,59 @@
|
||||
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
|
||||
|
||||
let
|
||||
|
||||
inherit (nixpkgs) pkgs;
|
||||
|
||||
f = { mkDerivation, ansi-terminal, base, blaze-html, blaze-markup
|
||||
, cmark, cmdargs, containers, directory, edit-distance, filepath
|
||||
, haskeline, HUnit, mtl, parsec, process, split, stdenv, text
|
||||
|
||||
, darwin, glfw3, SDL2, SDL2_image, SDL2_gfx, SDL2_mixer, SDL2_ttf
|
||||
}:
|
||||
mkDerivation {
|
||||
pname = "CarpHask";
|
||||
version = "0.3.0.0";
|
||||
src = ./.;
|
||||
isLibrary = false;
|
||||
isExecutable = true;
|
||||
enableSharedLibraries = false;
|
||||
enableSharedExecutables = false;
|
||||
enableLibraryProfiling = false;
|
||||
enableExecutableProfiling = false;
|
||||
libraryHaskellDepends = [
|
||||
ansi-terminal base blaze-html blaze-markup cmark containers
|
||||
directory edit-distance filepath haskeline mtl parsec process split
|
||||
text
|
||||
];
|
||||
pkgconfigDepends = [ glfw3 SDL2 SDL2_image SDL2_gfx SDL2_mixer SDL2_ttf ];
|
||||
executableHaskellDepends = [
|
||||
base cmdargs containers directory haskeline parsec process
|
||||
];
|
||||
executableFrameworkDepends = with darwin.apple_sdk.frameworks; [
|
||||
Carbon Cocoa IOKit CoreFoundation CoreVideo IOKit ForceFeedback
|
||||
];
|
||||
testHaskellDepends = [ base containers HUnit ];
|
||||
testTarget = "CarpHask-test";
|
||||
postCheck = ''
|
||||
env CARP=dist/build/carp/carp ./run_carp_tests.sh
|
||||
'';
|
||||
enableParallelBuilding = true;
|
||||
homepage = "https://github.com/eriksvedang/Carp";
|
||||
license = stdenv.lib.licenses.asl20;
|
||||
};
|
||||
|
||||
haskellPackages = if compiler == "default"
|
||||
then pkgs.haskellPackages
|
||||
else pkgs.haskell.packages.${compiler};
|
||||
|
||||
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
|
||||
|
||||
drv = variant (haskellPackages.callPackage f {});
|
||||
|
||||
in
|
||||
|
||||
if pkgs.lib.inNixShell
|
||||
then drv.env.overrideAttrs (o: {
|
||||
buildInputs = o.buildInputs ++ [ haskellPackages.cabal-install ];
|
||||
})
|
||||
else drv
|
171
docs/DynamicSemantics.md
Normal file
171
docs/DynamicSemantics.md
Normal file
@ -0,0 +1,171 @@
|
||||
# Dynamic Semantics
|
||||
|
||||
This document will help us rewrite Carp's dynamic evaluator (defined in Eval.hs) to make it behave in a more principled and non-surprising way.
|
||||
|
||||
## Goals of the rewrite
|
||||
* Fix the various bugs related to dynamic evaluation that has been found (see "Relevant issues" below).
|
||||
* Add missing features that are to be expected in a dynamic Lisp (see below).
|
||||
* Make it easy to extend the dynamic evaluator with new features in the future.
|
||||
|
||||
## Relevant issues
|
||||
* https://github.com/carp-lang/Carp/issues/560
|
||||
* https://github.com/carp-lang/Carp/issues/555
|
||||
* https://github.com/carp-lang/Carp/issues/545
|
||||
* https://github.com/carp-lang/Carp/issues/476
|
||||
* https://github.com/carp-lang/Carp/issues/556
|
||||
* https://github.com/carp-lang/Carp/issues/659
|
||||
* https://github.com/carp-lang/Carp/issues/660
|
||||
* https://github.com/carp-lang/Carp/issues/453
|
||||
|
||||
## Desired features (currently missing)
|
||||
* Documentation on how to use the dynamic language and the macro system
|
||||
* Complete macro facilities (quasiquoting, splicing, complete error reporting, etc)
|
||||
* Dynamic stack traces
|
||||
* Auto completion of user-defined names
|
||||
|
||||
<hr>
|
||||
|
||||
# Semantics
|
||||
|
||||
## Index
|
||||
[TODO]
|
||||
|
||||
## 0. Terms used in this document
|
||||
* form : Any valid Carp data struture as represented in text.
|
||||
* top level : Any form that isn't embedded in another form.
|
||||
* Static Carp : The compiled version of the Carp langauge
|
||||
* Dynamic Carp : The interpreted, functional, GC'ed version of the Carp langauge
|
||||
|
||||
## 1. Scoping Rules
|
||||
Related issues:
|
||||
* https://github.com/carp-lang/Carp/issues/659
|
||||
|
||||
Questions:
|
||||
#### How does Carp figure out what the value of the symbol X is?
|
||||
Lexical scoping (look in the current scope, then any enclosing scope, up until global scope).
|
||||
Things that create scopes:
|
||||
- function definitions (defn, defndynamic, fn)
|
||||
- let
|
||||
- modules
|
||||
|
||||
#### How do you set the value for symbol X?
|
||||
|
||||
`(set! <symbol> <value>)`
|
||||
|
||||
#### Are there any reserved names?
|
||||
Yes (see the Parsing module for more info)
|
||||
|
||||
- defn
|
||||
- def
|
||||
- do
|
||||
- while
|
||||
- fn
|
||||
- let
|
||||
- break
|
||||
- if
|
||||
- match
|
||||
- true
|
||||
- false
|
||||
- address
|
||||
- set!
|
||||
- the
|
||||
- ref
|
||||
- deref
|
||||
- with
|
||||
|
||||
More things should be moved to the reserved list, actually.
|
||||
The `:rest` token in defmacro is also reserved.
|
||||
|
||||
#### What is a keyword?
|
||||
There are no keywords. Maybe will be in the macros, see this implementation https://gist.github.com/sdilts/73a811a633bb0ef3dd7e31b84a138a5a.
|
||||
|
||||
#### Are there different namespaces for dynamic and static Carp?
|
||||
They use the same modules but dynamic lookup will only find dynamic functions, and static lookup will only find static functions.
|
||||
|
||||
### 1.1 Global Variables
|
||||
Questions:
|
||||
#### Are global variables mutable?
|
||||
Yes.
|
||||
|
||||
#### How are they mutated? When do these mutations come into affect?
|
||||
Using `set!`. The mutation comes into effect immedately (using IORefs internally).
|
||||
|
||||
#### Do global variables have lexical or dynamic scope?
|
||||
Lexical (no dynamic scope for anything).
|
||||
|
||||
### 1.2 Local variables
|
||||
Questions:
|
||||
#### Are local variables mutable?
|
||||
Yup.
|
||||
|
||||
#### When do local variables come in and out of scope?
|
||||
Lexical scoping rules, functions and let create new variables.
|
||||
|
||||
#### What is a closure? What are the important rules for variables inside closures?
|
||||
No captured variables are mutable.
|
||||
The dynamic lambdas captures the whole environment at the time the closure is created (when the `(fn ...)` form is evaluated).
|
||||
|
||||
### 1.3. Namespace Rules
|
||||
Questions:
|
||||
#### Given symbols `a` in the `Foo` module and `a` in the `Bar` module, how do I refer to each of them?
|
||||
Using `.`, Foo.a and Bar.a.
|
||||
By using `(use <module name>)` you can avoid having to specify the module.
|
||||
|
||||
#### What happens if multiple modules are imported and they contain the same symbol?
|
||||
Runtime error when looking up the symbol.
|
||||
|
||||
#### Given the symbols`Foo.a` and `Bar.a`, exist, which symbol does `a` refer to?
|
||||
Neither, unless any single one of the modules (Foo/Bar) is imported with `use`. If both are imported the lookup is an error since it can't be resolved to a single value.
|
||||
|
||||
#### Do functions and variables live in the same namespace?
|
||||
Yes. Types live in a different namespace.
|
||||
|
||||
### 1.4 Definitions
|
||||
Questions:
|
||||
#### What kinds of definitions are there and how are they created?
|
||||
|
||||
Dynamic context:
|
||||
- defndynamic (creates dynamic functions)
|
||||
- defdynamic (creates dynamic global variables)
|
||||
- defmacro (creates macros)
|
||||
|
||||
Static context:
|
||||
- defn (creates static functions)
|
||||
- def (creates static global variables)
|
||||
- deftype (for defining product- and sumtypes)
|
||||
- register (for making external functions available)
|
||||
|
||||
All contexts:
|
||||
- defmodule
|
||||
|
||||
## 2. Evaluation Rules
|
||||
Related issues:
|
||||
* https://github.com/carp-lang/Carp/issues/555
|
||||
|
||||
Questions:
|
||||
#### When are macros evaluated?
|
||||
#### When are symbols evaluated?
|
||||
#### When are forms evaluated?
|
||||
#### Are forms evaluated left-to-right or right-to-left?
|
||||
#### How does error reporting work?
|
||||
|
||||
### 2.1 Macros
|
||||
Questions:
|
||||
* What is a macro?
|
||||
* What functions are available at macro-expansion time?
|
||||
* What is quasi-quoting and what is its syntax?
|
||||
* What is splicing, and what is its syntax?
|
||||
|
||||
### 2.2 REPL
|
||||
Questions:
|
||||
* How does the REPL know when to evalutate something in the dynamic or static context?
|
||||
* When does it decide to run the given code in the dynamic or static context?
|
||||
|
||||
## 3. Types
|
||||
Issues:
|
||||
* [#560 Add Reflection Module Proposal](https://github.com/carp-lang/Carp/issues/560)
|
||||
|
||||
Questions:
|
||||
* What types are available?
|
||||
* When is a form typechecked?
|
||||
* How do you refer to a specific type? Are types [first class citizens](https://en.wikipedia.org/wiki/First-class_citizen)?
|
@ -3,7 +3,7 @@
|
||||
### Introduction
|
||||
|
||||
Carp borrows its looks from Clojure but the runtime semantics are much closer to those of ML or Rust.
|
||||
Types are inferred but can be annoted for readability using the ```the``` keyword (see below).
|
||||
Types are inferred but can be annotated for readability using the ```the``` keyword (see below).
|
||||
|
||||
Memory management is handled by static analysis, a value is owned by the function where it was created.
|
||||
When a value is returned or passed to another function the initial function will give up ownership of it
|
||||
@ -25,7 +25,7 @@ To learn more about the details of memory management, check out [Memory.md](http
|
||||
10.0 ;; Double
|
||||
true ;; Bool
|
||||
"hello" ;; &String
|
||||
\#"hello" ;; &Pattern
|
||||
#"hello" ;; &Pattern
|
||||
\e ;; Char
|
||||
[1 2 3] ;; (Array Int)
|
||||
{1 1.0 2 2.0} ;; (Map Int Double)
|
||||
@ -61,6 +61,7 @@ foo ; symbol
|
||||
(definterface interface-name (Fn [<t1> <t2>] <return>)) ;; Define a generic function that can have multiple implementations
|
||||
(def variable-name value) ;; Define a global variable (only handles primitive constants for the moment)
|
||||
(defmacro <name> [<arg1> <arg2> ...] <macro-body>) ;; Define a macro, its argument will not be evaluated when called
|
||||
(defdynamic <name> <value>) ;; A variable that can only be used at the REPL or during compilation
|
||||
(defndynamic <name> [<arg1> <arg2> ...] <function-body>) ;; A function that can only be used at the REPL or during compilation
|
||||
(defmodule <name> <definition1> <definition2> ...) ;; The main way to organize your program into smaller parts
|
||||
```
|
||||
@ -75,6 +76,9 @@ and other static analysis. The first three of them are also available in dynamic
|
||||
(do <expr1> <expr2> ... <return-expression>) ;; Perform side-effecting functions, then return a value
|
||||
(if <expression> <true-branch> <false-branch>) ;; Branching
|
||||
(while <expression> <body>) ;; Loop until expression is false
|
||||
(use <module>) ;; Brings all symbols inside <module> into the scope
|
||||
(with <module> <expr1> <expr2> ...) ;; Locally scoped `use` statement where all expressions after it will look up symbols in the <module>
|
||||
(match <expression> <case1> <expr1> <case2> <expr2> ...) ;; Pattern matches <expression> against a set of sumtype constructors
|
||||
(ref <expression>) ;; Borrow an owned value
|
||||
(address <expression>) ;; Takes the memory address of a value, returns a C-style pointer
|
||||
(set! <variable> <expression>) ;; Mutate a variable
|
||||
@ -167,6 +171,42 @@ Specifying the type solves this error:
|
||||
(String.length x))
|
||||
```
|
||||
|
||||
When you `use` a module, its declarations are brought into the current scope. If you `use` a module in the global scope, all of its declarations are brought into global scope after the call to `use`. Similarly, if you `use` a module in another module's scope, its declarations can be reffered to without qualifiers within the scope of the module:
|
||||
|
||||
```clojure
|
||||
(use String)
|
||||
|
||||
;; Only the `String` module is used in the global scope,
|
||||
;; so we can refer to `length` without a module qualifier.
|
||||
(defn f [x]
|
||||
(length x))
|
||||
|
||||
(defmodule Foo
|
||||
(use Array)
|
||||
;; Since the the `String` module is used in the global scope,
|
||||
;; and the Foo module `use`s `Array`, we again need to qualify calls to `length`
|
||||
;; to disambiguite which declaration we're referring to.
|
||||
(defn g [xs]
|
||||
(Array.length xs)))
|
||||
```
|
||||
|
||||
Sometimes, it's more convenient to bring a module's declarations into scope only for a limited number of forms. You can do this using the `with` form:
|
||||
|
||||
```clojure
|
||||
(defmodule Foo
|
||||
;; we need to use a module qualifier here,
|
||||
;; since there's no call to `use` in the `Foo` module scope.
|
||||
(defn f [x]
|
||||
(String.length x))
|
||||
|
||||
;; Using the `with` form, we can reference the module's declarations
|
||||
;; unqualified in all the forms contained in the `with`'s scope.
|
||||
(with String
|
||||
(defn g [x]
|
||||
(length x)))
|
||||
)
|
||||
```
|
||||
|
||||
### Structs
|
||||
```clojure
|
||||
(deftype Vector2 [x Int, y Int])
|
||||
@ -181,10 +221,59 @@ Specifying the type solves this error:
|
||||
(Vector2.update-x my-pos inc) ;; => (Vector2 11 20)
|
||||
```
|
||||
|
||||
### Sumtypes
|
||||
There are two ways to define `sumtypes`:
|
||||
|
||||
**Enumeration:**
|
||||
```clojure
|
||||
(deftype MyEnum
|
||||
Kind1
|
||||
Kind2
|
||||
Kind3)
|
||||
```
|
||||
|
||||
**Data:**
|
||||
```clojure
|
||||
(deftype (Either a b)
|
||||
(Left [a])
|
||||
(Right [b]))
|
||||
```
|
||||
|
||||
A Variant can be created with the same syntax as call expression
|
||||
```clojure
|
||||
(MyEnum.Kind1)
|
||||
(Either.Left 10)
|
||||
(Either.Right 11)
|
||||
|
||||
;; Or use `use` statement
|
||||
(use Either)
|
||||
(Left 10)
|
||||
(Right 11)
|
||||
|
||||
(use MyEnum)
|
||||
(Kind1)
|
||||
(Kind2)
|
||||
(Kind3)
|
||||
```
|
||||
|
||||
You can use pattern matching to extract values in a safe way
|
||||
```clojure
|
||||
(defn get [either]
|
||||
(match either
|
||||
(Either.Left a) a
|
||||
(Either.Right b) b))
|
||||
|
||||
(with MyEnum
|
||||
;; You can give a generic "otherwise" statement as well
|
||||
(match myenum
|
||||
(Kind1) (logic1)
|
||||
_ (logic-other)))
|
||||
```
|
||||
|
||||
### C Interop
|
||||
```clojure
|
||||
(system-include "math.h") ;; compiles to #include <math.h>
|
||||
(local-include "math.h") ;; compiles to #include "math.h"
|
||||
(relative-include "math.h") ;; compiles to #include "$carp_file_dir/math.h" where carp_file_dir is the absolute path to the folder containing the invoking .carp file
|
||||
|
||||
(register blah (Fn [Int Int] String)) ;; Will register the function 'blah' that takes two Int:s and returns a String
|
||||
(register pi Double) ;; Will register the global variable 'pi' of type Double
|
||||
|
@ -54,23 +54,25 @@ Please note that for private repos only loading through SSH is supported. For pu
|
||||
* [Dynamic ⦁](http://carp-lang.github.io/Carp/core/Dynamic.html) (only available in the repl and at compile time)
|
||||
|
||||
* [Maybe ⦁](http://carp-lang.github.io/Carp/core/Maybe.html)
|
||||
* [Either ⦁](http://carp-lang.github.io/Carp/core/Either.html)
|
||||
* [Result ⦁](http://carp-lang.github.io/Carp/core/Result.html)
|
||||
|
||||
### Numerics
|
||||
* [Int ⦁](http://carp-lang.github.io/Carp/core/Int.html)
|
||||
* SafeInt
|
||||
<!-- * SafeInt -->
|
||||
* [Long ⦁](http://carp-lang.github.io/Carp/core/Long.html)
|
||||
* [Bool ⦁](http://carp-lang.github.io/Carp/core/Bool.html)
|
||||
* [Float ⦁](http://carp-lang.github.io/Carp/core/Float.html)
|
||||
* [Double ⦁](http://carp-lang.github.io/Carp/core/Double.html)
|
||||
* [Vector](http://carp-lang.github.io/Carp/core/Vector.html)
|
||||
* [Vector2](http://carp-lang.github.io/Carp/core/Vector2.html)
|
||||
* [Vector3](http://carp-lang.github.io/Carp/core/Vector3.html)
|
||||
* [VectorN](http://carp-lang.github.io/Carp/core/VectorN.html)
|
||||
* [Geometry](http://carp-lang.github.io/Carp/core/Geometry.html)
|
||||
* [Statistics](http://carp-lang.github.io/Carp/core/Statistics.html)
|
||||
|
||||
### Text
|
||||
* [String ⦁](http://carp-lang.github.io/Carp/core/String.html)
|
||||
* [Char ⦁](http://carp-lang.github.io/Carp/core/Char.html)
|
||||
* Format ⦁
|
||||
<!-- * Format ⦁ -->
|
||||
* [Pattern ⦁](http://carp-lang.github.io/Carp/core/Pattern.html)
|
||||
|
||||
### Collections
|
||||
@ -82,15 +84,15 @@ Please note that for private repos only loading through SSH is supported. For pu
|
||||
* [System ⦁](http://carp-lang.github.io/Carp/core/System.html)
|
||||
|
||||
### Development
|
||||
* [Debug ⦁](http://carp-lang.github.io/Carp/core/Debug.html)
|
||||
* [Test](http://carp-lang.github.io/Carp/core/Test.html)
|
||||
* [Bench](http://carp-lang.github.io/Carp/core/Bench.html)
|
||||
* [Debug ⦁](http://carp-lang.github.io/Carp/core/Debug.html)
|
||||
* [Test ⦁](http://carp-lang.github.io/Carp/core/Test.html)
|
||||
|
||||
### Graphics, sound and interaction
|
||||
* [SDL](../core/SDL.carp)
|
||||
* [SDL Image](../core/SDL_image.carp)
|
||||
* [SDL TTF](../core/SDL_ttf.carp)
|
||||
* [SDL Mixer](../core/SDL_mixer.carp)
|
||||
* [SDL](http://carp-lang.github.io/Carp/sdl/SDL_index.html)
|
||||
* [SDL Image](http://carp-lang.github.io/Carp/sdl/IMG.html)
|
||||
* [SDL TTF](http://carp-lang.github.io/Carp/sdl/TTF.html)
|
||||
* [SDL Mixer](http://carp-lang.github.io/Carp/sdl/Mixer.html)
|
||||
* [GLFW](../core/GLFW.carp)
|
||||
* [OpenGL](../core/OpenGL.carp)
|
||||
|
||||
|
@ -5,7 +5,9 @@ To explore the commands available, enter ```(help)``` and press enter.
|
||||
|
||||
To load code from disk, use ```(load "filename.carp")```, this will add the source file `filename.carp` to the current 'project'. A project is a light weight concept in the repl that ties together source files and compiler settings much like in an IDE like Eclipse or Visual Studio.
|
||||
|
||||
To build your current project, call ```(build)```. This will emit an executable or dynamic library depending on if you have defined a main-function or not. Everything emitted by the compiler will be saved in a directory named ```out``` by default. This, and other settings regarding the project can be changed by various commands. To see a list of available commands, call ```(help "project")```.
|
||||
To build your current project, call ```(build)```. This will emit an executable or dynamic library depending on if you have defined a main-function or not. Please note that a project emitting a library will not initialize global variables automatically, the user of the library needs to call the C function `carp_init_globals` or the Carp function `System.carp-init-globals` instead.
|
||||
|
||||
Everything emitted by the compiler will be saved in a directory named ```out``` by default. This, and other settings regarding the project can be changed by various commands. To see a list of available commands, call ```(help "project")```.
|
||||
|
||||
There are a bunch of handy shortcuts for doing common things at the REPL:
|
||||
|
||||
|
@ -40,10 +40,17 @@ All the array transforming functions 'endo-map' and 'filter' use C-style mutatio
|
||||
|
||||
The restriction of 'endo-map' is that it must return an array of the same type as the input. If that's not possible, use 'copy-map' instead. It works like the normal 'map' found in other functional languages. The 'copy-' prefix is there to remind you of the fact that the function is allocating memory.
|
||||
|
||||
To execute side-effects, use the foreach macro:
|
||||
To execute side-effects, use the `doall` macro:
|
||||
|
||||
```
|
||||
(foreach println [@"Yo" @"Hola" @"Hej"])
|
||||
(doall IO.println [@"Yo" @"Hola" @"Hej"])
|
||||
```
|
||||
|
||||
Or `foreach` (works like a foreach loop construct in a lot of other programming languages):
|
||||
|
||||
```
|
||||
(foreach [x &[1 2 3]]
|
||||
(println* "x: " x))
|
||||
```
|
||||
|
||||
|
||||
@ -94,7 +101,7 @@ If-statements are kind of tricky in regards to memory management:
|
||||
manage)))
|
||||
```
|
||||
|
||||
The 'manage-me' variable is the return value in the second branch, but should get freed if "Too short" is returned.
|
||||
The 'manage' variable is the return value in the second branch, but should get freed if "Too short" is returned.
|
||||
The output is a somewhat noisy C program:
|
||||
```C
|
||||
string say_MINUS_what(string text) {
|
||||
|
@ -19,6 +19,11 @@ https://news.ycombinator.com/item?id=12039268
|
||||
|
||||
# OWNERSHIP & BORROWING
|
||||
|
||||
- https://gitlab.redox-os.org/redox-os/rust/tree/3b49b27e0cb07c8735b534c3825b491a585ab404/src/librustc_borrowck/borrowck
|
||||
- https://rust-lang.github.io/rustc-guide/borrow_check.html
|
||||
- https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md#detailed-design
|
||||
- http://ticki.github.io/blog/lambda-crabs-part-1-a-mathematical-introduction-to-lifetimes-and-regions/
|
||||
|
||||
- http://smallcultfollowing.com/babysteps/blog/2016/04/27/non-lexical-lifetimes-introduction/
|
||||
- http://smallcultfollowing.com/babysteps/blog/2016/05/04/non-lexical-lifetimes-based-on-liveness/
|
||||
- http://smallcultfollowing.com/babysteps/blog/2016/05/09/non-lexical-lifetimes-adding-the-outlives-relation/
|
||||
|
@ -27,6 +27,9 @@ For Flycheck:
|
||||
|
||||
To start an interactive session, make sure `carp` is in your path (inside Emacs) and execute `M-x run-carp`.
|
||||
|
||||
# Atom
|
||||
[language-carp](https://atom.io/packages/language-carp) offers highlight with both TextMate and Tree-sitter, where tree-sitter grammar is more powerful.
|
||||
|
||||
## Other editors
|
||||
Clojure syntax highlighting works very well with Carp since it uses the same symbols for most things.
|
||||
If you have written an editor mode, please tell us and it will be added here!
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,26 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), (Ref (Array a))] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>compares two arrays and inverts the result.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
@ -171,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), (Ref (Array a))] Bool)
|
||||
(λ [(Ref (Array a) b), (Ref (Array a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -191,7 +181,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] Bool)
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Ref (Array a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(all? f a)
|
||||
@ -211,7 +201,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int] (Array t))
|
||||
(λ [Int] (Array a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -231,7 +221,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] Bool)
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Ref (Array a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(any? f a)
|
||||
@ -251,7 +241,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Array t), Int, t] (Array t))
|
||||
(λ [(Array a), Int, a] (Array a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -271,7 +261,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array t)), Int, t] ())
|
||||
(λ [(Ref (Array a) b), Int, a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -291,7 +281,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array t)), Int, t] ())
|
||||
(λ [(Ref (Array a) b), Int, a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -311,7 +301,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Array a), Int, (Ref (λ [&a] a))] (Array a))
|
||||
(λ [(Array a), Int, (Ref (λ [(Ref a b)] a c) d)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(aupdate a i f)
|
||||
@ -331,7 +321,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), Int, (Ref (λ [&a] a))] ())
|
||||
(λ [(Ref (Array a) b), Int, (Ref (λ [(Ref a b)] a c) d)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(aupdate! a i f)
|
||||
@ -351,7 +341,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array (Array a)))] (Array a))
|
||||
(λ [(Ref (Array (Array a)) b)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(concat xs)
|
||||
@ -361,6 +351,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#contains?">
|
||||
<h3 id="contains?">
|
||||
contains?
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a) b), (Ref a b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(contains? arr el)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>checks wether an element exists in the array.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
@ -371,7 +381,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Array a))
|
||||
(λ [(Ref (Array a) b)] (Array a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -391,7 +401,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (Array a))
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Ref (Array a) e)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(copy-filter f a)
|
||||
@ -412,7 +422,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] b)), (Ref (Array a))] (Array b))
|
||||
(λ [(Ref (λ [(Ref a b)] c d) e), (Ref (Array a) b)] (Array c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(copy-map f a)
|
||||
@ -453,7 +463,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), &a] Int)
|
||||
(λ [(Ref (Array a) b), (Ref a b)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(element-count a e)
|
||||
@ -473,7 +483,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] Bool)
|
||||
(λ [(Ref (Array a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(empty? a)
|
||||
@ -493,7 +503,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Array a)] (Array a))
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Array a)] (Array a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -513,7 +523,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a] a)), (Array a)] (Array a))
|
||||
(λ [(Ref (λ [a] a b) c), (Array a)] (Array a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -533,7 +543,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Array (Pair Int a)))
|
||||
(λ [(Ref (Array a) b)] (Array (Pair Int a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(enumerated xs)
|
||||
@ -553,7 +563,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (Maybe a))
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Ref (Array a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(find f a)
|
||||
@ -574,7 +584,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (Maybe Int))
|
||||
(λ [(Ref (λ [(Ref a b)] Bool c) d), (Ref (Array a) b)] (Maybe Int))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(find-index f a)
|
||||
@ -595,7 +605,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Maybe a))
|
||||
(λ [(Ref (Array a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(first a)
|
||||
@ -616,7 +626,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), &a] (Maybe Int))
|
||||
(λ [(Ref (Array a) b), (Ref a b)] (Maybe Int))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(index-of a e)
|
||||
@ -637,7 +647,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Maybe a))
|
||||
(λ [(Ref (Array a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(last a)
|
||||
@ -658,7 +668,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array t))] Int)
|
||||
(λ [(Ref (Array a) b)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -678,7 +688,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Maybe a))
|
||||
(λ [(Ref (Array a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(maximum xs)
|
||||
@ -699,7 +709,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Maybe a))
|
||||
(λ [(Ref (Array a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(minimum xs)
|
||||
@ -717,16 +727,54 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array t)), Int] &t)
|
||||
(λ [(Ref (Array a) b), Int] (Maybe a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<pre class="args">
|
||||
(nth xs index)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>gets a reference to the <code>n</code>th element from an array <code>a</code>.</p>
|
||||
<p>gets a reference to the <code>n</code>th element from an array <code>arr</code> wrapped on a <code>Maybe</code>.</p>
|
||||
<p>If the <code>index</code> is out of bounds, return <code>Maybe.Nothing</code></p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#partition">
|
||||
<h3 id="partition">
|
||||
partition
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a) b), Int] (Array (Array a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(partition arr n)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Partitions an array <code>arr</code> into an array of arrays of length <code>n</code>
|
||||
sequentially filled with the <code>arr</code>'s original values.</p>
|
||||
<pre><code>This function will fill partitions until `arr` is exhuasted.
|
||||
|
||||
If `n` is greater than or equal to the length of `arr`, the result of this
|
||||
function is an array containing a single array of length `n`.
|
||||
|
||||
For example:
|
||||
|
||||
```clojure
|
||||
(Array.partition &[1 2 3 4] 2)
|
||||
=> [[1 2] [3 4]]
|
||||
(Array.partition &[1 2 3 4] 3)
|
||||
=> [[1 2 3] [4]]
|
||||
(Array.partition &[1 2 3 4] 6)
|
||||
=> [[1 2 3 4]]
|
||||
```
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -760,7 +808,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] a)
|
||||
(λ [(Ref (Array a) b)] a)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -780,7 +828,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), (Ref (λ [&a] Bool))] Int)
|
||||
(λ [(Ref (Array a) b), (Ref (λ [(Ref a b)] Bool c) d)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(predicate-count a pred)
|
||||
@ -791,19 +839,19 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#prefix-array">
|
||||
<h3 id="prefix-array">
|
||||
prefix-array
|
||||
<a class="anchor" href="#prefix">
|
||||
<h3 id="prefix">
|
||||
prefix
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), Int] (Array a))
|
||||
(λ [(Ref a b), Int] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(prefix-array xs end-index)
|
||||
(prefix xs end-index)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>gets a prefix array to <code>end-index</code>.</p>
|
||||
@ -820,7 +868,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] String)
|
||||
(λ [(Ref (Array a) b)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(prn x)
|
||||
@ -859,7 +907,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), a] ())
|
||||
(λ [(Ref (Array a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -899,7 +947,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Array t)] (Ptr t))
|
||||
(λ [(Array a)] (Ptr a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -919,7 +967,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a, &b] a)), a, (Ref (Array b))] a)
|
||||
(λ [(Ref (λ [a, (Ref b c)] a d) e), a, (Ref (Array b) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(reduce f x xs)
|
||||
@ -928,7 +976,7 @@
|
||||
<p>will reduce an array <code>xs</code> into a single value using a function <code>f</code> that takes the reduction thus far and the next value. The initial reduction value is <code>x</code>.</p>
|
||||
<p>As an example, consider this definition of <code>sum</code> based on <code>reduce</code>:</p>
|
||||
<pre><code>(defn sum [x]
|
||||
(reduce + 0 x))
|
||||
(reduce &(fn [x y] (+ x @y)) 0 x))
|
||||
</code></pre>
|
||||
<p>It will sum the previous sum with each new value, starting at <code>0</code>.</p>
|
||||
|
||||
@ -944,7 +992,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&a, (Array a)] (Array a))
|
||||
(λ [(Ref a b), (Array a)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(remove el arr)
|
||||
@ -984,7 +1032,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, (Ref (λ [] a))] (Array a))
|
||||
(λ [Int, (Ref (λ [] a b) c)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(repeat n f)
|
||||
@ -1004,13 +1052,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, (λ [Int] a)] (Array a))
|
||||
(λ [Int, (λ [Int] a b)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(repeat-indexed n f)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>repeats function <code>f</code> <code>n</code>times and stores the results in an array.</p>
|
||||
<p>repeats function <code>f</code> <code>n</code> times and stores the results in an array.</p>
|
||||
<p>This is similar to <a href="#repeat"><code>repeat</code></a>, but the function <code>f</code> will be supplied with the index of the element.</p>
|
||||
|
||||
</p>
|
||||
@ -1025,7 +1073,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, &a] (Array a))
|
||||
(λ [Int, (Ref a b)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(replicate n e)
|
||||
@ -1055,6 +1103,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#slice">
|
||||
<h3 id="slice">
|
||||
slice
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a) b), Int, Int] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(slice xs start-index end-index)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>gets a subarray from <code>start-index</code> to <code>end-index</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#sort">
|
||||
<h3 id="sort">
|
||||
@ -1085,7 +1153,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] ())
|
||||
(λ [(Ref (Array a) b)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sort! arr)
|
||||
@ -1105,7 +1173,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Array a), (Ref (λ [&a, &a] Bool))] (Array a))
|
||||
(λ [(Array a), (Ref (λ [(Ref a b), (Ref a b)] Bool c) d)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sort-by arr f)
|
||||
@ -1125,7 +1193,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), (Ref (λ [&a, &a] Bool))] ())
|
||||
(λ [(Ref (Array a) b), (Ref (λ [(Ref a b), (Ref a b)] Bool c) d)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sort-by! arr f)
|
||||
@ -1145,7 +1213,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] (Array a))
|
||||
(λ [(Ref (Array a) b)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sorted arr)
|
||||
@ -1165,7 +1233,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), (Ref (λ [&a, &a] Bool))] (Array a))
|
||||
(λ [(Ref (Array a) b), (Ref (λ [(Ref a c), (Ref a c)] Bool d) e)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sorted-by arr f)
|
||||
@ -1185,7 +1253,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] String)
|
||||
(λ [(Ref (Array a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -1196,39 +1264,19 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#subarray">
|
||||
<h3 id="subarray">
|
||||
subarray
|
||||
<a class="anchor" href="#suffix">
|
||||
<h3 id="suffix">
|
||||
suffix
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), Int, Int] (Array a))
|
||||
(λ [(Ref (Array a) b), Int] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(subarray xs start-index end-index)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>gets a subarray from <code>start-index</code> to <code>end-index</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#suffix-array">
|
||||
<h3 id="suffix-array">
|
||||
suffix-array
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), Int] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(suffix-array xs start-index)
|
||||
(suffix xs start-index)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>gets a suffix array from <code>start-index</code>.</p>
|
||||
@ -1245,7 +1293,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] a)
|
||||
(λ [(Ref (Array a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sum xs)
|
||||
@ -1265,7 +1313,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array (Array a)))] Int)
|
||||
(λ [(Ref (Array (Array a)) b)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sum-length xs)
|
||||
@ -1305,7 +1353,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a)), Int, Int] ())
|
||||
(λ [(Ref (Array a) b), Int, Int] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(swap! a i j)
|
||||
@ -1315,6 +1363,33 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unreduce">
|
||||
<h3 id="unreduce">
|
||||
unreduce
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, (Ref (λ [a] Bool b) c), (Ref (λ [a] a b) d)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(unreduce start test step)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>creates an array by producing values using <code>step</code> until they
|
||||
no longer satisfy <code>test</code>. The initial value is <code>start</code>.</p>
|
||||
<p>Example:</p>
|
||||
<pre><code>; if we didn’t have Array.range, we could define it like this:
|
||||
(defn range [start end step]
|
||||
(unreduce start &(fn [x] (< x (+ step end))) &(fn [x] (+ x step)))
|
||||
)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unsafe-first">
|
||||
<h3 id="unsafe-first">
|
||||
@ -1325,7 +1400,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] a)
|
||||
(λ [(Ref (Array a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(unsafe-first a)
|
||||
@ -1346,7 +1421,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] a)
|
||||
(λ [(Ref (Array a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(unsafe-last a)
|
||||
@ -1357,6 +1432,46 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unsafe-nth">
|
||||
<h3 id="unsafe-nth">
|
||||
unsafe-nth
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a) b), Int] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>gets a reference to the <code>n</code>th element from an array <code>a</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unsafe-raw">
|
||||
<h3 id="unsafe-raw">
|
||||
unsafe-raw
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref a (Array b))] (Ptr b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>returns an array <code>a</code> as a raw pointer—useful for interacting with C.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zero">
|
||||
<h3 id="zero">
|
||||
@ -1387,7 +1502,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a, &b] c)), (Ref (Array a)), (Ref (Array b))] (Array c))
|
||||
(λ [(Ref (λ [(Ref a b), (Ref c d)] e f) g), (Ref (Array a) b), (Ref (Array c) d)] (Array e))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip f a b)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [] a)] ())
|
||||
(λ [(λ [] a b)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(bench f)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -142,9 +152,9 @@
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
<a class="anchor" href="#=">
|
||||
<h3 id="=">
|
||||
=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
@ -161,9 +171,9 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
<h3 id="=">
|
||||
=
|
||||
<a class="anchor" href="#and">
|
||||
<h3 id="and">
|
||||
and
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
@ -189,7 +199,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Bool] Bool)
|
||||
(λ [(Ref Bool a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -208,7 +218,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Bool] String)
|
||||
(λ [(Ref String a), Bool] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -227,7 +237,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Bool] Int)
|
||||
(λ [(Ref Bool a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -236,6 +246,44 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#not">
|
||||
<h3 id="not">
|
||||
not
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Bool] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#or">
|
||||
<h3 id="or">
|
||||
or
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Bool, Bool] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#prn">
|
||||
<h3 id="prn">
|
||||
|
765
docs/core/Byte.html
Normal file
765
docs/core/Byte.html
Normal file
@ -0,0 +1,765 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="carp_style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="logo">
|
||||
<a href="http://github.com/carp-lang/Carp">
|
||||
<img src="logo.png">
|
||||
</a>
|
||||
<div class="title">
|
||||
core
|
||||
</div>
|
||||
<div class="index">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="Dynamic.html">
|
||||
Dynamic
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Int.html">
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Bool.html">
|
||||
Bool
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Float.html">
|
||||
Float
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Double.html">
|
||||
Double
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Vector2.html">
|
||||
Vector2
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Vector3.html">
|
||||
Vector3
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="VectorN.html">
|
||||
VectorN
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Geometry.html">
|
||||
Geometry
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Statistics.html">
|
||||
Statistics
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="String.html">
|
||||
String
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Char.html">
|
||||
Char
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pattern.html">
|
||||
Pattern
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Array.html">
|
||||
Array
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="IO.html">
|
||||
IO
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="System.html">
|
||||
System
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Debug.html">
|
||||
Debug
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Test.html">
|
||||
Test
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Bench.html">
|
||||
Bench
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Map.html">
|
||||
Map
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Maybe.html">
|
||||
Maybe
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Result.html">
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<h1>
|
||||
Byte
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#*">
|
||||
<h3 id="*">
|
||||
*
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#+">
|
||||
<h3 id="+">
|
||||
+
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#-">
|
||||
<h3 id="-">
|
||||
-
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/">
|
||||
<h3 id="/">
|
||||
/
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
<h3 id="<">
|
||||
<
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
<h3 id="=">
|
||||
=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#>">
|
||||
<h3 id=">">
|
||||
>
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#add-ref">
|
||||
<h3 id="add-ref">
|
||||
add-ref
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref Byte a), (Ref Byte b)] Byte)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add-ref x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-and">
|
||||
<h3 id="bit-and">
|
||||
bit-and
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-not">
|
||||
<h3 id="bit-not">
|
||||
bit-not
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-or">
|
||||
<h3 id="bit-or">
|
||||
bit-or
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-shift-left">
|
||||
<h3 id="bit-shift-left">
|
||||
bit-shift-left
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-shift-right">
|
||||
<h3 id="bit-shift-right">
|
||||
bit-shift-right
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#bit-xor">
|
||||
<h3 id="bit-xor">
|
||||
bit-xor
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#clamp">
|
||||
<h3 id="clamp">
|
||||
clamp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, a, a] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(clamp min max val)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
copy
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref Byte a)] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dec">
|
||||
<h3 id="dec">
|
||||
dec
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#even?">
|
||||
<h3 id="even?">
|
||||
even?
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(even? a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#format">
|
||||
<h3 id="format">
|
||||
format
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a), Byte] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-int">
|
||||
<h3 id="from-int">
|
||||
from-int
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-string">
|
||||
<h3 id="from-string">
|
||||
from-string
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a)] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#hash">
|
||||
<h3 id="hash">
|
||||
hash
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref Byte a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#inc">
|
||||
<h3 id="inc">
|
||||
inc
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mod">
|
||||
<h3 id="mod">
|
||||
mod
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#odd?">
|
||||
<h3 id="odd?">
|
||||
odd?
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(odd? a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#pow">
|
||||
<h3 id="pow">
|
||||
pow
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(pow x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Raise x to the power of y.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#prn">
|
||||
<h3 id="prn">
|
||||
prn
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(prn x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#random">
|
||||
<h3 id="random">
|
||||
random
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] Byte)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(random)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#random-between">
|
||||
<h3 id="random-between">
|
||||
random-between
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte, Byte] Byte)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(random-between lower upper)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#str">
|
||||
<h3 id="str">
|
||||
str
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#to-int">
|
||||
<h3 id="to-int">
|
||||
to-int
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Byte] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zero">
|
||||
<h3 id="zero">
|
||||
zero
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] Byte)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,25 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Char, Char] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
@ -267,7 +258,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Char] Char)
|
||||
(λ [(Ref Char a)] Char)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -286,7 +277,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Char] String)
|
||||
(λ [(Ref String a), Char] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -324,7 +315,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Char] Int)
|
||||
(λ [(Ref Char a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -363,7 +354,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Char] Int)
|
||||
(λ [(Ref Char a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(meaning char-ref)
|
||||
@ -518,7 +509,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] a)
|
||||
(λ [] Char)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -217,25 +227,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double, Double] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
<h3 id="<">
|
||||
@ -293,6 +284,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#MAX">
|
||||
<h3 id="MAX">
|
||||
MAX
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Double
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#abs">
|
||||
<h3 id="abs">
|
||||
@ -341,7 +351,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Double, &Double] Double)
|
||||
(λ [(Ref Double a), (Ref Double b)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add-ref x y)
|
||||
@ -360,7 +370,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double, Double] Bool)
|
||||
(λ [a, a] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(approx x y)
|
||||
@ -447,25 +457,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#clamp">
|
||||
<h3 id="clamp">
|
||||
clamp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, a, a] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(clamp min max val)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
@ -476,7 +467,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Double] Double)
|
||||
(λ [(Ref Double a)] Double)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -523,6 +514,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dec">
|
||||
<h3 id="dec">
|
||||
dec
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dec x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#e">
|
||||
<h3 id="e">
|
||||
@ -590,7 +600,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Double] String)
|
||||
(λ [(Ref String a), Double] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -609,7 +619,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double, &Int] Double)
|
||||
(λ [Double, (Ref Int a)] Double)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -675,6 +685,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-string">
|
||||
<h3 id="from-string">
|
||||
from-string
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a)] Double)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#hash">
|
||||
<h3 id="hash">
|
||||
@ -685,7 +714,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Double] Int)
|
||||
(λ [(Ref Double a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -694,6 +723,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#inc">
|
||||
<h3 id="inc">
|
||||
inc
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(inc x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ldexp">
|
||||
<h3 id="ldexp">
|
||||
@ -780,7 +828,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double, &Double] Double)
|
||||
(λ [Double, (Ref Double a)] Double)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -314,9 +324,9 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#Sym">
|
||||
<h3 id="Sym">
|
||||
Sym
|
||||
<a class="anchor" href="#Symbol">
|
||||
<h3 id="Symbol">
|
||||
Symbol
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
@ -370,6 +380,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#array">
|
||||
<h3 id="array">
|
||||
array
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#array?">
|
||||
<h3 id="array?">
|
||||
@ -1016,6 +1045,45 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#collect-into">
|
||||
<h3 id="collect-into">
|
||||
collect-into
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(collect-into xs f)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Transforms a dynamic data literal into another, preserving order</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#collect-into-internal">
|
||||
<h3 id="collect-into-internal">
|
||||
collect-into-internal
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(collect-into-internal xs acc f)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#cons">
|
||||
<h3 id="cons">
|
||||
@ -1054,6 +1122,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#cxr">
|
||||
<h3 id="cxr">
|
||||
cxr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(cxr x pair)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dec">
|
||||
<h3 id="dec">
|
||||
@ -1244,6 +1331,44 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list">
|
||||
<h3 id="list">
|
||||
list
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list-to-array-internal">
|
||||
<h3 id="list-to-array-internal">
|
||||
list-to-array-internal
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(list-to-array-internal xs acc)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list?">
|
||||
<h3 id="list?">
|
||||
@ -1282,25 +1407,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#local-include">
|
||||
<h3 id="local-include">
|
||||
local-include
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#macro-error">
|
||||
<h3 id="macro-error">
|
||||
@ -1358,6 +1464,44 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#nthcar">
|
||||
<h3 id="nthcar">
|
||||
nthcar
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(nthcar n pair)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#nthcdr">
|
||||
<h3 id="nthcdr">
|
||||
nthcdr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(nthcdr n pair)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#os">
|
||||
<h3 id="os">
|
||||
@ -1396,25 +1540,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#project-set!">
|
||||
<h3 id="project-set!">
|
||||
project-set!
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#quit">
|
||||
<h3 id="quit">
|
||||
@ -1453,6 +1578,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#relative-include">
|
||||
<h3 id="relative-include">
|
||||
relative-include
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#reload">
|
||||
<h3 id="reload">
|
||||
@ -1565,6 +1709,25 @@
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#write-file">
|
||||
<h3 id="write-file">
|
||||
write-file
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -217,25 +227,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float, Float] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
<h3 id="<">
|
||||
@ -293,6 +284,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#MAX">
|
||||
<h3 id="MAX">
|
||||
MAX
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Float
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#abs">
|
||||
<h3 id="abs">
|
||||
@ -341,7 +351,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Float, &Float] Float)
|
||||
(λ [(Ref Float a), (Ref Float b)] Float)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add-ref x y)
|
||||
@ -360,7 +370,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float, Float] Bool)
|
||||
(λ [a, a] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(approx x y)
|
||||
@ -476,7 +486,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Float] Float)
|
||||
(λ [(Ref Float a)] Float)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -523,6 +533,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dec">
|
||||
<h3 id="dec">
|
||||
dec
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float] Float)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dec x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#exp">
|
||||
<h3 id="exp">
|
||||
@ -571,7 +600,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Float] String)
|
||||
(λ [(Ref String a), Float] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -590,7 +619,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float, &Int] Float)
|
||||
(λ [Float, (Ref Int a)] Float)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -618,6 +647,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-string">
|
||||
<h3 id="from-string">
|
||||
from-string
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a)] Float)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#hash">
|
||||
<h3 id="hash">
|
||||
@ -628,7 +676,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Float] Int)
|
||||
(λ [(Ref Float a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -637,6 +685,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#inc">
|
||||
<h3 id="inc">
|
||||
inc
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float] Float)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(inc x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ldexp">
|
||||
<h3 id="ldexp">
|
||||
@ -723,7 +790,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Float, &Float] Float)
|
||||
(λ [Float, (Ref Float a)] Float)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double] Double)
|
||||
(λ [a] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(degree-to-radians n)
|
||||
@ -171,7 +181,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Double] Double)
|
||||
(λ [a] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(radians-to-degree n)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -228,13 +238,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] ())
|
||||
(λ [Id] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(color cname)
|
||||
(color cid)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>sets the output color using ANSI coloration based on a color name <code>cname</code>.</p>
|
||||
<p>sets the output color using ANSI coloration based on a color id <code>cid</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -248,13 +258,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] ())
|
||||
(λ [Id, (Ref String a)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(colorize cname s)
|
||||
(colorize cid s)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>wraps a string in ANSI coloration based on a color name <code>cname</code> and prints it.</p>
|
||||
<p>wraps a string in ANSI coloration based on a color id <code>cid</code> and prints it.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -265,10 +275,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
doc-stub
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
a
|
||||
(λ [(Ref String a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -288,7 +298,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] ())
|
||||
(λ [(Ref String a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -388,13 +398,13 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] (Ptr FILE))
|
||||
(λ [(Ref String a), (Ref String b)] (Ptr FILE))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a file pointer.</p>
|
||||
<p>opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a file pointer. Consider using the function open-file instead.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -518,6 +528,45 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#getenv">
|
||||
<h3 id="getenv">
|
||||
getenv
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [String] (Maybe String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(getenv s)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#open-file">
|
||||
<h3 id="open-file">
|
||||
open-file
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a), (Ref String b)] (Result (Ptr FILE) Int))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(open-file filename mode)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>opens a file by name using a mode (one or multiple of [r]ead, [w]rite, and [a]ppend), returns a Result type that contains an error string or a file pointer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#print">
|
||||
<h3 id="print">
|
||||
@ -528,7 +577,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] ())
|
||||
(λ [(Ref String a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -548,7 +597,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] ())
|
||||
(λ [(Ref String a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -568,7 +617,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Result String String))
|
||||
(λ [(Ref String a)] (Result String Int))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(read->EOF filename)
|
||||
@ -588,7 +637,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -618,6 +667,63 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stderr">
|
||||
<h3 id="stderr">
|
||||
stderr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stdin">
|
||||
<h3 id="stdin">
|
||||
stdin
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#stdout">
|
||||
<h3 id="stdout">
|
||||
stdout
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(Ptr FILE)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unlink">
|
||||
<h3 id="unlink">
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -217,25 +227,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Int] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
<h3 id="<">
|
||||
@ -361,7 +352,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Int, &Int] Int)
|
||||
(λ [(Ref Int a), (Ref Int b)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add-ref x y)
|
||||
@ -513,7 +504,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Int] Int)
|
||||
(λ [(Ref Int a)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -570,7 +561,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int] String)
|
||||
(λ [(Ref String a), Int] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -609,7 +600,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Int)
|
||||
(λ [(Ref String a)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -628,7 +619,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Int] Int)
|
||||
(λ [(Ref Int a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -801,7 +792,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Int, &Int] Bool)
|
||||
(λ [Int, Int, (Ref Int a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -821,7 +812,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Int, &Int] Bool)
|
||||
(λ [Int, Int, (Ref Int a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -841,7 +832,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Int, &Int] Bool)
|
||||
(λ [Int, Int, (Ref Int a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -217,25 +227,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Long, Long] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
<h3 id="<">
|
||||
@ -293,6 +284,44 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#MAX">
|
||||
<h3 id="MAX">
|
||||
MAX
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Long
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#MIN">
|
||||
<h3 id="MIN">
|
||||
MIN
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Long
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#abs">
|
||||
<h3 id="abs">
|
||||
@ -436,7 +465,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Long] Long)
|
||||
(λ [(Ref Long a)] Long)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -493,7 +522,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Long] String)
|
||||
(λ [(Ref String a), Long] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -531,7 +560,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Long)
|
||||
(λ [(Ref String a)] Long)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -550,7 +579,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Long] Int)
|
||||
(λ [(Ref Long a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -702,7 +731,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Long, Long, &Long] Bool)
|
||||
(λ [Long, Long, (Ref Long a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -721,7 +750,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Long, Long, &Long] Bool)
|
||||
(λ [Long, Long, (Ref Long a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -740,7 +769,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Long, Long, &Long] Bool)
|
||||
(λ [Long, Long, (Ref Long a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -804,6 +833,25 @@
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zero">
|
||||
<h3 id="zero">
|
||||
zero
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] Long)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), (Ref (Map a b))] Bool)
|
||||
(λ [(Ref (Map a b) c), (Ref (Map a b) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= m1 m2)
|
||||
@ -170,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a, &b] Bool)), (Ref (Map a b))] Bool)
|
||||
(λ [(Ref (λ [(Ref a b), (Ref c b)] Bool d) e), (Ref (Map a c) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(all? pred m)
|
||||
@ -190,7 +200,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Ref (Array (Bucket a b))))
|
||||
(λ [(Ref (Map a b) c)] (Ref (Array (Bucket a b)) c))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -210,7 +220,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), &a] Bool)
|
||||
(λ [(Ref (Map a b) c), (Ref a c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(contains? m k)
|
||||
@ -230,7 +240,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Map a b))
|
||||
(λ [(Ref (Map a b) c)] (Map a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -330,7 +340,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [&a, &b] b)), (Map a b)] (Map a b))
|
||||
(λ [(Ref (λ [(Ref a b), (Ref c b)] c d) e), (Map a c)] (Map a c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(endo-map f m)
|
||||
@ -350,7 +360,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), (Ref (λ [&a, &b] ()))] ())
|
||||
(λ [(Ref (Map a b) c), (Ref (λ [(Ref a c), (Ref b c)] () d) e)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(for-each m f)
|
||||
@ -370,7 +380,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array (Pair a b)))] (Map a b))
|
||||
(λ [(Ref (Array (Pair a b)) c)] (Map a b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(from-array a)
|
||||
@ -390,7 +400,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), &a] b)
|
||||
(λ [(Ref (Map a b) c), (Ref a c)] b)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(get m k)
|
||||
@ -410,7 +420,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), &a] (Maybe b))
|
||||
(λ [(Ref (Map a b) c), (Ref a c)] (Maybe b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(get-maybe m k)
|
||||
@ -430,7 +440,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), &a, &b] b)
|
||||
(λ [(Ref (Map a b) c), (Ref a c), (Ref b d)] b)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(get-with-default m k default-value)
|
||||
@ -470,7 +480,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Array a))
|
||||
(λ [(Ref (Map a b) c)] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(keys m)
|
||||
@ -490,7 +500,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a, &b, &c] a)), a, (Ref (Map b c))] a)
|
||||
(λ [(Ref (λ [a, (Ref b c), (Ref d c)] a e) f), a, (Ref (Map b d) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(kv-reduce f init m)
|
||||
@ -510,7 +520,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] Int)
|
||||
(λ [(Ref (Map a b) c)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(length m)
|
||||
@ -530,7 +540,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] &Int)
|
||||
(λ [(Ref (Map a b) c)] (Ref Int c))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -550,7 +560,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] String)
|
||||
(λ [(Ref (Map a b) c)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -570,7 +580,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), &a, &b] (Map a b))
|
||||
(λ [(Map a b), (Ref a c), (Ref b c)] (Map a b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(put m k v)
|
||||
@ -590,7 +600,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), &a, &b] ())
|
||||
(λ [(Ref (Map a b) c), (Ref a c), (Ref b d)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(put! m k v)
|
||||
@ -610,7 +620,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), &a] (Map a b))
|
||||
(λ [(Map a b), (Ref a c)] (Map a b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(remove m k)
|
||||
@ -630,7 +640,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Map b a))
|
||||
(λ [(Ref (Map a b) c)] (Map b a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(reverse m)
|
||||
@ -667,10 +677,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), (Array (Bucket a b))] ())
|
||||
(λ [(Ref (Map a b) c), (Array (Bucket a b))] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -710,7 +720,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b)), Int] ())
|
||||
(λ [(Ref (Map a b) c), Int] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -730,7 +740,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] String)
|
||||
(λ [(Ref (Map a b) c)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(str m)
|
||||
@ -750,7 +760,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Array (Pair a b)))
|
||||
(λ [(Ref (Map a b) c)] (Array (Pair a b)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(to-array m)
|
||||
@ -770,7 +780,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), &a, (Ref (λ [b] b))] (Map a b))
|
||||
(λ [(Map a b), (Ref a c), (Ref (λ [b] b d) c)] (Map a b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(update m k f)
|
||||
@ -790,7 +800,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), (Ref (λ [(Array (Bucket a b))] (Array (Bucket a b))))] (Map a b))
|
||||
(λ [(Map a b), (Ref (λ [(Array (Bucket a b))] (Array (Bucket a b)) c) d)] (Map a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -810,7 +820,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), (Ref (λ [Int] Int))] (Map a b))
|
||||
(λ [(Map a b), (Ref (λ [Int] Int c) d)] (Map a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -830,7 +840,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Map a b), &a, (Ref (λ [b] b)), b] (Map a b))
|
||||
(λ [(Map a b), (Ref a c), (Ref (λ [b] b d) c), b] (Map a b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(update-with-default m k f v)
|
||||
@ -850,7 +860,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Map a b))] (Array b))
|
||||
(λ [(Ref (Map a b) c)] (Array b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vals m)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a)), (Ref (Maybe a))] Bool)
|
||||
(λ [(Ref (Maybe a) b), (Ref (Maybe a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -211,7 +221,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Maybe a), (λ [a] b)] (Maybe b))
|
||||
(λ [(Maybe a), (Ref (λ [a] b c) d)] (Maybe b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(apply a f)
|
||||
@ -231,7 +241,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] (Maybe a))
|
||||
(λ [(Ref (Maybe a) b)] (Maybe a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -302,6 +312,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#get-tag">
|
||||
<h3 id="get-tag">
|
||||
get-tag
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a) b)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>Gets the tag from a <code>Maybe</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#just?">
|
||||
<h3 id="just?">
|
||||
@ -312,7 +342,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] Bool)
|
||||
(λ [(Ref (Maybe a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(just? a)
|
||||
@ -333,7 +363,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] Bool)
|
||||
(λ [(Ref (Maybe a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(nothing? a)
|
||||
@ -375,7 +405,7 @@ a value using <code>zero</code> if a <code>Nothing</code> is passed.</p>
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] String)
|
||||
(λ [(Ref (Maybe a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -385,27 +415,6 @@ a value using <code>zero</code> if a <code>Nothing</code> is passed.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ptr">
|
||||
<h3 id="ptr">
|
||||
ptr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] (Ptr a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(ptr a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Creates a <code>(Ptr a)</code> from a <code>(Maybe a)</code>. If the <code>Maybe</code> was
|
||||
<code>Nothing</code>, this function will return a <code>NULL</code> value.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#str">
|
||||
<h3 id="str">
|
||||
@ -416,7 +425,7 @@ a value using <code>zero</code> if a <code>Nothing</code> is passed.</p>
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a))] String)
|
||||
(λ [(Ref (Maybe a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -465,6 +474,84 @@ a value using <code>zero</code> if a <code>Nothing</code> is passed.</p>
|
||||
<p class="doc">
|
||||
<p>is an unsafe unwrapper that will get the value from a <code>Just</code>. If <code>a</code> is <code>Nothing</code>, a runtime error will be generated.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unsafe-ptr">
|
||||
<h3 id="unsafe-ptr">
|
||||
unsafe-ptr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Maybe a) b)] (Ptr a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(unsafe-ptr a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Creates a <code>(Ptr a)</code> from a <code>(Maybe a)</code>. If the <code>Maybe</code> was
|
||||
<code>Nothing</code>, this function will return a <code>NULL</code> value.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zip">
|
||||
<h3 id="zip">
|
||||
zip
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a, b] c d) e), (Maybe a), (Maybe b)] (Maybe c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip f a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zip4">
|
||||
<h3 id="zip4">
|
||||
zip4
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a, b, c, d] e f) g), (Maybe a), (Maybe b), (Maybe c), (Maybe d)] (Maybe e))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip4 f a b c d)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zip8">
|
||||
<h3 id="zip8">
|
||||
zip8
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (λ [a, b, c, d, e, f, g, h] i j) k), (Maybe a), (Maybe b), (Maybe c), (Maybe d), (Maybe e), (Maybe f), (Maybe g), (Maybe h)] (Maybe i))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip8 f a b c d e a1 b1 c1)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &Pattern] Bool)
|
||||
(λ [(Ref Pattern a), (Ref Pattern b)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -170,7 +180,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern] Pattern)
|
||||
(λ [(Ref Pattern a)] Pattern)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -189,7 +199,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] Int)
|
||||
(λ [(Ref Pattern a), (Ref String b)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -210,7 +220,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] (Array Int))
|
||||
(λ [(Ref Pattern a), (Ref String b)] (Array Int))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -231,7 +241,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Char))] Pattern)
|
||||
(λ [(Ref (Array Char) a)] Pattern)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(from-chars chars)
|
||||
@ -251,7 +261,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] (Array (Array String)))
|
||||
(λ [(Ref Pattern a), (Ref String b)] (Array (Array String)))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -262,6 +272,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#global-match-str">
|
||||
<h3 id="global-match-str">
|
||||
global-match-str
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref Pattern a), (Ref String b)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(global-match-str p s)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#init">
|
||||
<h3 id="init">
|
||||
@ -272,7 +301,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Pattern)
|
||||
(λ [(Ref String a)] Pattern)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -291,7 +320,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] (Array String))
|
||||
(λ [(Ref Pattern a), (Ref String b)] (Array String))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -312,7 +341,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] String)
|
||||
(λ [(Ref Pattern a), (Ref String b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -333,7 +362,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String] Bool)
|
||||
(λ [(Ref Pattern a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(matches? pat s)
|
||||
@ -353,7 +382,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern] String)
|
||||
(λ [(Ref Pattern a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -362,6 +391,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#split">
|
||||
<h3 id="split">
|
||||
split
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref Pattern a), (Ref String b)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(split p s)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>splits a string by a pattern.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#str">
|
||||
<h3 id="str">
|
||||
@ -372,7 +421,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern] String)
|
||||
(λ [(Ref Pattern a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -391,7 +440,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&Pattern, &String, &String, Int] String)
|
||||
(λ [(Ref Pattern a), (Ref String b), (Ref String c), Int] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
|
354
docs/core/Pointer.html
Normal file
354
docs/core/Pointer.html
Normal file
@ -0,0 +1,354 @@
|
||||
<!DOCTYPE HTML>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
|
||||
<link rel="stylesheet" href="carp_style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="content">
|
||||
<div class="logo">
|
||||
<a href="http://github.com/carp-lang/Carp">
|
||||
<img src="logo.png">
|
||||
</a>
|
||||
<div class="title">
|
||||
core
|
||||
</div>
|
||||
<div class="index">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="Dynamic.html">
|
||||
Dynamic
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Int.html">
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Bool.html">
|
||||
Bool
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Float.html">
|
||||
Float
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Double.html">
|
||||
Double
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Vector2.html">
|
||||
Vector2
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Vector3.html">
|
||||
Vector3
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="VectorN.html">
|
||||
VectorN
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Geometry.html">
|
||||
Geometry
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Statistics.html">
|
||||
Statistics
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="String.html">
|
||||
String
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Char.html">
|
||||
Char
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pattern.html">
|
||||
Pattern
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Array.html">
|
||||
Array
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="IO.html">
|
||||
IO
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="System.html">
|
||||
System
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Debug.html">
|
||||
Debug
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Test.html">
|
||||
Test
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Bench.html">
|
||||
Bench
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Map.html">
|
||||
Map
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Maybe.html">
|
||||
Maybe
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Result.html">
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<h1>
|
||||
Pointer
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#add">
|
||||
<h3 id="add">
|
||||
add
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a), Long] (Ptr a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>adds a long integer value to a pointer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
copy
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Ptr a) b)] (Ptr a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>copies a pointer <code>p</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dec">
|
||||
<h3 id="dec">
|
||||
dec
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a)] (Ptr a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dec a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#eq">
|
||||
<h3 id="eq">
|
||||
eq
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a), (Ptr a)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>checks two pointers for equality.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-long">
|
||||
<h3 id="from-long">
|
||||
from-long
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Long] (Ptr a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>converts a long integer to a pointer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#inc">
|
||||
<h3 id="inc">
|
||||
inc
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a)] (Ptr a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(inc a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#sub">
|
||||
<h3 id="sub">
|
||||
sub
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a), Long] (Ptr a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>subtracts a long integer value from a pointer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#to-long">
|
||||
<h3 id="to-long">
|
||||
to-long
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a)] Long)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>converts a pointer to a long integer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#to-ref">
|
||||
<h3 id="to-ref">
|
||||
to-ref
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a)] (Ref a StaticLifetime))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>converts a pointer to a reference type. The user will have to ensure themselves that this is a safe operation.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#width">
|
||||
<h3 id="width">
|
||||
width
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr a)] Long)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>gets the byte size of a pointer.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -151,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b)), (Ref (Result a b))] Bool)
|
||||
(λ [(Ref (Result a b) c), (Ref (Result a b) d)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -171,7 +181,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [b] (Result a b))
|
||||
(λ [a] (Result b a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -211,7 +221,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (λ [a] (Result c b))] (Result c b))
|
||||
(λ [(Result a b), (Ref (λ [a] (Result c b) d) e)] (Result c b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(and-then a f)
|
||||
@ -232,7 +242,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (λ [a] c), (λ [b] d)] (Result c d))
|
||||
(λ [(Result a b), (Ref (λ [a] c d) e), (Ref (λ [b] f d) g)] (Result c f))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(apply a success-f error-f)
|
||||
@ -252,7 +262,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b))] (Result a b))
|
||||
(λ [(Ref (Result a b) c)] (Result a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -292,7 +302,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b))] Bool)
|
||||
(λ [(Ref (Result a b) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(error? a)
|
||||
@ -341,6 +351,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#get-tag">
|
||||
<h3 id="get-tag">
|
||||
get-tag
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b) c)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>Gets the tag from a <code>Result</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#map">
|
||||
<h3 id="map">
|
||||
@ -351,7 +381,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (λ [a] c)] (Result c b))
|
||||
(λ [(Result a b), (Ref (λ [a] c d) e)] (Result c b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(map a f)
|
||||
@ -361,6 +391,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#map-error">
|
||||
<h3 id="map-error">
|
||||
map-error
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (Ref (λ [b] c d) e)] (Result a c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(map-error a f)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>takes a <code>Result</code> and applies a function <code>f</code> to it if it is an <code>Error</code> type, and wraps it back up. In the case that it is a <code>Success</code>, it is returned as is.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#or-else">
|
||||
<h3 id="or-else">
|
||||
@ -371,7 +421,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (λ [b] (Result a c))] (Result a c))
|
||||
(λ [(Result a b), (Ref (λ [b] (Result a c) d) e)] (Result a c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(or-else a f)
|
||||
@ -392,7 +442,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b))] String)
|
||||
(λ [(Ref (Result a b) c)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -412,7 +462,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b))] String)
|
||||
(λ [(Ref (Result a b) c)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -432,7 +482,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Result a b))] Bool)
|
||||
(λ [(Ref (Result a b) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(success? a)
|
||||
@ -514,7 +564,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Result a b), (λ [b] a)] a)
|
||||
(λ [(Result a b), (Ref (λ [b] a c) d)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(unwrap-or-else a f)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -170,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double)), Int] Double)
|
||||
(λ [(Ref (Array Double) a), Int] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(grouped-median data interval)
|
||||
@ -190,7 +200,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(high-median data)
|
||||
@ -210,7 +220,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(iqr data)
|
||||
@ -230,7 +240,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(low-median data)
|
||||
@ -250,7 +260,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array a))] a)
|
||||
(λ [(Ref (Array a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mean data)
|
||||
@ -270,7 +280,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(median data)
|
||||
@ -290,7 +300,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(pstdev data)
|
||||
@ -330,7 +340,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(pvariance data)
|
||||
@ -350,7 +360,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] (Array Double))
|
||||
(λ [(Ref (Array Double) a)] (Array Double))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(quartiles data)
|
||||
@ -370,7 +380,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(stdev data)
|
||||
@ -390,7 +400,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(stdev-pct data)
|
||||
@ -409,7 +419,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Summary)
|
||||
(λ [(Ref (Array Double) a)] Summary)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(summary samples)
|
||||
@ -429,7 +439,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Double))] Double)
|
||||
(λ [(Ref (Array Double) a)] Double)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(variance data)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,25 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#<">
|
||||
@ -170,7 +161,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -189,7 +180,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -208,7 +199,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -246,7 +237,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(alpha? s)
|
||||
@ -266,7 +257,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(alphanum? s)
|
||||
@ -286,7 +277,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] String)
|
||||
(λ [(Ref String a), (Ref String b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -305,7 +296,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int] Char)
|
||||
(λ [(Ref String a), Int] Char)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -324,7 +315,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Array Char))
|
||||
(λ [(Ref String a)] (Array Char))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -343,7 +334,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(chomp s)
|
||||
@ -363,7 +354,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(collapse-whitespace s)
|
||||
@ -383,7 +374,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array String))] String)
|
||||
(λ [(Ref (Array String) a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(concat strings)
|
||||
@ -403,7 +394,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Char] Bool)
|
||||
(λ [(Ref String a), Char] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(contains? s c)
|
||||
@ -423,7 +414,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Char] Int)
|
||||
(λ [(Ref String a), Char] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(count-char s c)
|
||||
@ -443,7 +434,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Ptr Char))
|
||||
(λ [(Ref String a)] (Ptr Char))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -462,7 +453,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(empty? s)
|
||||
@ -482,7 +473,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(ends-with? s sub)
|
||||
@ -502,7 +493,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] String)
|
||||
(λ [(Ref String a), (Ref String b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -521,7 +512,26 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array Char))] String)
|
||||
(λ [(Ref (Array Char) a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#from-cstr">
|
||||
<h3 id="from-cstr">
|
||||
from-cstr
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ptr Char)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -540,7 +550,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Int)
|
||||
(λ [(Ref String a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hash k)
|
||||
@ -559,7 +569,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Char)
|
||||
(λ [(Ref String a)] Char)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(head s)
|
||||
@ -579,7 +589,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(hex? s)
|
||||
@ -599,7 +609,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(in? s sub)
|
||||
@ -619,7 +629,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Char] Int)
|
||||
(λ [(Ref String a), Char] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -638,7 +648,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Char, Int] Int)
|
||||
(λ [(Ref String a), Char, Int] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -657,7 +667,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [String, (Ref (Array String))] String)
|
||||
(λ [(Ref String a), (Ref (Array String) b)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(join sep strings)
|
||||
@ -677,7 +687,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Char, (Ref (Array String))] String)
|
||||
(λ [Char, (Ref (Array String) a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(join-with-char sep strings)
|
||||
@ -697,7 +707,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Int)
|
||||
(λ [(Ref String a)] Int)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -716,7 +726,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Array String))
|
||||
(λ [(Ref String a)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(lines s)
|
||||
@ -736,7 +746,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(lower? s)
|
||||
@ -756,7 +766,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(num? s)
|
||||
@ -776,7 +786,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Char, &String] String)
|
||||
(λ [Int, Char, (Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(pad-left len pad s)
|
||||
@ -796,7 +806,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Char, &String] String)
|
||||
(λ [Int, Char, (Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(pad-right len pad s)
|
||||
@ -807,19 +817,19 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#prefix-string">
|
||||
<h3 id="prefix-string">
|
||||
prefix-string
|
||||
<a class="anchor" href="#prefix">
|
||||
<h3 id="prefix">
|
||||
prefix
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int] String)
|
||||
(λ [(Ref String a), Int] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(prefix-string s a)
|
||||
(prefix s a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Return the first <code>a</code> characters of the string <code>s</code>.</p>
|
||||
@ -836,7 +846,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -874,7 +884,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, &String] String)
|
||||
(λ [Int, (Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(repeat n inpt)
|
||||
@ -894,7 +904,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(reverse s)
|
||||
@ -904,6 +914,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#slice">
|
||||
<h3 id="slice">
|
||||
slice
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref String a), Int, Int] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(slice s a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#split-by">
|
||||
<h3 id="split-by">
|
||||
@ -914,7 +943,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, (Ref (Array Char))] (Array String))
|
||||
(λ [(Ref String a), (Ref (Array Char) b)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(split-by s separators)
|
||||
@ -934,7 +963,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, &String] Bool)
|
||||
(λ [(Ref String a), (Ref String b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(starts-with? s sub)
|
||||
@ -954,7 +983,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -973,7 +1002,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int, Char] ())
|
||||
(λ [(Ref String a), Int, Char] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -992,7 +1021,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int, &String] ())
|
||||
(λ [(Ref String a), Int, (Ref String b)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -1002,38 +1031,19 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#substring">
|
||||
<h3 id="substring">
|
||||
substring
|
||||
<a class="anchor" href="#suffix">
|
||||
<h3 id="suffix">
|
||||
suffix
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int, Int] String)
|
||||
(λ [(Ref String a), Int] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(substring s a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#suffix-string">
|
||||
<h3 id="suffix-string">
|
||||
suffix-string
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String, Int] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(suffix-string s b)
|
||||
(suffix s b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Return the last <code>b</code> characters of the string <code>s</code>.</p>
|
||||
@ -1050,7 +1060,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Array String))] Int)
|
||||
(λ [(Ref (Array String) a)] Int)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sum-length strings)
|
||||
@ -1070,7 +1080,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -1089,7 +1099,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(trim s)
|
||||
@ -1109,7 +1119,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(trim-left s)
|
||||
@ -1129,7 +1139,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] String)
|
||||
(λ [(Ref String a)] String)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(trim-right s)
|
||||
@ -1149,7 +1159,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] Bool)
|
||||
(λ [(Ref String a)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(upper? s)
|
||||
@ -1169,7 +1179,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] (Array String))
|
||||
(λ [(Ref String a)] (Array String))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(words s)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,6 +150,387 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EACCES">
|
||||
<h3 id="EACCES">
|
||||
EACCES
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EEXIST">
|
||||
<h3 id="EEXIST">
|
||||
EEXIST
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EINTR">
|
||||
<h3 id="EINTR">
|
||||
EINTR
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EINVAL">
|
||||
<h3 id="EINVAL">
|
||||
EINVAL
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EIO">
|
||||
<h3 id="EIO">
|
||||
EIO
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EISDIR">
|
||||
<h3 id="EISDIR">
|
||||
EISDIR
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ELOOP">
|
||||
<h3 id="ELOOP">
|
||||
ELOOP
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EMFILE">
|
||||
<h3 id="EMFILE">
|
||||
EMFILE
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENAMETOOLONG">
|
||||
<h3 id="ENAMETOOLONG">
|
||||
ENAMETOOLONG
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENOENT">
|
||||
<h3 id="ENOENT">
|
||||
ENOENT
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENOMEM">
|
||||
<h3 id="ENOMEM">
|
||||
ENOMEM
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENOSPC">
|
||||
<h3 id="ENOSPC">
|
||||
ENOSPC
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENOSR">
|
||||
<h3 id="ENOSR">
|
||||
ENOSR
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENOTDIR">
|
||||
<h3 id="ENOTDIR">
|
||||
ENOTDIR
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#ENXIO">
|
||||
<h3 id="ENXIO">
|
||||
ENXIO
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EOVERFLOW">
|
||||
<h3 id="EOVERFLOW">
|
||||
EOVERFLOW
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#EROFS">
|
||||
<h3 id="EROFS">
|
||||
EROFS
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#abort">
|
||||
<h3 id="abort">
|
||||
abort
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#carp-init-globals">
|
||||
<h3 id="carp-init-globals">
|
||||
carp-init-globals
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int, Int] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>Initializes all global variables (in correct order, based on interdependencies). Called automatically by <code>main</code> if the project is compiled as an executable. Client code needs to call this function manually when using a library written in Carp.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#errno">
|
||||
<h3 id="errno">
|
||||
errno
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
Int
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#exit">
|
||||
@ -190,7 +581,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [t] ())
|
||||
(λ [a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -210,7 +601,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int] &String)
|
||||
(λ [Int] (Ref String a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -461,7 +852,7 @@
|
||||
external
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [&String] ())
|
||||
(λ [(Ref String a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -170,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), a, a, &b] State)
|
||||
(λ [(Ref State a), b, b, (Ref c d)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-equal state x y descr)
|
||||
@ -190,7 +200,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), Int, (λ [] ()), &a] State)
|
||||
(λ [(Ref State a), Int, (λ [] () b), (Ref c d)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-exit state exit-code f descr)
|
||||
@ -210,7 +220,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), Bool, &a] State)
|
||||
(λ [(Ref State a), Bool, (Ref b c)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-false state x descr)
|
||||
@ -230,7 +240,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), a, a, &b] State)
|
||||
(λ [(Ref State a), b, b, (Ref c d)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-not-equal state x y descr)
|
||||
@ -250,7 +260,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), a, b, &c, (λ [a, b] Bool)] State)
|
||||
(λ [(Ref State a), b, c, (Ref d e), (λ [b, c] Bool f)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-op state x y descr op)
|
||||
@ -270,7 +280,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), Int, (λ [] ()), &a] State)
|
||||
(λ [(Ref State a), Int, (λ [] () b), (Ref c d)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-signal state signal x descr)
|
||||
@ -289,7 +299,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State), Bool, &a] State)
|
||||
(λ [(Ref State a), Bool, (Ref b c)] State)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(assert-true state x descr)
|
||||
@ -309,7 +319,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref State)] ())
|
||||
(λ [(Ref State a)] ())
|
||||
</p>
|
||||
<pre class="args">
|
||||
(print-test-results state)
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,25 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, a] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
@ -170,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -189,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] (Vector2 a))
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add a b)
|
||||
@ -208,13 +199,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Double)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(angle-between a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Get the angle between to vectors a and b.</p>
|
||||
<p>Get the angle between two vectors a and b.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -228,7 +219,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(anti-parallel? a b)
|
||||
@ -238,26 +229,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#approx">
|
||||
<h3 id="approx">
|
||||
approx
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(approx a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Check whether the vectors a and b are approximately equal.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
@ -268,7 +239,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] (Vector2 a))
|
||||
(λ [(Ref (Vector2 a) b)] (Vector2 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -308,7 +279,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Double)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dist a b)
|
||||
@ -328,7 +299,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), a] (Vector2 a))
|
||||
(λ [(Ref (Vector2 a) b), a] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(div a n)
|
||||
@ -347,7 +318,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] a)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dot a b)
|
||||
@ -367,7 +338,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double))] Double)
|
||||
(λ [(Ref (Vector2 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(heading a)
|
||||
@ -397,26 +368,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#lerp">
|
||||
<h3 id="lerp">
|
||||
lerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), (Ref (Vector2 a)), a] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(lerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mag">
|
||||
<h3 id="mag">
|
||||
@ -427,7 +378,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double))] Double)
|
||||
(λ [(Ref (Vector2 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag o)
|
||||
@ -447,7 +398,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] a)
|
||||
(λ [(Ref (Vector2 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag-sq o)
|
||||
@ -457,6 +408,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#map">
|
||||
<h3 id="map">
|
||||
map
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a] b c), (Ref (Vector2 a) d)] (Vector2 b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(map f v)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mul">
|
||||
<h3 id="mul">
|
||||
@ -467,7 +437,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), a] (Vector2 a))
|
||||
(λ [(Ref (Vector2 a) b), a] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mul a n)
|
||||
@ -486,7 +456,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double))] (Vector2 Double))
|
||||
(λ [(Ref (Vector2 a) b)] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(normalize o)
|
||||
@ -506,7 +476,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(parallel? a b)
|
||||
@ -526,7 +496,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(perpendicular? a b)
|
||||
@ -546,7 +516,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] String)
|
||||
(λ [(Ref (Vector2 a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -566,7 +536,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] (Vector2 Double))
|
||||
(λ [] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(random)
|
||||
@ -585,7 +555,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 Double)), Double] (Vector2 Double))
|
||||
(λ [(Ref (Vector2 a) b), a] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(rotate a n)
|
||||
@ -622,10 +592,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), a] ())
|
||||
(λ [(Ref (Vector2 a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -662,10 +632,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), a] ())
|
||||
(λ [(Ref (Vector2 a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -685,7 +655,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] String)
|
||||
(λ [(Ref (Vector2 a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -705,7 +675,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] (Vector2 a))
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sub a b)
|
||||
@ -714,6 +684,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#sum">
|
||||
<h3 id="sum">
|
||||
sum
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sum o)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#update-x">
|
||||
<h3 id="update-x">
|
||||
@ -724,7 +713,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Vector2 a), (Ref (λ [a] a))] (Vector2 a))
|
||||
(λ [(Vector2 a), (Ref (λ [a] a b) c)] (Vector2 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -744,7 +733,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Vector2 a), (Ref (λ [a] a))] (Vector2 a))
|
||||
(λ [(Vector2 a), (Ref (λ [a] a b) c)] (Vector2 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -754,6 +743,65 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vapprox">
|
||||
<h3 id="vapprox">
|
||||
vapprox
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vapprox a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Check whether the vectors a and b are approximately equal.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vlerp">
|
||||
<h3 id="vlerp">
|
||||
vlerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a) b), (Ref (Vector2 a) c), a] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vlerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vreduce">
|
||||
<h3 id="vreduce">
|
||||
vreduce
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] a c), a, (Ref (Vector2 b) d)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vreduce f i v)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#x">
|
||||
<h3 id="x">
|
||||
@ -764,7 +812,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] &a)
|
||||
(λ [(Ref (Vector2 a) b)] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -784,7 +832,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector2 a))] &a)
|
||||
(λ [(Ref (Vector2 a) b)] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -804,13 +852,32 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] (Vector2 Double))
|
||||
(λ [] (Vector2 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zip">
|
||||
<h3 id="zip">
|
||||
zip
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] c d), (Ref (Vector2 a) e), (Ref (Vector2 b) f)] (Vector2 c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip f a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,25 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, a] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
@ -170,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -189,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add a b)
|
||||
@ -208,13 +199,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Double)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(angle-between a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Get the angle between to vectors a and b.</p>
|
||||
<p>Get the angle between two vectors a and b.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -228,7 +219,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(anti-parallel? a b)
|
||||
@ -238,6 +229,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#cmul">
|
||||
<h3 id="cmul">
|
||||
cmul
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(cmul a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#copy">
|
||||
<h3 id="copy">
|
||||
@ -248,7 +258,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b)] (Vector3 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -268,7 +278,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(cross a b)
|
||||
@ -298,6 +308,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dist">
|
||||
<h3 id="dist">
|
||||
dist
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dist a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Get the distance between the vectors a and b.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#div">
|
||||
<h3 id="div">
|
||||
@ -308,10 +338,10 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), a] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b), a] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(div a n)
|
||||
(div v n)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
@ -327,7 +357,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] a)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dot a b)
|
||||
@ -357,26 +387,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#lerp">
|
||||
<h3 id="lerp">
|
||||
lerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), (Ref (Vector3 a)), a] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(lerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mag">
|
||||
<h3 id="mag">
|
||||
@ -387,7 +397,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double))] Double)
|
||||
(λ [(Ref (Vector3 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag o)
|
||||
@ -407,7 +417,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] a)
|
||||
(λ [(Ref (Vector3 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag-sq o)
|
||||
@ -417,6 +427,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#map">
|
||||
<h3 id="map">
|
||||
map
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a] b c), (Ref (Vector3 a) d)] (Vector3 b))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(map f v)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mul">
|
||||
<h3 id="mul">
|
||||
@ -427,10 +456,29 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), a] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b), a] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mul a n)
|
||||
(mul v n)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#neg">
|
||||
<h3 id="neg">
|
||||
neg
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(neg a)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
@ -446,7 +494,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double))] (Vector3 Double))
|
||||
(λ [(Ref (Vector3 a) b)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(normalize o)
|
||||
@ -466,7 +514,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(parallel? a b)
|
||||
@ -486,7 +534,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(perpendicular? a b)
|
||||
@ -506,7 +554,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] String)
|
||||
(λ [(Ref (Vector3 a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -526,7 +574,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] (Vector3 Double))
|
||||
(λ [] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(random)
|
||||
@ -562,10 +610,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), a] ())
|
||||
(λ [(Ref (Vector3 a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -602,10 +650,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), a] ())
|
||||
(λ [(Ref (Vector3 a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -642,10 +690,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), a] ())
|
||||
(λ [(Ref (Vector3 a) b), a] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -665,7 +713,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] String)
|
||||
(λ [(Ref (Vector3 a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -685,7 +733,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] (Vector3 a))
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sub a b)
|
||||
@ -694,6 +742,25 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#sum">
|
||||
<h3 id="sum">
|
||||
sum
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sum o)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#update-x">
|
||||
<h3 id="update-x">
|
||||
@ -704,7 +771,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
|
||||
(λ [(Vector3 a), (Ref (λ [a] a b) c)] (Vector3 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -724,7 +791,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
|
||||
(λ [(Vector3 a), (Ref (λ [a] a b) c)] (Vector3 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -744,7 +811,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
|
||||
(λ [(Vector3 a), (Ref (λ [a] a b) c)] (Vector3 a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -754,6 +821,65 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vapprox">
|
||||
<h3 id="vapprox">
|
||||
vapprox
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vapprox a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Check whether the vectors a and b are approximately equal.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vlerp">
|
||||
<h3 id="vlerp">
|
||||
vlerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a) b), (Ref (Vector3 a) c), a] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vlerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vreduce">
|
||||
<h3 id="vreduce">
|
||||
vreduce
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] a c), a, (Ref (Vector3 b) d)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vreduce f i v)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#x">
|
||||
<h3 id="x">
|
||||
@ -764,7 +890,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] &a)
|
||||
(λ [(Ref (Vector3 a) b)] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -784,7 +910,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] &a)
|
||||
(λ [(Ref (Vector3 a) b)] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -804,7 +930,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (Vector3 a))] &a)
|
||||
(λ [(Ref (Vector3 a) b)] (Ref a b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -824,13 +950,32 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [] (Vector3 Double))
|
||||
(λ [] (Vector3 a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zip">
|
||||
<h3 id="zip">
|
||||
zip
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] c d), (Ref (Vector3 a) e), (Ref (Vector3 b) f)] (Vector3 c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip f a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -27,6 +27,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -132,6 +137,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@ -140,25 +150,6 @@
|
||||
</h1>
|
||||
<div class="module-description">
|
||||
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#/=">
|
||||
<h3 id="/=">
|
||||
/=
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, a] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(/= a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#=">
|
||||
@ -170,7 +161,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), (Ref (VectorN a))] Bool)
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) b)] Bool)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(= a b)
|
||||
@ -189,7 +180,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe (VectorN a)))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) c)] (Maybe (VectorN a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(add a b)
|
||||
@ -208,13 +199,13 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) b)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(angle-between a b)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Get the angle between to vectors a and b.</p>
|
||||
<p>Get the angle between two vectors a and b.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -228,7 +219,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) b)] (Maybe Bool))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(anti-parallel? a b)
|
||||
@ -248,7 +239,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a))] (VectorN a))
|
||||
(λ [(Ref (VectorN a) b)] (VectorN a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -288,7 +279,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) c)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dist a b)
|
||||
@ -308,7 +299,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), a] (VectorN a))
|
||||
(λ [(Ref (VectorN a) b), a] (VectorN a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(div a n)
|
||||
@ -327,7 +318,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) c)] (Maybe a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dot x y)
|
||||
@ -357,26 +348,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#lerp">
|
||||
<h3 id="lerp">
|
||||
lerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), (Ref (VectorN a)), a] (Maybe (VectorN a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(lerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#mag">
|
||||
<h3 id="mag">
|
||||
@ -387,7 +358,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double))] Double)
|
||||
(λ [(Ref (VectorN a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag o)
|
||||
@ -407,7 +378,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double))] Double)
|
||||
(λ [(Ref (VectorN a) b)] a)
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mag-sq o)
|
||||
@ -427,7 +398,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), a] (VectorN a))
|
||||
(λ [(Ref (VectorN a) b), a] (VectorN a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(mul a n)
|
||||
@ -446,7 +417,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a))] &Int)
|
||||
(λ [(Ref (VectorN a) b)] (Ref Int b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -466,7 +437,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double))] (VectorN Double))
|
||||
(λ [(Ref (VectorN a) b)] (VectorN a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(normalize o)
|
||||
@ -486,7 +457,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) b)] (Maybe Bool))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(parallel? a b)
|
||||
@ -506,7 +477,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) b)] (Maybe Bool))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(perpendicular? a b)
|
||||
@ -526,7 +497,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a))] String)
|
||||
(λ [(Ref (VectorN a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -546,7 +517,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int] (VectorN Double))
|
||||
(λ [Int] (VectorN a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(random-sized n)
|
||||
@ -585,7 +556,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), Int] ())
|
||||
(λ [(Ref (VectorN a) b), Int] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -622,10 +593,10 @@
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
instantiate
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), (Array a)] ())
|
||||
(λ [(Ref (VectorN a) b), (Array a)] ())
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -645,7 +616,7 @@
|
||||
template
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a))] String)
|
||||
(λ [(Ref (VectorN a) b)] String)
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -665,7 +636,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe (VectorN a)))
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) c)] (Maybe (VectorN a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(sub a b)
|
||||
@ -684,7 +655,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(VectorN a), (Ref (λ [Int] Int))] (VectorN a))
|
||||
(λ [(VectorN a), (Ref (λ [Int] Int b) c)] (VectorN a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -704,7 +675,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(VectorN a), (Ref (λ [(Array a)] (Array a)))] (VectorN a))
|
||||
(λ [(VectorN a), (Ref (λ [(Array a)] (Array a) b) c)] (VectorN a))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -724,7 +695,7 @@
|
||||
instantiate
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a))] (Ref (Array a)))
|
||||
(λ [(Ref (VectorN a) b)] (Ref (Array a) b))
|
||||
</p>
|
||||
<span>
|
||||
|
||||
@ -734,6 +705,26 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#vlerp">
|
||||
<h3 id="vlerp">
|
||||
vlerp
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(Ref (VectorN a) b), (Ref (VectorN a) c), a] (Maybe (VectorN a)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(vlerp a b amnt)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#zero-sized">
|
||||
<h3 id="zero-sized">
|
||||
@ -744,7 +735,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [Int] (VectorN Double))
|
||||
(λ [Int] (VectorN a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zero-sized n)
|
||||
@ -763,7 +754,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] c), (Ref (VectorN a)), (Ref (VectorN b))] (Maybe (VectorN c)))
|
||||
(λ [(λ [a, b] c d), (Ref (VectorN a) e), (Ref (VectorN b) f)] (Maybe (VectorN c)))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip f a b)
|
||||
@ -782,7 +773,7 @@
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [(λ [a, b] c), (Ref (Array a)), (Ref (Array b))] (VectorN c))
|
||||
(λ [(λ [a, b] c d), (Ref (Array a) e), (Ref (Array b) f)] (VectorN c))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(zip- f a b)
|
||||
|
@ -23,6 +23,11 @@
|
||||
Int
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Byte.html">
|
||||
Byte
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Long.html">
|
||||
Long
|
||||
@ -128,6 +133,11 @@
|
||||
Result
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="Pointer.html">
|
||||
Pointer
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user