mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-11 20:49:05 +03:00
and binop, *-macros
This commit is contained in:
parent
43fd972ef5
commit
05efae290d
14
LIBRARIES.md
Normal file
14
LIBRARIES.md
Normal file
@ -0,0 +1,14 @@
|
||||
# Core Libraries
|
||||
See ```lisp/core.carp```
|
||||
|
||||
# GL
|
||||
See ```lisp/gl.carp```
|
||||
|
||||
# The '*' macros
|
||||
Since the functions in Carp can't accept a variable number of args there are a bunch of helper macros that allows you to circumvent this limitation. Here are some examples:
|
||||
|
||||
```clojure
|
||||
(str* "This string " "and this string, here's a number " 123 ", etc...")
|
||||
(println* "X = " x ", Y = " y)
|
||||
(and* true false false true false)
|
||||
```
|
2
TODO.md
2
TODO.md
@ -34,7 +34,7 @@
|
||||
- Macro splicing
|
||||
- Modules
|
||||
- A Set-type with reader syntax #{}
|
||||
- Instantiate generic functions like '=' for primitive types
|
||||
- Instantiate generic functions like '=' for primitive types when calling them
|
||||
|
||||
## Modules
|
||||
- Name
|
||||
|
@ -5,6 +5,19 @@
|
||||
;;(reset! log-deps-when-baking-ast true)
|
||||
|
||||
|
||||
;; (defn and-internal [forms]
|
||||
;; (match forms
|
||||
;; (a b) (list 'and-binary a b)
|
||||
;; (a ... xs) (list 'and-binary a (and-internal xs))))
|
||||
|
||||
;; (defmacro and* [... forms]
|
||||
;; (and-internal forms))
|
||||
|
||||
;; (defn use-and []
|
||||
;; (if (and* true true false true)
|
||||
;; @"YES"
|
||||
;; @"NO"))
|
||||
|
||||
;; (bake use-and)
|
||||
|
||||
|
||||
;;(tester/run-suite "")
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
(defn binop? [form]
|
||||
(match form
|
||||
(x ... _) (contains? '(+ - * / <) x)
|
||||
(x ... _) (contains? '(+ - * / < and) x)
|
||||
_ false))
|
||||
|
||||
(defn gen-fn-type [arg-count]
|
||||
@ -42,7 +42,9 @@
|
||||
(if (binop? l)
|
||||
(match l
|
||||
(op left right) {:node :binop
|
||||
:type (gen-typevar)
|
||||
:type (if (= op 'and)
|
||||
:bool
|
||||
(gen-typevar))
|
||||
:op op
|
||||
:left (form-to-ast left)
|
||||
:right (form-to-ast right)})
|
||||
|
@ -3,6 +3,7 @@
|
||||
;; (reset! profile-infer-time true)
|
||||
;; (reset! profile-external-compiler-time true)
|
||||
|
||||
(load-lisp (str carp-dir "lisp/test_binops.carp"))
|
||||
(load-lisp (str carp-dir "lisp/test_printing.carp"))
|
||||
(load-lisp (str carp-dir "lisp/test_equality.carp"))
|
||||
(load-lisp (str carp-dir "lisp/test_globals.carp"))
|
||||
|
17
lisp/test_binops.carp
Normal file
17
lisp/test_binops.carp
Normal file
@ -0,0 +1,17 @@
|
||||
(tester/set-suite! "binops")
|
||||
|
||||
(deftest test-and-1
|
||||
(do
|
||||
(defn use-and-1 []
|
||||
(and true false))
|
||||
(bake use-and-1)
|
||||
(assert-eq false (use-and-1))))
|
||||
|
||||
(deftest test-and-2
|
||||
(do
|
||||
(defn use-and-2 []
|
||||
(and true true))
|
||||
(bake use-and-2)
|
||||
(assert-eq true (use-and-2))))
|
||||
|
||||
(tester/run-suite "binops")
|
@ -9,6 +9,8 @@
|
||||
#include "types.h"
|
||||
#include "platform.h"
|
||||
|
||||
#define and &&
|
||||
|
||||
#ifdef WIN32
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user