Skip to content

Commit 91d74be

Browse files
committed
Merge branch 'feature/value-regex' [#58]
2 parents effb834 + 861b05e commit 91d74be

24 files changed

+481
-127
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ nom = "5.1"
1212
rand = "0.7"
1313
itertools= "0.9"
1414
url = "2.1.1"
15+
regex = "1.3.7"
1516
reqwest = { version = "0.10.4", features = ["blocking"] }

examples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# ClojureRS Examples
2+
3+
These small programs show some implemented functionality as small
4+
programs as that can be interpreted by ClojureRS.
5+
6+
### TODO
7+
8+
Less trivial examples depending on available features

examples/guess_number.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(println "Guess a number between 1 and 3.")
2+
(print "guess > ")
3+
(flush)
4+
(let [answer (read-line)
5+
number (+ (rand-int 3) 1)]
6+
7+
(if (= answer (str number))
8+
(println "correct!")
9+
(println "wrong, the correct was " number)))

examples/strings.clj

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
(defn main []
3+
4+
(println "'hello world' ends with 'orld' : " (clojure.string/ends-with? "hello world" "orld"))
5+
(println "'hello world' starts with 'hel' : " (clojure.string/starts-with? "hello world" "hel"))
6+
7+
(println "nil is empty string : " (clojure.string/blank? nil))
8+
(println "whitespace is empty string : " (clojure.string/blank? " "))
9+
(println "hello is empty string : " (clojure.string/blank? "hello"))
10+
11+
(println "hello,world splitted by regex pattern " #"\"" " " (clojure.string/split "hello,world", #","))
12+
13+
(println "murder is backwards : " (clojure.string/reverse "murder"))
14+
15+
(println "upper case hello : " (clojure.string/upper-case "hello"))
16+
(println "lower case HELLO : " (clojure.string/lower-case "HELLO"))
17+
18+
(println "joining array of items with ', ' : " (clojure.string/join ", " [1, "second", true]))
19+
20+
(println "hello world includes 'o wor' : " (clojure.string/includes? "hello world" "o wor")))
21+
22+
(main)
23+

examples/what_is_your_name.clj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(print "What is your name? " )
2+
(flush)
3+
(let [answer (read-line)]
4+
(println "Hello, " answer "!"))

src/clojure/string.clj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"clojure.string"
2+
3+
"TODO : some special syntax required because of missing require"
4+
5+
(def clojure.string/split-lines
6+
(fn [s]
7+
(clojure.string/split s #"\r?\n")))

src/clojure_std.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
pub (crate) mod thread;
2-
pub (crate) mod time;
3-
pub (crate) mod env;
1+
pub(crate) mod env;
2+
pub(crate) mod thread;
3+
pub(crate) mod time;

src/clojure_std/env.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::ifn::IFn;
33
use crate::value::{ToValue, Value};
44
use std::rc::Rc;
55

6-
use std::env;
76
use crate::type_tag::TypeTag;
7+
use std::env;
88

99
/// provides a function to return env variables
1010
/// similair to Clojure (System/getenv [key])
@@ -20,13 +20,11 @@ impl IFn for GetEnvFn {
2020
fn invoke(&self, args: Vec<Rc<Value>>) -> Value {
2121
if args.len() == 1 {
2222
match args.get(0).unwrap().to_value() {
23-
Value::String(key) => {
24-
match env::var(key) {
25-
Ok(val) => Value::String(val),
26-
Err(_) => Value::Nil
27-
}
28-
}
29-
_a => error_message::type_mismatch(TypeTag::String, &_a)
23+
Value::String(key) => match env::var(key) {
24+
Ok(val) => Value::String(val),
25+
Err(_) => Value::Nil,
26+
},
27+
_a => error_message::type_mismatch(TypeTag::String, &_a),
3028
}
3129
} else {
3230
return error_message::wrong_arg_count(1, args.len());

src/clojure_string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub(crate) mod includes_qmark_;
44
pub(crate) mod join;
55
pub(crate) mod lower_case;
66
pub(crate) mod reverse;
7+
pub(crate) mod split;
78
pub(crate) mod starts_with_qmark_;
89
pub(crate) mod trim;
910
pub(crate) mod trim_newline;

src/clojure_string/join.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::iterable::Iterable;
21
use crate::ifn::IFn;
2+
use crate::iterable::Iterable;
33
use crate::value::{ToValue, Value};
44
use std::rc::Rc;
55

@@ -22,7 +22,7 @@ impl IFn for JoinFn {
2222
if args.len() != 1 && args.len() != 2 {
2323
return error_message::wrong_varg_count(&[1, 2], args.len());
2424
}
25-
25+
2626
let separator = if args.len() == 1 {
2727
String::from("")
2828
} else {
@@ -40,13 +40,11 @@ impl IFn for JoinFn {
4040
.iter()
4141
.map(|x| x.to_string())
4242
.collect::<Vec<std::string::String>>()
43-
.join(&separator)
43+
.join(&separator),
4444
)
45-
}
46-
else {
45+
} else {
4746
Value::String(String::from(""))
4847
}
49-
5048
}
5149
}
5250

0 commit comments

Comments
 (0)