scheme

How can you rewrite "begin" in Scheme?

As the Wikipedia article explains, begin in Scheme is a library form that can be rewritten using more fundamental forms like lambda. But how do you rewrite a begin, especially considering the following? x ===> error: undefined identifier: x (begin (define x 28) x) ===> 28 x ===> 28 ...

When to use (values ...) (define-values ...) in Scheme.

I have read documentation for functions such as values and define-values that return and consume multiple values. I understand what they do. It's not clear to me when you would want to use such a thing. When would it be bad/impossible to build a single list of values and consume that single list of values instead? ...

How do I do a floating-point modulo operation in Scheme?

% isn't defined. modulo only works on integers. I want something equivalent to Javascript's modulo / c's fmod. ...

Why do you have to cons with a null to get a proper list in scheme?

I realize this is a total n00b question, but I'm curious and I thought I might get a better explanation here than anywhere else. Here's a list (I'm using Dr. Scheme) > (list 1 2 3) (1 2 3) Which I think is just sugar for this: > (cons 1 (cons 2 (cons 3 null))) (1 2 3) This, on the other hand, does something else: > (cons 1 (cons ...

How to check for NaN in Scheme?

Also is there a place where I could look up all the floating points ops in Scheme? ...

How do I do exponents in Scheme?

pow, ^, ** doesn't work, and Scheme seems to be too common a word to be able to effectively google it. ...

How to do bit-wise zero-filling right shift in Scheme?

According to here, arithmetic-shift will bit-shift left and right. The right shift preserves the sign. Is there any unsigned right-shift operator, which fills the vacated bits with zero instead of the sign bit? ...

Scheme: Implementing n-argument compose using fold

I'm trying to find the "best" implementation of a multi-argument "compose" in Scheme (I know it's a builtin in some implementations, but assume for the moment I am using one that doesn't have this). For a 2-argument compose function I have this: (define compose (lambda (f g) (lambda x (f (apply g x))))) This has the advan...

SICP 1.31: Approximating Pi

Hello- I'm working through SICP on my own, so I don't have an instructor to ask about this. This code is supposed to approximate pi but always returns zero instead. (define (approx-pi acc) (define (factors a) (define basic-num (if (= (mod a 2) 0) (/ a 2) (/ (- a 1) 2))) (if (= (mod basic-num ...

scheme and set!

How can I change the value of a variable via a function that consumes lambda parameter? Ie: ;;definitions (define test "fails") (define (experiment input) (set! input "works")) ;;interactions > test "fails" > (experiment test) > test "fails" This seems to fail.. Regards ...

Compiling a .ss file

I heard that you can compile .ss files with DrScheme, and even remember doing it once to result in some good speedups on my code, since it doesn't need to put in all the debugging info necessary for the GUI. How does one go about doing this? ...

Flush stdout in DrScheme?

I can do it in Java, Python, Haskell... how do you do it in DrScheme? A customary google search didn't yield the answer. ...

Translating the Q and P function from The Little Schemer into Common Lisp?

In Chapter 9 of the Little Schemer, the Author presents the following two functions (define Q (lambda (str n) (cond ((zero? (remainder (first$ str ) n)) (Q (second$ str ) n)) (t (build (first$ str ) (lambda ( ) (Q (second$ str ) n))))))) (define P (lambda (str) (build (first$ st...

Lisp as a Scripting Language in a C++ app...

Hey, I've been looking at the possibility of adding a scripting language into my framework and I heard about Lisp and thought I would give it a go. Is there a VM for Lisp like Lua and Python or am I in the wrong mindset. I found CLISP here, http://clisp.cons.org/, but am not sure if this is what I am looking for. Can anyone point me in ...

"for each" or "every" keywords in Scheme

Is there a for loop or for each loop in Scheme ? I've been searching around and found there is a keyword "every" but the scheme compiler language I'm using does not have this function pre-build in. This is what it suppose to do, it can be find here (define (first-letters sent) (every first sent)) > (first-letters '(here comes the su...

How to Implement a counter for every number inside a list with Scheme ?

Okay I want to count the number of times each [number] has appeared inside a list using Scheme. How can I do that ? I also would like to store the counter of the given number and re-construct a new list. For example I have the following list ((1 2)(2 5)(5 7)(7 8)(6 8)(4 6)(3 4)(1 3)(4 8)) I was thinking first flatten the list, and the...

How to solve the following problem using accumulate (Scheme) [Solved]

Hello, I'm trying to do the following problem (there is a formula so I print-screened and uploaded it) (http://img248.imageshack.us/img248/6558/problemh.jpg) Using accumulate: (define (accumulate combiner null-value term a next b) (if (> a b) null-value (combiner (term a) (accumulate combiner null-value term (n...

Scheme, getting the pointer from pointed struct

Assume I have a such struct: (define-struct node (value next)) ;and making 2 nodes, parent pointing to child as next. (define child (make-node 2 null)) (define parent (make-node 1 child)) Under PLT Scheme, while having child in my hand (and not knowing that parent is the pointer), is it possible to find the pointing node sctuct with...

Pros and cons of MIT Scheme and DrScheme to study SICP?

All, In your mind, what are the pros and cons of using MIT Scheme versus DrScheme, in the context of trying to go through SICP (presumably simultaneously to watching some / all the MIT 6.001 videos)? Please feel free to edit below: MIT Scheme pros: - Specifically built for SICP and MIT 6.001. MIT Scheme cons: DrScheme pros: - Wid...

Check string containment in Scheme

How do I check, in DrScheme, whether a string contains a given character / substring? How do I include the proper module if it is defined in a module? ...