diff --git a/src/builtins/def.rs b/src/builtins/def.rs
index e9c06d6..0d4e739 100644
--- a/src/builtins/def.rs
+++ b/src/builtins/def.rs
@@ -14,27 +14,26 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-use crate::ast::Expr;
use crate::compiler::Compiler;
-use crate::types::collections::core::{first, rest};
+use crate::types::collections::core::Seq;
use crate::types::{ExprResult, List};
-pub fn def<'a>(compiler: &'a Compiler, args: &'a List) -> ExprResult<'a> {
+pub fn def<'a>(compiler: &'a Compiler, args: List) -> ExprResult<'a> {
// TODO: We need to support docstrings for def
- // if args.length != 3 {
- // // TODO: Raise a meaningful error by including the location
- // panic!(format!(
- // "`def` expects 2 parameters, '{}' given.",
- // args.length
- // ));
- // }
+ if args.length() != 2 {
+ // TODO: Raise a meaningful error by including the location
+ panic!(format!(
+ "`def` expects 2 parameters, '{}' given.",
+ args.length()
+ ));
+ }
- // //let def_ = &args.first;1
- // let name = first(rest(args));
- // //let value = first(rest(rest(args)));
+ //let def_ = &args.first;1
+ let name = args.first();
+ let value = args.rest().first();
- // println!("<<<< {:?}", name);
- // // TODO: make sure that `def_` is a symbol and its name is "def"
+ println!("<<<< {:?} \n {:?}", name, value);
+ // TODO: make sure that `def_` is a symbol and its name is "def"
Err("Is not completed".to_string())
}
diff --git a/src/reader.rs b/src/reader.rs
index fcc45e9..c35e8e6 100644
--- a/src/reader.rs
+++ b/src/reader.rs
@@ -126,15 +126,13 @@ impl ExprReader {
match self.read_expr(reader) {
Ok(value) => result.push(value),
Err(e) => match self.get_char(reader, true) {
- // is it an empty list ?
- // TODO: we might want to return an actual empty list here
Some(')') => return Ok(Expr::list_to_cons(result)),
_ => return Err(e),
},
};
loop {
- let next = match self.get_char(reader, true) {
+ match self.get_char(reader, true) {
Some(')') => return Ok(Expr::list_to_cons(result)),
Some(e) => {
self.unget_char(e);
diff --git a/src/types/collections/core.rs b/src/types/collections/core.rs
index c67fe34..f95afd8 100644
--- a/src/types/collections/core.rs
+++ b/src/types/collections/core.rs
@@ -15,26 +15,25 @@
* along with this program. If not, see .
*/
+/// Seq trait describes a seqable collection. Please note that `first`
+/// and `rest` return a copy of the data not the reference!
pub trait Seq {
- fn first(&self) -> &T;
- fn rest(&self) -> Option<&Self>;
+ type Coll;
+
+ fn first(&self) -> Option;
+ fn rest(&self) -> Self::Coll;
}
-pub fn first<'a, T, S: Seq>(coll: impl Into