plt-scheme

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) ...

How do you compare two strings and ignore the case in Scheme?

I want to write a function like equalp, which gives #t for (equalp "Xy" "xY"). ...

Pattern Matching in Scheme

How do I accept the following input? (list of 0 or more charcters and ends with 3) or (list of 1 or more characters 4 and 0 or more characters after 4) something like (match ( list 3)) -> #t (match ( list 1 2 3)) -> #t (match (list 1 2 3 4)) -> #t (match (list 1 2 3 4 5)) -> #t (match (list 4)) -> #f EDIT: THIS IS NOT MY HO...

Writing an auto-memoizer in Scheme. Help with macro and a wrapper.

I am facing a couple of problems while writing an auto-memoizer in Scheme. I have a working memoizer function, which creats a hash table and checks if the value is already computed. If it has been computed before then it returns the value else it calls the function. (define (memoizer fun) (let ((a-table (make-hash))) (λ(n) ...

How do I profile in DrScheme?

How Do I profile my functions using DrScheme? (require profile) (define (factorial n) (cond ((= n 1) 1) (else (* n (factorial (- n 1)))))) (profile factorial) The above code returns Profiling results ----------------- Total cpu time observed: 0ms (out of 0ms) Number of samples taken: 0 (once every 0ms) =============...

how to print a newline in a file in plt scheme?

I need to have a newline every time I write to a file in plt scheme. I wonder if there is a special procedure that allows me to do this. ...

How do I use Declarations (type, inline, optimize) in Scheme?

How do I declare the types of the parameters in order to circumvent type checking? How do I optimize the speed to tell the compiler to run the function as fast as possible like (optimize speed (safety 0))? How do I make an inline function in Scheme? How do I use an unboxed representation of a data object? And finally are any of these...

What are the things that optimize speed declaration do in CL?

What are some of the optimization steps that this command does `(optimize speed (safety 0))` Can I handcode some of these techniques in my Lisp/Scheme program? ...

Can I disassemble my code in PLTScheme?

Can I see the translated machine instruction of a scheme function like (disassemble) in LISP? ...

How to add up the elements for a structure in Scheme/Lisp

I have an input which is of this form: (((lady-in-water . 1.25) (snake . 1.75) (run . 2.25) (just-my-luck . 1.5)) ((lady-in-water . 0.8235294117647058) (snake . 0.5882352941176471) (just-my-luck . 0.8235294117647058)) ((lady-in-water . 0.8888888888888888) (snake . 1.5555555555555554) (just-my-luck . 1.3333333333333333)))...

How do I make a module in PLT Scheme?

I tried doing this: #lang scheme (module duck scheme/base (provide num-eggs quack) (define num-eggs 2) (define (quack n) (unless (zero? n) (printf "quack\n") (quack (sub1 n))))) But I get this error: module: illegal use (not at top-level) in: (module duck scheme/base (provide num-eggs qu...

How do you perform arithmetic calculations on symbols in Scheme/Lisp?

I need to perform calculations with a symbol. I need to convert the time which is of hh:mm form to the minutes passed. ;; (get-minutes symbol)->number ;; convert the time in hh:mm to minutes ;; (get-minutes 6:19)-> 6* 60 + 19 (define (get-minutes time) (let* ((a-time (string->list (symbol->string time))) (hour (first a-time)...

About "If.." in Scheme (plt-scheme)

I had a pretty simple requirement in my Scheme program to execute more than one statement, in the true condition of a 'if'. . So I write my code, something like this: (if (= 1 1) ((expression1) (expression2)) ; these 2 expressions are to be executed when the condition is true (expression3) ) Obviously, the above doesn't work, ...

How to write the Average Function for this Data structure in Scheme/Lisp?

I want to find the price of a new-item based on the average prices of similar items. The function get-k-similar uses k-Nearest Neighbors but returns me this output ((list rating age price) proximity). For example, 2-similar would be: (((5.557799748150248 3 117.94262493533647) . 3.6956648993026904) ((3.0921378389849963 7 75.614925605968...

Question about SimpleHTTPServer.py

I am partially through implementing the functionality of SimpleHTTPServer.py in Scheme. I am having some good fun with HTTP request/response mechanism. While going through the above file, I came across this- " # redirect browser - doing basically what apache does" in the code". Why is this redirection necessary in such a scenario? ...

What are "reduction semantics"? Please explain the use of PLT Redex in layman's term.

Somebody please explain the usage of reduction semantics and the PLT Redex in simpler language. Thanks. ...

How do I include files in DrScheme?

I'm using DrScheme to work through SICP, and I've noticed that certain procedures (for example, square) get used over and over. I'd like to put these in a separate file so that I can include them in other programs without having to rewrite them every time, but I can't seem to figure out how to do this. I've tried: (load filename) (loa...

Intuitive motivation for Literate Programming?

So, I used the scribble/lp module to write my first literate program using plt-scheme: #lang scribble/lp (require scribble/lp) <<lp_scheme.ss>> @chunk[<squarefunction> (define (f x) (* x x))] Nothing useful there, of course. Now I am sort of wondering why would I just not use plain comments, instead of literate prog...

Debugging Scheme in Emacs

I am shifting from DrScheme to Emacs to edit my PLT Scheme files. Can you teach me how to use steppers or debuggers in Emacs? Thanks. ...