scheme

Using Let in Scheme

I want to write a program to find the roots of the quadratic equation in Scheme. I used LET for certain bindings. (define roots-with-let (λ (a b c) (let ((4ac (* 4 a c)) (2a (* 2 a)) (discriminant (sqrt ( - (* b b) (4ac))))) (cons ( / ( + (- b) discriminant) 2a) ( / ( - (- b) discriminant) 2a)...

How do I load library to support hashtable in R5RS language (DrScheme)?

Looks like R5RS language in DrScheme does not come with hashtable library.. when I run (make-hash-table) it throws an error... Pretty Big has support for hashtable but does not support mutable pairs.. so I am stuck making one of them work for me .. How do I add support for hashtable in R5RS? thanks ...

Difference between null? and empty? in Scheme.

Berkeley's "CS 61A Lecture 8: UI Recursion and Iteration III" says that null? checks if the list is empty and empty? checks if the list is empty or the word is empty? The lecturer also goes on to say (null? empty) will return false. But DrScheme doesnt mind at all. What is the difference between null? and empty? in Scheme? ...

Scheme(Bigloo) Server-Client Help

Hello everybody, I need to make a Server-Client software in bigloo and i need some help to make that. I am using the latest version of bigloo, but i browsed in internet and there is only an example using an old version. There they use macros like (socket-dup s) and (thread-await! (make-connect-signal s2)), where s is the server socket ...

What does the last element in a list point to in Scheme?

When I make a list in Scheme, what does the cdr of the last pair point to? Is it an 'empty word' or an 'empty list'? DrScheme doesnt mind (cons 'a empty) nor (cons 'a '()). Finally what is the difference between the empty word and the empty list? ...

Learn Macros in Scheme from On Lisp

I really want to learn Scheme macros. I glanced over the content of "On Lisp" and a lot of the chapters have been devoted to Lisp macros. However I do not know common lisp. Can I use it to learn Scheme Macros? ...

looking up the text of a procedure in scheme

The ipython python shell has a wonderful feature, whereby you can type: foo?? and see the text of function foo. Does scheme (in particular, MIT scheme), have anything like this? I want to be able to say (define (foo x) (* x x)) and later view (or even operate on) the list (* x x). Is there a way to do this? ...

Difference between Print and Display.

PLT Scheme's documentation says: The rationale for providing print is that display and write both have relatively standard output conventions, and this standardization restricts the ways that an environment can change the behavior of these procedures. No output conventions should be assumed for print, so that envir...

Im trying to access a N dimensional vector but I get into infinite recursion.

I want to access a n-dimensional vector but somehow (empty? '()) keeps returning false. ;; access n dimensional vectors ;; (access-nd vector a-list-of-numbers) -> element ;; (access-nd (vector (vector 'x 'y) 'a 'b)) 0 1 ) -> x (define (access-nd avector . alist) (cond ((and (not(empty? alist)) (vector? avector)) (vector-re...

How to save and sort coordinates (of points) in scheme ?

Hi, I want to save coordinates of points (X,Y) in a list. Also I want to sort the list by X or Y value every time I add points in that list. How can I do that? Thanks in advance. ...

Simplest example of backwards continuations in Scheme without explicit mutation

I've written a small Scheme interpreter in C#, and realised that the way I had implemented it, it was very easy to add support for proper continuations. So I added them... but want to "prove" that they way that I've added them is correct. My Scheme interpreter however has no support for "mutating" state - everything is immutable. So i...

Loop in PLT Scheme

Hi, How can I implement loop in plt-scheme like in java- for(int i=0;i<10;){ for(int j=0;j<3;){ System.out.println(""+j); j++; } System.out.println(""+i); i++; } Thanks in advance. ...

Fetch elements from List in scheme

Hi, How to go through a list or fetch element from a list in scheme? How can I name each element (like we do for variables in java) in a list? Thanks in advance. I want to compare every point in a list to another point. So, as we do in java or python- for(int i;i<list.size();i++){ if (list[i]> k){ //do something } ...

How do I make a Lazy List in an Eager Language?

I wanted to make a lazy list in Scheme. This is what I have so far. ;; Constructor for Pairs (define (cons-stream a b) (cons a (λ() b))) ;; Selectors (define (car-stream a-stream) (car a-stream)) (define (cdr-stream a-stream) ((cdr a-stream))) ;; Lazy List using the pairs (define (lazy-list from) (cons-stream from (lazy-list ...

Extra newline in emacs' scheme-mode

I'm running ypsilon scheme using Emacs 23's scheme-mode. When I enter an expression in the interpreter, it adds an extra newline (see below). I've never seen this happen for any other interpreter. I know ypsilon isn't doing it, because it looks fine in shell-mode a shell (though shell-mode exhibits the same incorrect behavior). What func...

Separate Namespaces for Functions and Variables in Common Lisp versus Scheme

Scheme uses a single namespace for all variables, regardless of whether they are bound to functions or other types of values. Common Lisp separates the two, such that the identifier "hello" may refer to a function in one context, and a string in another. (Note 1: This question needs an example of the above; feel free to edit it and add ...

How do I get mit-scheme to return a floating point number?

(/ 4 3) returns 4/3 as an answer. What is the simplest way to get 1.3...? ...

What is the time complexity of 'assoc' function in scheme?

What is the time complexity of this nifty function 'assoc'? ...

How do you define a constant in PLT Scheme?

How do I declare that a symbol will always stand for a particular value and cannot be changed throughout the execution of the program? ...

How do I write Push and Pop in Scheme?

Right now I have (define (push x a-list) (set! a-list (cons a-list x))) (define (pop a-list) (let ((result (first a-list))) (set! a-list (rest a-list)) result)) But I get this result: Welcome to DrScheme, version 4.2 [3m]. Language: Module; memory limit: 256 megabytes. > (define my-list (list 1 2 3)) > (push 4 my-list) ...