Carp/examples/bugs.carp
2018-01-28 06:35:08 +01:00

57 lines
1.6 KiB
Plaintext

;; This file contains examples of unsolved bugs
(load "Debug.carp")
(project-set! "printAST" "true")
(Debug.sanitize-addresses)
;; UNSOLVED BUG B
;; When enabling more interfaces like:
;; (definterface inc (Fn [a] a))
;; (defmodule Int (defn inc [x] (Int.+ x 1)))
;; (defmodule Float (defn inc [x] (Float.+ x 1.0f)))
;; ;; the following code doesn't figure out all the type variables:
;; (defn f [x] (=> x inc inc inc))
;; ;; This code works though:
;; ;; (defn f [x] (=> x foo foo))
;; ;; which means that it's the concretizer that has run too few times.
;; ;; Running it until nothing changes should be the fix.
;; (defn main [] (IO.println &(str (f 10.0f))))
;; BUG D
;; This shouldn't compile:
;; (defn faulty-repeat [n inpt]
;; (let [str ""]
;; (do
;; (for [i 0 n]
;; (set! &str &(append @str @inpt)))
;; @str)))
;; (defn main []
;; (let [strings (faulty-repeat 20 "x")]
;; (IO.println &strings)))
;; BUG F
;; Generic Hashmap Stuff
(use Array)
(deftype (Entry a b) [key a value b])
(deftype (Bucket a b) [entries (Array (Entry a b))])
(defmodule String
(defn zero [] @""))
(defn get-object [bucket lookup-key]
(let-do [pairs (Bucket.entries bucket)
result (zero)]
(for [i 0 (count pairs)]
(let [pair (nth pairs i)]
(when (= (Entry.key pair) &lookup-key)
(set! &result @(Entry.value pair)))))
result))
(defn main []
(let-do [start (Bucket.init [(Entry.init @"hello" 12345)
(Entry.init @"goodbye" 666)])]
(IO.println &(str &start))
(IO.println &(str @(get-object &start @"hello")))
))