mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-16 15:38:24 +03:00
55 lines
941 B
Plaintext
55 lines
941 B
Plaintext
;; Type selection (choose the right function based on the types at the call site)
|
|
(use IO)
|
|
(use Int)
|
|
|
|
;; USER DEFINED FUNCTIONS
|
|
(defn f [] true)
|
|
(defmodule A (defn f [] 123))
|
|
(defmodule B (defn f [] @"hello"))
|
|
|
|
(use A)
|
|
(use B)
|
|
|
|
(defn main []
|
|
(do
|
|
(if (f) (println "yes") (println "no"))
|
|
(println (ref (str (f))))
|
|
(println (ref (f)))))
|
|
|
|
(build)
|
|
(run)
|
|
|
|
;; => yes
|
|
;; 123
|
|
;; hello
|
|
|
|
|
|
|
|
;; PLUS FUNCTION
|
|
(use Double)
|
|
(use Float)
|
|
|
|
(defn shouldBeInt [x] (+ x 10))
|
|
(defn shouldBeDouble [x] (+ x 10.0))
|
|
(defn shouldBeFloat [x] (+ x 10.0f))
|
|
|
|
(defn shouldBeFloatInLet [x] (let [a (+ x 10.0f)]
|
|
a))
|
|
|
|
|
|
;; RECORD FIELDS
|
|
(deftype Person [name String])
|
|
(deftype Building [name String])
|
|
|
|
(use Person)
|
|
(use Building)
|
|
|
|
(defn main []
|
|
(let [thing (Building.init @"Eiffel Tower")
|
|
another (Person.init @"Alice")]
|
|
(do (println (name (ref thing)))
|
|
(println (name (ref another))))))
|
|
|
|
(build)
|
|
(run)
|