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
...
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?
...
% isn't defined. modulo only works on integers. I want something equivalent to Javascript's modulo / c's fmod.
...
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 ...
Also is there a place where I could look up all the floating points ops in Scheme?
...
pow, ^, ** doesn't work, and Scheme seems to be too common a word to be able to effectively google it.
...
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?
...
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...
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 ...
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
...
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?
...
I can do it in Java, Python, Haskell... how do you do it in DrScheme? A customary google search didn't yield the answer.
...
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...
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 ...
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...
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...
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...
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...
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...
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?
...