Skip to content

Commit

Permalink
Minor edits for def
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Aug 6, 2024
1 parent e18bdb8 commit d347b20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions convex-core/src/main/cvx/convex/core.cvx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@
(empty? decl) (fail :ARITY "`defn` requires at least one function definition"))
(let [fnform (cons 'fn
decl)
name (syntax name (meta (first decl)))] ;; Note: merges in metadata on parameter list
`(def ~name ~fnform)))
nf (syntax name (meta (first decl)))] ;; Note: merges in metadata on parameter list
(eval `(def ~name)) ;; ensure we have a forward declaration at expand time
`(def ~nf ~fnform)))

(defn identity
^{:doc {:description "An identity function which returns its first argument unchanged."
Expand Down
16 changes: 8 additions & 8 deletions convex-core/src/test/java/convex/core/lang/CompilerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public void testConstantCompilation() {


@Test public void testDef() {
assertEquals(2L,evalL("(do (def a 2) (def b 3) a)"));
assertEquals(7L,evalL("(do (def a 2) (def a 7) a)"));
assertEquals(9L,evalL("(do (def a 9) (def a) a)"));
assertEquals(9L,evalL("(do (def a) (def a 9) a)"));
assertCVMEquals(2L,eval("(do (def a 2) (def b 3) a)"));
assertCVMEquals(7L,eval("(do (def a 2) (def a 7) a)"));
assertCVMEquals(9L,eval("(do (def a 9) (def a) a)"));
assertCVMEquals(9L,eval("(do (def a) (def a 9) a)"));
assertNull(eval("(do (def a 9) (def a nil) a)"));

// TODO: check if these are most logical error types?
Expand All @@ -205,11 +205,11 @@ public void testConstantCompilation() {
}

@Test public void testDefOverCore() {
// TODO consider better compilation unit handling in static case
if (!Constants.OPT_STATIC) {
assertEquals(13L,evalL("(do (def count 13) count)"));
// TODO: This might not be sane?
if (Constants.OPT_STATIC) {
assertCVMEquals(Core.COUNT,eval("(do (def count 13) count)"));
} else {
assertEquals(Core.COUNT,eval("(do (def count 13) count)"));
assertCVMEquals(13L,eval("(do (def count 13) count)"));
}
}

Expand Down

0 comments on commit d347b20

Please sign in to comment.