mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
Fixed all examples after changing string literals to refs.
This commit is contained in:
parent
515bc03664
commit
9781c5f7cb
@ -56,7 +56,12 @@ arrayModule = Env { envBindings = bindings, envParent = Nothing, envModuleName =
|
||||
]
|
||||
|
||||
startingGlobalEnv :: Env
|
||||
startingGlobalEnv = Env { envBindings = bs, envParent = Nothing, envModuleName = Nothing, envUseModules = [], envMode = ExternalEnv }
|
||||
startingGlobalEnv = Env { envBindings = bs,
|
||||
envParent = Nothing,
|
||||
envModuleName = Nothing,
|
||||
envUseModules = [(SymPath [] "String")],
|
||||
envMode = ExternalEnv
|
||||
}
|
||||
where bs = Map.fromList [ register "and" (FuncTy [BoolTy, BoolTy] BoolTy)
|
||||
, register "or" (FuncTy [BoolTy, BoolTy] BoolTy)
|
||||
, register "not" (FuncTy [BoolTy] BoolTy)
|
||||
|
@ -5,4 +5,5 @@
|
||||
(register copy (Fn [(Ref String)] String))
|
||||
(register count (Fn [(Ref String)] Int))
|
||||
(register duplicate (Fn [(Ref String)] String))
|
||||
(register raw (Fn [(Ref String)] String)) ;; bad name?
|
||||
)
|
||||
|
@ -137,6 +137,10 @@ string String_duplicate(string *s) {
|
||||
return strdup(*s);
|
||||
}
|
||||
|
||||
string String_raw(string *s) {
|
||||
return *s;
|
||||
}
|
||||
|
||||
string Char_str(char c) {
|
||||
char *buffer = CARP_MALLOC(2);
|
||||
snprintf(buffer, 2, "%c", c);
|
||||
|
@ -10,8 +10,8 @@
|
||||
(use C)
|
||||
|
||||
(defn main []
|
||||
(let [c1 (C.init "Hej" [1 2 3])
|
||||
(let [c1 (C.init @"Hej" [1 2 3])
|
||||
c2 (C.copy &c1)
|
||||
a1 [(C.copy &c2) (C.copy &c2) (C.copy &c2)]
|
||||
a2 (copy &a1)]
|
||||
(IO.println &"OK.")))
|
||||
(IO.println "OK.")))
|
||||
|
@ -1,14 +1,13 @@
|
||||
(use IO)
|
||||
(use Int)
|
||||
(use String)
|
||||
(use Array)
|
||||
|
||||
(deftype A [s String])
|
||||
|
||||
(defn f []
|
||||
(let [stuff [(A.init "hej") (A.init "svej")]]
|
||||
(let [stuff [(A.init (String.copy "hej")) (A.init (String.copy "svej"))]]
|
||||
()))
|
||||
|
||||
(defn main []
|
||||
(do (f)
|
||||
(println &"OK.")))
|
||||
(println "OK.")))
|
||||
|
@ -73,14 +73,14 @@
|
||||
(= et SDL_KEYDOWN) (let [key (event-keycode &event)]
|
||||
(cond
|
||||
(= key SDLK_ESCAPE) (quit &app)
|
||||
(println &"Unrecognized key.")))
|
||||
(println &"Some other event happened..."))))))
|
||||
(println "Unrecognized key.")))
|
||||
(println "Some other event happened..."))))))
|
||||
|
||||
(defn main []
|
||||
(let [app (app-init "~ CARP ~" 512 512)
|
||||
(let [app (app-init (String.copy "~ CARP ~") 512 512)
|
||||
rend (app-renderer app)
|
||||
img1 (IMG_LoadTexture rend "./img/square.png")
|
||||
img2 (IMG_LoadTexture rend "./img/carp_logo_969_no_texture.png")
|
||||
img1 (IMG_LoadTexture rend (raw "./img/square.png"))
|
||||
img2 (IMG_LoadTexture rend (raw "./img/carp_logo_969_no_texture.png"))
|
||||
images (Images.init img1 img2)]
|
||||
(while true
|
||||
(do
|
||||
|
@ -5,21 +5,21 @@
|
||||
(use String)
|
||||
|
||||
(defn main []
|
||||
(do (println (ref "~ The number guessing game ~"))
|
||||
(print (ref "Please enter a number between 1 - 99: "))
|
||||
(do (println "~ The number guessing game ~")
|
||||
(print "Please enter a number between 1 - 99: ")
|
||||
(let [play true
|
||||
answer (random-between 1 100)]
|
||||
(while play
|
||||
(let [guess (get-line)
|
||||
num (from-string &guess)]
|
||||
(if (= (ref guess) (ref "q\n"))
|
||||
(if (= (ref guess) "q\n")
|
||||
(do
|
||||
(println (ref "Good bye..."))
|
||||
(println "Good bye...")
|
||||
(set! &play false))
|
||||
(do
|
||||
(if (< num answer)
|
||||
(println (ref "Too low."))
|
||||
(println "Too low.")
|
||||
(if (> num answer)
|
||||
(println (ref "Too high."))
|
||||
(println (ref "Correct!"))))
|
||||
(print (ref "Please guess again: ")))))))))
|
||||
(println "Too high.")
|
||||
(println "Correct!")))
|
||||
(print "Please guess again: "))))))))
|
||||
|
@ -4,7 +4,6 @@
|
||||
(use Double)
|
||||
(use Array)
|
||||
(use System)
|
||||
(use String)
|
||||
(use Char)
|
||||
|
||||
(deftype A [])
|
||||
@ -15,40 +14,40 @@
|
||||
hah))
|
||||
|
||||
(defn e []
|
||||
"hej")
|
||||
@"hej")
|
||||
|
||||
(defn f []
|
||||
(let [s "hej"]
|
||||
(let [s @"hej"]
|
||||
(noop (address s))))
|
||||
|
||||
(defn g []
|
||||
(let [s "hej"]
|
||||
(let [s @"hej"]
|
||||
s))
|
||||
|
||||
(defn h []
|
||||
(let [s "hej"]
|
||||
(let [s @"hej"]
|
||||
(println (ref s))))
|
||||
|
||||
(defn i [s]
|
||||
(do (println (ref s))
|
||||
"hej"))
|
||||
(do (println s)
|
||||
@"hej"))
|
||||
|
||||
(defn j [s]
|
||||
(do (noop (address s))
|
||||
"hej"))
|
||||
@"hej"))
|
||||
|
||||
(defn k []
|
||||
(let [s "hej"]
|
||||
(do (println (ref "?"))
|
||||
(let [s @"hej"]
|
||||
(do (println "?")
|
||||
123)))
|
||||
|
||||
(defn l []
|
||||
(do (noop (address "hej"))
|
||||
(println (ref "blub"))
|
||||
"ccccc"))
|
||||
(do (noop (address @"hej"))
|
||||
(println (ref @"blub"))
|
||||
@"ccccc"))
|
||||
|
||||
(defn m []
|
||||
(let [x (ref "yes")]
|
||||
(let [x "yes"]
|
||||
(do (println x)
|
||||
(println x))))
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
(defn main []
|
||||
(do
|
||||
(println (ref (B.id2 "hej")))
|
||||
(println (ref (B.id2 @"hej")))
|
||||
(println (ref (str (A.hard true 10 20))))
|
||||
(println (ref (str (A.hard false 10 20))))))
|
||||
|
||||
|
@ -5,14 +5,14 @@
|
||||
;; USER DEFINED FUNCTIONS
|
||||
(defn f [] true)
|
||||
(defmodule A (defn f [] 123))
|
||||
(defmodule B (defn f [] "hello"))
|
||||
(defmodule B (defn f [] @"hello"))
|
||||
|
||||
(use A)
|
||||
(use B)
|
||||
|
||||
(defn main []
|
||||
(do
|
||||
(if (f) (println (ref "yes")) (println (ref "no")))
|
||||
(if (f) (println "yes") (println "no"))
|
||||
(println (ref (str (f))))
|
||||
(println (ref (f)))))
|
||||
|
||||
@ -45,8 +45,8 @@
|
||||
(use Building)
|
||||
|
||||
(defn main []
|
||||
(let [thing (Building.init "Eiffel Tower")
|
||||
another (Person.init "Alice")]
|
||||
(let [thing (Building.init @"Eiffel Tower")
|
||||
another (Person.init @"Alice")]
|
||||
(do (println (name (ref thing)))
|
||||
(println (name (ref another))))))
|
||||
|
||||
|
@ -9,8 +9,8 @@
|
||||
(defmodule Vec2
|
||||
(defn str [v]
|
||||
(append
|
||||
(append "x: " (Int.str (Vec2.x v)))
|
||||
(append ", y: " (Int.str (Vec2.y v)))))
|
||||
(append @"x: " (Int.str (Vec2.x v)))
|
||||
(append @", y: " (Int.str (Vec2.y v)))))
|
||||
(defn basic [] (Vec2.init 10 20)))
|
||||
|
||||
(defmodule Advanced
|
||||
|
Loading…
Reference in New Issue
Block a user