I'm trying to learn scheme via SICP. Exercise 1.3 reads as follow: Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. Please comment on how I can improve my solution.
(define (big x y)
(if (> x y) x y))
(define (p a b c)
(cond ((> a b) (+ (square a) (square (bi...
What are the popular (ok, popular is relative) web frameworks for the various flavours of LISP?
...
I have experimented with Lisp (actually Scheme) and found it to be a very beautiful language that I am interested in learning more about. However, it appears that Lisp is never used serious projects, and I haven't seen it listed as a desired skill on any job posting. I am interested in hearing from anyone who has used Lisp or seen it u...
I know that JavaScript doesn't support macros (Lisp-style ones) but I was wondering if anyone had a solution to maybe simulate macros? I Googled it, and one of the solutions suggested using eval(), but as he said, would be quite costly.
They don't really have to be very fancy. I just want to do simple stuff with them. And it shouldn't ...
question: ((lambda (x y) (x y)) (lambda (x) (* x x)) (* 3 3))
this was #1 on the midterm, i put "81 9" he thought i forgot to cross one out lawl, so i cross out 81, and he goes aww. Anyways, i dont understand why its 81.
I understand why (lambda (x) (* x x)) (* 3 3) = 81, but the first lambda i dont understand what the x and y values a...
A lambda expression which takes a function (of one argument) and a number, and applies the function to twice the number.
...
If you could help me with ANY part of this question, I would appreciate it. Thanks.
2^0 = 1
2^N = 2^(N-1) + 2^(N-1)
Convert this definition into an exactly equivalent tree-recursive function called two-to-the-power-of. Describe its asymptotic time complexity and explain why it has this time complexity.
Now write a function called ttt...
I've caught the bug to learn functional programming for real. So my
next self-study project is to work through the Structure and
Interpretation of Computer Programs. Unfortunately, I've never
learned Lisp, as I was not a CS major in college.
While SICP does not emphasize the tools for programming, doing the
exercises entails picking a ...
Many examples of macros seem to be about hiding lambdas, e.g. with-open-file in CL. I'm looking for some more exotic uses of macros, particularly in PLT Scheme. I'd like to get a feel for when to consider using a macro vs. using functions.
...
I wrote this scheme code to compute one solution of the quadratic equation a*x2 + b*x + c = 0
(define (solve-quadratic-equation a b c) (define disc (sqrt (- (* b b) (* 4.0 a c)))) (/ (+ (- b) disc) (* 2.0 a)))
However, someone told me that this procedure is hard to understand. Why?
What would a cleaned up version of this procedure lo...
Is anyone familiar with this?
Write a procedure that takes as inputs
a procedure that computes f and a
positive integer n and returns the
procedure that computes the nth
repeated application of f. The
procedure should be able to be used as
follows:
((repeated square 2) 5)
625
I know that the following code I've create...
Evaluate:
((((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4) 5)
This is what I did:
-evaluate ((((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4) 5)
-evaluate 5 -> 5
-evaluate (((lambda (x) (lambda (y) (lambda (x) (+ x y)))) 3) 4)
-evaluate 4 -> 4
-evaluate ((lambda (x) (lambda (y) (lambda (x) (+ x y)))) ...
(define (square x)
(display (* x x)))
(define (sum-of-squares a b)
(+ (square a) (square b)))
I tested it, and the sum-of-squares function will not work. Why is this?
...
If f is a numerical function and n is a positive integer, then we can form the nth repeated application of f, which is defined to be the function whose value at x is f(f(...(f(x))...)). For example, if f is the function x + 1, then the nth repeated application of f is the function x + n. If f is the operation of squaring a number, then t...
What is the time complexity? Why?
(define (mult a b)
(define (internal a accum)
(if (= a 1) accum
(internal (- a 1) (+ accum b))))
(internal a b))
(define (to-the-power-of m n)
(define (internal x accum)
(if (= x 0) accum
(internal (- x 1) (mult accum m))))
(internal n...
Could you write a function that takes one argument (a positive integer) and
divides it by two if it's even, or
multiplies it by three and adds one if it's odd
and then returns the resulting number.
And then a separate function that takes one argument (a positive integer) and repeatedly passes it to the previous function until it rea...
I want to see how long a function takes to run. What's the easiest way to do this in PLT-Scheme? Ideally I'd want to be able to do something like this:
> (define (loopy times)
(if (zero? times)
0
(loopy (sub1 times))))
> (loopy 5000000)
0 ;(after about a second)
> (timed (loopy 5000000))
Took: 0.93 se...
I have been using PLT Scheme, but it has some issues. Does anyone know of a better implementation for working through SICP?
...
A k-ary necklace of length n is an ordered list of length n whose items are drawn from an alphabet of length k, which is the lexicographically first list in a sort of all lists sharing an ordering under rotation.
Example:
(1 2 3) and (1 3 2) are the necklaces of length 3 from the alphabet {1 2 3}.
More info:
http://en.wikipedia.org/wi...
I recently downloaded PLT Scheme and DrScheme. When I open DrScheme, I am told to choose a language. However, I'm not familiar with any of my options, and the help guides don't really break it down to help me easily choose which choice.
So, first - is DrScheme and PLT Scheme really the tools I need to learn Lisp and/or Scheme? If so, wh...