Skip to content

Commit 55c9861

Browse files
author
Sasha
committed
Merge remote-tracking branch 'upstream/master'
2 parents 04b93dc + 265008a commit 55c9861

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

readme.org

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
* ClojureRS
2-
[[https://i.imgur.com/rpioVBP.png]]
1+
[[https://i.imgur.com/SgRDG6z.png]]
32

4-
Put simply, Clojure implemented atop Rust! For now, a Clojure interpreter implemented in Rust.
3+
Put simply, Clojure implemented atop Rust! For now, a Clojure interpreter implemented in Rust.
4+
**
5+
[[https://i.imgur.com/rpioVBP.png]]
6+
/The repl in action/
57

68
** Project Goals:
79
1. To create a version of Clojure that gets to exist independent of a particular platform
@@ -15,3 +17,6 @@
1517
Check clojureRS.org (the file, not website) for more notes about
1618
the design of the language, which should grow as the program
1719
grows.
20+
** Discussion
21+
Come join us on discord!
22+
[[https://discord.gg/aS5Sa8p]]

src/persistent_list_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ impl fmt::Display for PersistentListMap {
171171
#[cfg(test)]
172172
mod tests {
173173
use crate::persistent_list_map::*;
174-
use crate::value::ToValue;
175174
use crate::symbol::Symbol;
175+
use crate::value::ToValue;
176176

177177
#[test]
178178
fn test_persistent_list_map() {

src/repl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::fs::File;
2+
use std::io;
23
use std::io::BufRead;
34
use std::io::BufReader;
45
use std::io::Write;
5-
use std::io;
66

77
use crate::environment::Environment;
88
use crate::reader;

src/rust_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl ToValue for DoMacro {
149149
impl IFn for DoMacro {
150150
fn invoke(&self, args: Vec<&Value>) -> Value {
151151
// @TODO generalize arity exceptions, and other exceptions
152-
if args.len() == 0 {
152+
if args.is_empty() {
153153
return vec![Symbol::intern("do").to_rc_value(), Rc::new(Value::Nil)]
154154
.into_list()
155155
.to_value();

src/value.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::fmt;
1616
use std::fmt::Debug;
1717
use std::hash::{Hash, Hasher};
1818
use std::rc::Rc;
19+
use std::cmp::{Ord, Ordering};
1920

2021
// @TODO Change IFn's name -- IFn is a function, not an IFn.
2122
// The body it executes just happens to be an the IFn.
@@ -441,7 +442,7 @@ impl Value {
441442
.map(|rc_arg| rc_arg)
442443
.collect::<Vec<Rc<Value>>>();
443444

444-
if arg_rc_values.len() < 1 {
445+
if arg_rc_values.is_empty() {
445446
return Some(Rc::new(Value::Condition(format!(
446447
"Wrong number of arguments (Given: {}, Expect: >=1",
447448
arg_rc_values.len()
@@ -500,7 +501,8 @@ impl Value {
500501
let arg_rc_values = PersistentList::iter(args)
501502
.map(|rc_arg| rc_arg)
502503
.collect::<Vec<Rc<Value>>>();
503-
if arg_rc_values.len() < 1 || arg_rc_values.len() > 2 {
504+
if arg_rc_values.is_empty() || arg_rc_values.len() > 2 {
505+
// @TODO: we give 0 but it may be 3, 4, 5...
504506
return Some(Rc::new(Value::Condition(std::string::String::from(
505507
"Wrong number of arguments given to let (Given: 0, Expecting: 1 or 2)",
506508
))));
@@ -546,19 +548,16 @@ impl Value {
546548
// quote just involves an infinite loop of macroexpansion. Or so it seems
547549
//
548550
QuoteMacro => {
549-
if args.len() > 1 {
550-
Some(Rc::new(Value::Condition(format!(
551+
match args.len().cmp(&1) {
552+
Ordering::Greater => Some(Rc::new(Value::Condition(format!(
551553
"Wrong number of arguments (Given: {}, Expected: 1)",
552554
args.len()
553-
))))
554-
}
555-
// @TODO define is_empty()
556-
else if args.len() < 1 {
557-
Some(Rc::new(Value::Condition(std::string::String::from(
555+
)))),
556+
// @TODO define is_empty()
557+
Ordering::Less => Some(Rc::new(Value::Condition(std::string::String::from(
558558
"Wrong number of arguments (Given: 0, Expected: 1)",
559-
))))
560-
} else {
561-
Some(args.nth(0))
559+
)))),
560+
Ordering::Equal => Some(args.nth(0)),
562561
}
563562
}
564563
//
@@ -692,7 +691,7 @@ impl Evaluable for Rc<Value> {
692691
//
693692
// Sounds less correct but also seems clearer; the current error message relies on
694693
// you pretty much already knowing when this error message is called
695-
try_apply_ifn.unwrap_or(Rc::new(Value::Condition(format!(
694+
try_apply_ifn.unwrap_or_else(|| Rc::new(Value::Condition(format!(
696695
"Execution Error: {} cannot be cast to clojure.lang.IFn",
697696
ifn.type_tag()
698697
))))

0 commit comments

Comments
 (0)