mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
BUGFIX: Can't define '=' in terms of '=' on generic members of type, see Pair.=
This commit is contained in:
parent
bcd4e6d298
commit
275947dc35
@ -4,9 +4,8 @@
|
||||
(defn init-from-refs [r1 r2]
|
||||
(Pair.init @r1 @r2))
|
||||
|
||||
;; BUG: Can't define this function because = resolves to Pair.= in the body.
|
||||
;; (defn = [p1 p2]
|
||||
;; (and (= (Pair.a p1) (Pair.a p2))
|
||||
;; (= (Pair.b p1) (Pair.b p2))))
|
||||
(defn = [p1 p2]
|
||||
(and (= (Pair.a p1) (Pair.a p2))
|
||||
(= (Pair.b p1) (Pair.b p2))))
|
||||
|
||||
)
|
||||
|
@ -8,7 +8,6 @@
|
||||
** 0.3
|
||||
*** References must keep track of their origin and prevent usage of them if the origin has been given away.
|
||||
Currently it's possible to set a ref so it points to a value in a more short-lived scope, leads to 'stack-use-after-scope' error in clang-sanitizer.
|
||||
*** Can't define '=' in terms of '=' on generic members of type, see Pair.=
|
||||
* Big Language Features
|
||||
** 1.0
|
||||
*** Lambdas (anonymous functions) that compile on Windows and don't leak memory!
|
||||
|
@ -45,8 +45,12 @@
|
||||
;; (set! r &xs))
|
||||
;; (println* r)))
|
||||
|
||||
;; Resolves to wrong thing
|
||||
;; '=' resolves to wrong thing
|
||||
(deftype (Foo t) [x t])
|
||||
(defmodule Foo
|
||||
(defn = [a b]
|
||||
(= (Foo.x a) (Foo.x b))))
|
||||
|
||||
(defn main []
|
||||
(do (println* (= &(Foo.init 123) &(Foo.init 666)))
|
||||
(println* (= &(Foo.init 123) &(Foo.init 123)))))
|
||||
|
@ -7,8 +7,6 @@
|
||||
(defn construct-from-ref [r]
|
||||
(Trivial.init @r))
|
||||
|
||||
(deftype (Pair a b) [x a y b])
|
||||
|
||||
;; Simplified dictionary:
|
||||
(deftype (Entry a b) [key a value b])
|
||||
(deftype (Bucket a b) [entries (Array (Entry a b))])
|
||||
@ -40,8 +38,8 @@
|
||||
(IO.println &(str &(Pair.init 10 @"hello")))
|
||||
(IO.println &(str &(Pair.init true 3.2)))
|
||||
(IO.println &(str &(Pair.init [1 2 3] [true false true false])))
|
||||
(IO.println &(str &(Pair.update-x (Pair.init 100 100) Int.inc)))
|
||||
(IO.println &(str &(Pair.set-y (Pair.init 100 100) 200)))
|
||||
(IO.println &(str @(Pair.x &(Pair.init 100 100))))
|
||||
(IO.println &(str &(Pair.update-a (Pair.init 100 100) Int.inc)))
|
||||
(IO.println &(str &(Pair.set-b (Pair.init 100 100) 200)))
|
||||
(IO.println &(str @(Pair.a &(Pair.init 100 100))))
|
||||
(try-dictionary)
|
||||
))
|
||||
|
@ -61,3 +61,8 @@
|
||||
|
||||
;; (defn main []
|
||||
;; (f))
|
||||
|
||||
(defn-do main []
|
||||
(println* "eq? " (= &(Pair.init 5 true) &(Pair.init 6 false)))
|
||||
(println* "eq? " (= &(Pair.init 5 true) &(Pair.init 5 true)))
|
||||
)
|
||||
|
@ -29,10 +29,13 @@ setFullyQualifiedSymbols typeEnv globalEnv env (XObj (Lst [defn@(XObj Defn _ _),
|
||||
body])
|
||||
i t) =
|
||||
-- For self-recursion, there must be a binding to the function in the inner env.
|
||||
-- Note: This inner env is ephemeral since it is not stored in a module or global scope.
|
||||
let functionEnv = Env Map.empty (Just env) Nothing [] InternalEnv
|
||||
envWithSelf = extendEnv functionEnv functionName sym
|
||||
envWithArgs = foldl' (\e arg@(XObj (Sym (SymPath _ argSymName) _) _ _) -> extendEnv e argSymName arg) envWithSelf argsArr
|
||||
-- It is marked as external to not mess up lookup.
|
||||
-- Inside the recursion env is the function env that contains bindings for the arguments of the function.
|
||||
-- Note: These inner envs is ephemeral since they are not stored in a module or global scope.
|
||||
let recursionEnv = Env Map.empty (Just env) Nothing [] ExternalEnv
|
||||
envWithSelf = extendEnv recursionEnv functionName sym
|
||||
functionEnv = Env Map.empty (Just recursionEnv) Nothing [] InternalEnv
|
||||
envWithArgs = foldl' (\e arg@(XObj (Sym (SymPath _ argSymName) _) _ _) -> extendEnv e argSymName arg) functionEnv argsArr
|
||||
in XObj (Lst [defn, sym, args, setFullyQualifiedSymbols typeEnv globalEnv envWithArgs body]) i t
|
||||
setFullyQualifiedSymbols typeEnv globalEnv env (XObj (Lst [the@(XObj The _ _), typeXObj, value]) i t) =
|
||||
let value' = setFullyQualifiedSymbols typeEnv globalEnv env value
|
||||
|
Loading…
Reference in New Issue
Block a user