mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
all: use dynor and dynand
This commit is contained in:
parent
10a76a20fc
commit
a761b561e3
@ -15,12 +15,6 @@
|
||||
(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 "Macros.carp")
|
||||
@ -52,3 +46,10 @@
|
||||
(load "Sort.carp")
|
||||
(load "Binary.carp")
|
||||
(load "Control.carp")
|
||||
|
||||
(if (not (dynor (= "windows" (os)) (= "mingw32" (os))))
|
||||
(do
|
||||
(system-include "sys/wait.h")
|
||||
(system-include "unistd.h"))
|
||||
())
|
||||
|
||||
|
@ -170,7 +170,7 @@
|
||||
;; commands expand to (command <name>), fns expand to a non-list.
|
||||
;;
|
||||
;; TODO: Support passing anonymous functions.
|
||||
(if (not (Dynamic.or (list? f) (list? g)))
|
||||
(if (not (dynor (list? f) (list? g)))
|
||||
(macro-error "compose can only compose named dynamic functions. To
|
||||
compose anonymous functions, such as curried functions,
|
||||
see comp.")
|
||||
@ -183,14 +183,10 @@
|
||||
;; symbols such as '(p r a c)
|
||||
(list f-name (list 'eval (list 'apply g-name (list 'quote arguments))))))))
|
||||
|
||||
;; Dynamic.or already exists, but since it's a special form, it can't be passed
|
||||
;; to higher order functions like reduce. So, we define an alternative here.
|
||||
(defndynamic or-internal [x y]
|
||||
(defndynamic dynor [x y]
|
||||
(if x true y))
|
||||
|
||||
;; Dynamic.and already exists, but since it's a special form, it can't be passed
|
||||
;; to higher order functions like reduce. So, we define an alternative here.
|
||||
(defndynamic and-internal [x y]
|
||||
(defndynamic dynand [x y]
|
||||
(if x y false))
|
||||
|
||||
(doc curry
|
||||
@ -255,7 +251,7 @@
|
||||
(defndynamic unreduce-internal [f x lim acc counter]
|
||||
;; Currently only works with anonymous functions and named functions.
|
||||
;; does not work with commands.
|
||||
(if (not (Dynamic.or (array? acc) (list? acc)))
|
||||
(if (not (dynor (array? acc) (list? acc)))
|
||||
(macro-error
|
||||
"Unreduce requires a dynamic data structure to collect results, such as
|
||||
(list) or (array).")
|
||||
@ -372,7 +368,7 @@
|
||||
|
||||
(hidden zip-internal)
|
||||
(defndynamic zip-internal [f forms acc]
|
||||
(if (reduce or-internal false (map-internal empty? forms (list)))
|
||||
(if (reduce dynor false (map-internal empty? forms (list)))
|
||||
acc
|
||||
(zip-internal
|
||||
f
|
||||
@ -537,12 +533,12 @@
|
||||
()))
|
||||
|
||||
(defmacro windows-only [:rest forms]
|
||||
(if (Dynamic.or (= "windows" (os)) (= "mingw32" (os)))
|
||||
(if (dynor (= "windows" (os)) (= "mingw32" (os)))
|
||||
(eval (cons (quote do) forms))
|
||||
()))
|
||||
|
||||
(defmacro not-on-windows [:rest forms]
|
||||
(if (not (Dynamic.or (= "windows" (os)) (= "mingw32" (os))))
|
||||
(if (not (dynor (= "windows" (os)) (= "mingw32" (os))))
|
||||
(eval (cons (quote do) forms))
|
||||
()))
|
||||
|
||||
|
@ -366,25 +366,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#and-internal">
|
||||
<h3 id="and-internal">
|
||||
and-internal
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(and-internal x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#append">
|
||||
<h3 id="append">
|
||||
@ -1148,6 +1129,25 @@ in the list as an argument to the function.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#column">
|
||||
<h3 id="column">
|
||||
column
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#compose">
|
||||
<h3 id="compose">
|
||||
@ -1328,6 +1328,177 @@ and then to the following argument.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#defdynamic">
|
||||
<h3 id="defdynamic">
|
||||
defdynamic
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#defined?">
|
||||
<h3 id="defined?">
|
||||
defined?
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#definterface">
|
||||
<h3 id="definterface">
|
||||
definterface
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#defmacro">
|
||||
<h3 id="defmacro">
|
||||
defmacro
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#defmodule">
|
||||
<h3 id="defmodule">
|
||||
defmodule
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#defndynamic">
|
||||
<h3 id="defndynamic">
|
||||
defndynamic
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#deftype">
|
||||
<h3 id="deftype">
|
||||
deftype
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dynand">
|
||||
<h3 id="dynand">
|
||||
dynand
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dynand x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#dynor">
|
||||
<h3 id="dynor">
|
||||
dynor
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(dynor x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#e">
|
||||
<h3 id="e">
|
||||
@ -1415,6 +1586,25 @@ and then to the following argument.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#eval">
|
||||
<h3 id="eval">
|
||||
eval
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#eval-internal">
|
||||
<h3 id="eval-internal">
|
||||
@ -1472,6 +1662,25 @@ and then to the following argument.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#file">
|
||||
<h3 id="file">
|
||||
file
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#filter">
|
||||
<h3 id="filter">
|
||||
@ -1564,6 +1773,25 @@ and then to the following argument.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#info">
|
||||
<h3 id="info">
|
||||
info
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#last">
|
||||
<h3 id="last">
|
||||
@ -1602,6 +1830,25 @@ and then to the following argument.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#line">
|
||||
<h3 id="line">
|
||||
line
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list">
|
||||
<h3 id="list">
|
||||
@ -1746,6 +1993,63 @@ applications.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#members">
|
||||
<h3 id="members">
|
||||
members
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#meta">
|
||||
<h3 id="meta">
|
||||
meta
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#meta-set!">
|
||||
<h3 id="meta-set!">
|
||||
meta-set!
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#no-echo">
|
||||
<h3 id="no-echo">
|
||||
@ -1823,25 +2127,6 @@ applications.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#or-internal">
|
||||
<h3 id="or-internal">
|
||||
or-internal
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(or-internal x y)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#os">
|
||||
<h3 id="os">
|
||||
@ -1899,6 +2184,25 @@ applications.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#quote">
|
||||
<h3 id="quote">
|
||||
quote
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#quoted">
|
||||
<h3 id="quoted">
|
||||
@ -1958,6 +2262,44 @@ value through successive applications of <code>f</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#register">
|
||||
<h3 id="register">
|
||||
register
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#register-type">
|
||||
<h3 id="register-type">
|
||||
register-type
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#relative-include">
|
||||
<h3 id="relative-include">
|
||||
@ -2145,6 +2487,25 @@ value through successive applications of <code>f</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#type">
|
||||
<h3 id="type">
|
||||
type
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unreduce">
|
||||
<h3 id="unreduce">
|
||||
@ -2174,6 +2535,25 @@ Collects results in the structure given by <code>acc</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#use">
|
||||
<h3 id="use">
|
||||
use
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#write-file">
|
||||
<h3 id="write-file">
|
||||
|
@ -126,6 +126,7 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
|
||||
External _ -> error (show (CannotEmitExternal xobj))
|
||||
ExternalType -> error (show (DontVisitObj xobj))
|
||||
e@(Command _) -> error (show (DontVisitObj xobj))
|
||||
e@(Primitive _) -> error (show (DontVisitObj xobj))
|
||||
e@(Deftemplate _) -> error (show (DontVisitObj xobj))
|
||||
e@(Instantiate _) -> error (show (DontVisitObj xobj))
|
||||
e@(Defalias _) -> error (show (DontVisitObj xobj))
|
||||
@ -497,6 +498,10 @@ toC toCMode (Binder meta root) = emitterSrc (execState (visit startingIndent roo
|
||||
XObj (Command _) _ _ : _ ->
|
||||
return ""
|
||||
|
||||
-- Primitive
|
||||
XObj (Primitive _) _ _ : _ ->
|
||||
return ""
|
||||
|
||||
-- Interface
|
||||
XObj (Interface _ _) _ _ : _ ->
|
||||
return ""
|
||||
@ -766,6 +771,8 @@ toDeclaration (Binder meta xobj@(XObj (Lst xobjs) _ t)) =
|
||||
""
|
||||
XObj (Command _) _ _ : _ ->
|
||||
""
|
||||
XObj (Primitive _) _ _ : _ ->
|
||||
""
|
||||
_ -> error ("Internal compiler error: Can't emit other kinds of definitions: " ++ show xobj)
|
||||
toDeclaration _ = error "Missing case."
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
(defndynamic _make-exe-path [pth]
|
||||
(let [out (Project.get-config "output-directory")
|
||||
sep (if (Dynamic.or (= (os) "windows") (= (os) "mingw32")) "\\" "/")
|
||||
sep (if (dynor (= (os) "windows") (= (os) "mingw32")) "\\" "/")
|
||||
lst (Dynamic.String.suffix out (- (String.length out) 1))]
|
||||
(Dynamic.String.concat (array out (if (= lst sep) "" sep) pth))))
|
||||
|
||||
|
@ -34,8 +34,8 @@
|
||||
1 true
|
||||
false))
|
||||
|
||||
(defmacro test-and [a b] (Dynamic.and a b))
|
||||
(defmacro test-or [a b] (Dynamic.or a b))
|
||||
(defmacro test-and [a b] (dynand a b))
|
||||
(defmacro test-or [a b] (dynor a b))
|
||||
(defmacro test-not [a] (not a))
|
||||
(defmacro test-< [a b] (< a b))
|
||||
(defmacro test-> [a b] (> a b))
|
||||
@ -60,12 +60,12 @@
|
||||
|
||||
(defmacro test-map []
|
||||
(let [mapped (Dynamic.map length '((a) (b c) (d e f)))]
|
||||
(Dynamic.and (Dynamic.and (= 1 (Dynamic.car mapped)) (= 2 (Dynamic.cadr mapped))) (= 3
|
||||
(dynand (dynand (= 1 (Dynamic.car mapped)) (= 2 (Dynamic.cadr mapped))) (= 3
|
||||
(Dynamic.caddr mapped)))))
|
||||
|
||||
(defmacro test-zip []
|
||||
(let [zipped (Dynamic.zip array '('a 'd) '('c 'o) '('e 'g))]
|
||||
(Dynamic.and (= 'ace (Symbol.concat (eval (Dynamic.car zipped))))
|
||||
(dynand (= 'ace (Symbol.concat (eval (Dynamic.car zipped))))
|
||||
(= 'dog (Symbol.concat (eval (Dynamic.cadr zipped)))))))
|
||||
|
||||
(defmacro test-curry []
|
||||
@ -81,12 +81,12 @@
|
||||
(= 10 (Dynamic.reduce + 0 '(1 2 3 4))))
|
||||
|
||||
(defmacro test-unreduce []
|
||||
(Dynamic.reduce Dynamic.and-internal true
|
||||
(Dynamic.reduce dynand true
|
||||
(Dynamic.map 'eval
|
||||
(Dynamic.zip = '(1 2 3 4) (Dynamic.unreduce (curry + 1) 0 4 (list))))))
|
||||
|
||||
(defmacro test-filter []
|
||||
(Dynamic.reduce Dynamic.and-internal true
|
||||
(Dynamic.reduce dynand true
|
||||
(Dynamic.map 'eval
|
||||
(Dynamic.zip = '('a 'a 'a 'a)
|
||||
(Dynamic.map Dynamic.quoted
|
||||
@ -95,17 +95,17 @@
|
||||
(defmacro test-empty []
|
||||
;; We can't compare '[] and '[] for some reason.
|
||||
;; But '() and '() are comparable
|
||||
(Dynamic.and (= '() (Dynamic.empty '(1 2 3 4)))
|
||||
(dynand (= '() (Dynamic.empty '(1 2 3 4)))
|
||||
(empty? (Dynamic.empty '[1 2 3 4]))))
|
||||
|
||||
(defmacro test-reverse []
|
||||
(Dynamic.reduce Dynamic.and-internal true
|
||||
(Dynamic.reduce dynand true
|
||||
(Dynamic.map 'eval
|
||||
(Dynamic.zip = '(4 3 2 1) (Dynamic.reverse '(1 2 3 4))))))
|
||||
|
||||
(defmacro test-take []
|
||||
(let [result (Dynamic.take 2 '(1 2 3 4))]
|
||||
(Dynamic.and (= 1 (car result ))
|
||||
(dynand (= 1 (car result ))
|
||||
(= '() (cddr result)))))
|
||||
|
||||
(deftest test
|
||||
|
Loading…
Reference in New Issue
Block a user