Skip to content

Commit

Permalink
Improved web client functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
cowuake committed Nov 2, 2023
1 parent 3b49c9b commit aa39ce4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
23 changes: 9 additions & 14 deletions schemus/src/core/builtins.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, rc::Rc, time::Instant};
use std::{cell::{RefCell, RefMut}, rc::Rc, time::Instant};

use super::{environment::Environment, evaluator::eval, s_expression::*};

Expand Down Expand Up @@ -300,13 +300,11 @@ fn r_display(args: ProcedureArgs, env: ProcedureEnv) -> ProcedureOutput {

match eval(&args[0], env.clone()) {
Ok(val) => match val {
SExpr::String(string) => print!("{}", string.borrow()), // Avoids double quotes
expr => print!("{}", expr),
SExpr::String(string) => Ok(SExpr::Symbol(string.borrow().to_string())), // Avoids double quotes
expr => Ok(SExpr::Symbol(format!("{}", expr)))
},
Err(e) => return Err(e),
Err(e) => Err(e),
}

Ok(SExpr::Unspecified)
}

fn r_cond(args: ProcedureArgs, env: ProcedureEnv) -> SpecialFormOutput {
Expand Down Expand Up @@ -822,12 +820,11 @@ fn r_environment_bindings(args: ProcedureArgs, env: ProcedureEnv) -> ProcedureOu
let mut bindings = env_guard.get_bindings().clone();
bindings.sort_by(|a, b| (a.0).cmp(b.0));

// TODO: Consider building up lists and using the display procedure on them
for binding in bindings {
println!("({}, {})", binding.0, binding.1);
}
let mut output: String = "".to_owned();
bindings.iter().for_each(|b| output.push_str(format!("({}, {})\n", b.0, b.1).as_str()));
output.remove(output.len() - 1);

Ok(SExpr::Unspecified)
Ok(SExpr::Symbol(output))
}

fn r_time(args: ProcedureArgs, env: ProcedureEnv) -> ProcedureOutput {
Expand All @@ -836,9 +833,7 @@ fn r_time(args: ProcedureArgs, env: ProcedureEnv) -> ProcedureOutput {
match r_eval(args, env.clone()) {
Ok(_) => {
let elapsed = then.elapsed();
print!("Elapsed time: {:?}", elapsed);

Ok(SExpr::Unspecified)
Ok(SExpr::Symbol(format!("{:?}", elapsed)))
}
Err(e) => Err(e),
}
Expand Down
6 changes: 3 additions & 3 deletions schemus/src/scheme/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub const PRELUDE: &str = r#"
(define (moo) (display "There is no cow level!"))
(define (count-to n) (if (= n 0) 'Done! (count-to (- n 1))))
(define (sum-to n) (if (= n 0) 0 (+ n (sum-to (- n 1)))))
(define (fact n) (if (= n 0) 1 (* n (fact (- n 1)))))
(define factt (lambda (n) (define aux (lambda (n acc) (cond ((= n 0) acc) ((> n 0) (aux (- n 1) (* n acc)))))) (aux n 1)))
(define factt2 (lambda (n) (define aux (lambda (n acc) (if (= n 0) acc (aux (- n 1) (* n acc))))) (aux n 1)))
(define (fact-pure n) (if (= n 0) 1 (* n (fact (- n 1)))))
(define fact (lambda (n) (define aux (lambda (n acc) (if (= n 0) acc (aux (- n 1) (* n acc))))) (aux n 1)))
(define fact2 (lambda (n) (define aux (lambda (n acc) (cond ((= n 0) acc) ((> n 0) (aux (- n 1) (* n acc)))))) (aux n 1)))
(define (evil n) (+ n (evil (- n 1))))
(define (fib n) (cond ((= n 1) 0) ((= n 2) 1) ((> n 1) (+ (fib (- n 1)) (fib (- n 2))))))
)
Expand Down

0 comments on commit aa39ce4

Please sign in to comment.