scheme

What is call/cc?

I've tried several times to grasp the concept of continuations and call/cc. Every single attempt was a failure. Can somebody please explain me these concepts, ideally with more realistic examples than these on Wikipedia or in other SO posts. I have background in web programming and OOP. I also understand 6502 assembly and had a minor ra...

Why doesn't Scheme support first class environments?

Hi guys, I've been reading through SICP (Structure and Interpration of Computer Programs) and was really excited to discover this wonderful special form: "make-environment", which they demonstrate to use in combination with eval as a way of writing modular code (excerpt from section 4.3 on "packages"): (define scientific-library (make...

How can you re-define a constant identifier in DrScheme?

I am using DrScheme to write a Scheme interpreter. I define a Read Eval Print Loop and I am re-defining the eval procedure. This works fine in other scheme implementations like Chez Scheme, but I don't like the code editing in Chez Scheme, so I would like to use DrScheme for this. When I make a definition such as: (define (eval exp env)...

How do you properly compute pairwise differences in Scheme?

Hello, Given a list of numbers, say, (1 3 6 10 0), how do you compute differences (xi - xi-1), provided that you have x-1 = 0 ? (the result in this example should be (1 2 3 4 -10)) I've found this solution to be correct: (define (pairwise-2 f init l) (first (foldl (λ (x acc-data) (let ([result-list (first acc-data)] ...

Fixing Lisp Syntax

Being a newbie to Lisp I'm wondering if the Lisp syntax could be "fixed"? Some people say the syntax in Lisp is one of its biggest strengths. I don't quite understand this. Isn't it possible to replace "obvious" parentheses with a combination of white spaces, new lines and indenting? Just like in Python? It looks to me like parenthe...

Lisp evaluation of let statements

I am writing a Scheme interpreter, and I am faced with a valid let statement such as: ;; should print 7 (let ((a 4) (b 3)) (let ((a (* a a)) (b (* b b))) (+ a b) (- a b))) My interpreter implements only a purely functional subset of Scheme, so there will be no side effects such as set!. In a purely functio...

What background is needed for reading "Purely Functional Data Structures" ?

I have just finished reading Little Schemer.. Now I am planning on reading Purely Functional Data Structures.. but the notations in the book looks very complicated.. are there easier alternative to this book that talk about data structure in functional languages.. if not then what do I need to read before I can start on this book... Th...

How can I tell if a list has a third item?

I have a function that takes a list that either has two or three elements. ;; expecting either ((a b c) d) or ((a b c) d e) (define (has-third-item ls) (if (null? (caddr ls)) false true) ) But this code fails with mcar: expects argument of type <mutable-pair>; given () on the (null? (caddr ls)) expr...

Can you return nothing from a function in Scheme?

I'm writing a scheme interpreter, and in the case of an if statement such as: (if (< 1 0) 'true) Any interpreter I've tried just returns a new prompt. But when I coded this, I had an if for whether there was an alternative expression. What can I return in the if such that nothing gets printed? (if (has-alternative if-expr) (eval (a...

How do you halt in DrScheme's implementation of R5RS?

When using DrScheme with R5RS, there is no error function. I plan to write my own, but can't figure out how to halt the program execution. I tried commands such as: (halt) (exit) (error) and none worked. How do you halt program execution? ...

Beginner: Curried functions in Scheme

I'm using the SICP lectures and text to learn about Scheme on my own. I am looking at an exercise that says "An application of an expression E is an expression of the form (E E1,...En). This includes the case n=0, corresponding to an expression (E). A Curried application of E is either an application of E or an application of a Curried ...

What is the Scheme function to find an element in a list?

I have a list of elements '(a b c) and I want to find if (true or false) x is in it, where x can be 'a or 'd, for instance. Is there a built in function for this? ...

Loading libraries in Dr Scheme

I am working through SICP using Dr Scheme. How do I load external libraries in Dr Scheme? Say I want to use Math library then how do I ask Dr Scheme to load the particular library? I tried with the following: (require (lib "math.ss")) Got the following error: reference to undefined identifier: require I have chosen R5RS as the langua...

Seeking Simply Scheme idioms for Dr. Scheme

I'm working my way through SICP, using both the Ableson/Sussman lectures and the Berkeley 61A lectures, which are far more my speed. I'd like to do some of the Berkeley homework, but need the definitions for sentence, butfirst, butlast and so forth. It looks like at one time there was a simply scheme language built in to Dr. Scheme, but ...

Windows Scheme/Lisp Implementation

With the thousands of implementations of LISP and Scheme available I'm having a very hard time finding just the right one to use for Windows development. I learned these languages in school and found them to be very elegant, however, I don't seem to be able to find an implementation that would be suitable for developing code other than ...

Seeking contrived example code: continuations!

So I believe I understand continuations now, at least on some level, thanks to the community scheme wiki and Learn Scheme in Fixnum Days. But I'd like more practice -- that is, more example code I can work through in my head (preferably contrived, so there's not extraneous stuff to distract from the concept). Specifically, I'd like to ...

Python Macros: Use Cases?

If Python had a macro facility similar to Lisp/Scheme (something like MetaPython), how would you use it? If you are a Lisp/Scheme programmer, what sorts of things do you use macros for (other than things that have a clear syntactic parallel in Python such as a while loop)? ...

How to write a scheme function that takes two lists and returns four lists

I have 2 lists of elements '(a b c) '(d b f) and want to find differences, union, and intersection in one result. Is that possible? How? I wrote a member function that checks if there is a car of the first list in the second list, but I can't throw a member to the new list. (define (checkResult lis1 lis2) (cond........... )) (checkr...

Car return value? Or scheme being werid.

Okay i noticed this semi weridish behavior in one of my projects using scheme, and lists. I managed to isolate the behavior, into a single section. The code is: (define x (list 1 2 3)) (define y (list 4 5)) (define z (cons (car x) (cdr y))) (define w (append y z)) (define v (cons (cdr x) (cdr y))) (set-car! x 6) (set-car! y 7) (set-cdr!...

How to improve this piece of code?

My solution to exercise 1.11 of SICP is: (define (f n) (if (< n 3) n (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)))) )) As expected, a evaluation such as (f 100) takes a long time. I was wondering if there was a way to improve this code (without foregoing the recursion), and/or take advantage of multi-core box. I am usi...