scheme

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

EVAL in SCHEME

Peter Norvig in PAIP says: " in modern lisps...eval is used less often (in fact, in Scheme there is no eval at all)" " if you find yourself using eval, you are probably doing the wrong thing". What are some of the ways to circumvent using eval in scheme? Arent there case where eval is absolutely necessary? ...

How do I apply a symbol as a function in Scheme?

Hi, Is there a way I can apply '+ to '( 1 2 3)? edit: what i am trying to say is that the function i get will be a symbol. Is there a way to apply that? Thanks. ...

Position Independent Parameters to Scheme Functions

How do I pass position-independent parameters to scheme functions? ...

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

Append! in Scheme?

I'm learning R5RS Scheme at the moment (from PocketScheme) and I find that I could use a function that is built into some variants of Scheme but not all: Append! In other words - destructively changing a list. I am not so much interested in the actual code as an answer as much as understanding the process by which one could pass a list...

Scheme Coding Style Questions

I am confused about the Scheme style for my code. Should I format if forms as: a. if() () () or b. if () () () or c. if () () () Should I format cond clauses as a. cond () () or b. cond () () When do I use a single ; to comment and a double ;;? ...

How to improve this mergesort in scheme ?

Hi, I am a C++ programmer, I wrote this code to see if I can think functionally :) Any hints to improve it ? (define (append listOne listTwo) (cond ((null? listOne) listTwo) (else (cons (car listOne) (append (cdr listOne) listTwo))))) (define (merge listOne listTwo) (cond ((null? listOne) listTwo) ((null? listTwo) l...

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

Specifics of call/cc

This is related to http://stackoverflow.com/questions/612761/what-is-call-cc, but I didn't want to hijack this question for my own purposes, and some of its arguments like the analogy to setjmp/longjmp evade me. I think I have a sufficient idea about what a continuation is, I think of it as a snapshot of the current call stack. I don't ...

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

Simplest example of need for "unification" in type inference

I'm trying to get my head around how type inference is implemented. In particularly, I don't quite see where/why the heavy lifting of "unification" comes into play. I'll give an example in "pseudo C#" to help clarify: The naive way to do it would be something like this: Suppose you "parse" your program into an expression tree such tha...

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