scheme

Detecting EOF in a Binary File using Scheme

(define (read-all-input) (local ((define line (bytes->list (read-bytes 4)))) (if (eof-object? line) empty (cons line (read-all-input))))) (void (read-all-input)) The above code fails because bytes->list expects an argument of type byte string, but is given # ...

Lists in scheme

Hi, I'm trying to write a function in scheme that takes a list and squares every item on the list, then returns the list in the form (list x y z). However, I'm not sure how to write a code that will do that. So far, I have (define (square=list list) (cond [(empty? list) false] [else (list (sqr (first a-list))(square-list (res...

Real-World Scheme OOP Programs?

I am working on a sort of "bug finder" for Scheme (R5RS) and I want to try if and how well it would work for object-oriented programming. Therefore I was looking at some of the numerous object systems for Scheme (for example, Tiny-CLOS, Prometheus, and YASOS). Of course, in order to find bugs, I have to have code in which I can search t...

Convert Byte String to Int in Scheme

I have code like this to convert hex into byte string (define (word->bin s) (let ((n (string->number s))) (bytes (bitwise-and (arithmetic-shift n -24) #xFF) (bitwise-and (arithmetic-shift n -16) #xFF) (bitwise-and (arithmetic-shift n -8) #xFF) (bitwise-and n #xFF)))) (word->bin "#x10000002") I'm thinking of a similar...

Help understanding Sieve of Eratosthenes implementation

This is boring, I know, but I need a little help understanding an implementation of the Sieve of Eratosthenes. It's the solution to this Programming Praxis problem. (define (primes n) (let* ((max-index (quotient (- n 3) 2)) (v (make-vector (+ 1 max-index) #t))) (let loop ((i 0) (ps '(2))) (let ((p (+ i i 3)) (startj...

Solving X from linear equations in Scheme?

I want to solve x. How can I do it in Scheme? T1-F2=0 F1+T2=GM-Gm Cos(60)(2.5*Gm+x*GM-l*F1)-l*Sin(60)*T1=0 F1=0.1*T1 F2=0.3*T2 M=20 m=80 l=5 My try is: (lambda T1 . ;; T1=F2 (lambda F2 . ;; F2=0.3*T2 (lambda F1 . ;; F1=0.1*T1 (lambda Gm . ( lambda GM . (- ( * 1/2 ( - ...

What is the best Scheme implementation for (sys-admin) shell scripts?

I've gone through the academic Scheme stuff (read SICP, The Little Schemer, The Seasoned Schemer, TSPL) and been playing with Scheme as a toy for a while. But I want to get practical. Today I needed to write a shell script to do some batch file processing, and thought "why not do it in Scheme?". I did, and it was a joy. Now I'm forced ...

getting an interval of a vector

I want to take an interval of a vector in Scheme. I know there is a procedure named vector->values, but seems like it returns each element separately, while I want to get the result as a vector. How can I achieve this? > (vector->values (vector 1 2 3 4 5) 0 3) 1 2 3 while I need: #(1 2 3) ...

scheme and if condition

Hi I want to return nothing when if condition is not met, for instance (if x y z) so if x is not met, z will be executed and I want to do nothing at z, just same as pythons "pass" ...

"unfold" for common lisp?

I learned quite a bit of scheme from SICP but am more interested in common lisp now. I know common lisp's fold is reduce, with special arguments for left or right folding, but what is the equivalent of unfold? Googling has not helped much. In fact I get the impression there is no unfold??? ...

What does this xkcd code do?

On the xkcd site today, the following appeared as a joke in a <script language="scheme"> tag so what does the following code do / represent? (define (eval exp env) (cond ((self-evaluating? exp) exp) ((variable? exp) (lookup-variable-value exp env)) ((quoted? exp) (text-of-quotation exp)) ((assignment? exp) ...

Recommendations for OpenGL / Scheme combination

I'd like to try out OpenGL programming in Scheme. Can anyone give a recommendation for a decent Scheme compiler / OpenGL library combination? I have no reservations, though it would be nice (but not a requirement) to be able to produce native, executable binaries primarily on Windows, but also on UNIX and/or Mac OS X. EDIT: Changed t...

SICP exercise 1.16, where is my bug, because it looks right to me

I've just started working through this book for fun; I wish it were homework, but I could never afford to attend MIT, and there are tons of people smarter than me anyway. :p fast-exp is supposed to find b^n, i.e. 4^2 = 16, 3^3 = 27 (define (fast-exp b n) (define (fast-exp-iter n-prime a) (cond ((= n-prime 1) a) ((= (rem...

How To Build a DrScheme Teach Pack

Hello, I'm learning PLT Scheme and I want to know how can I build a Teach Pack for DrScheme, some tutorials...? Thanks. ...

Scheme/Lisp nested loops and recursion

I'm trying to solve a problem in Scheme which is demanding me to use a nested loop or a nested recursion. e.g. I have two lists which I have to check a condition on their Cartesian product. What is the best way to approach these types of problems? Any pointers on how to simplify these types of functions? I'll elaborate a bit, since m...

Converting a Scheme expression to a string

Given an expression '(lambda (x) x) How can I translate this into a string. I thought symbol->string will do the job but no it cant not a symbol. e.g for a macro to-string: (to-string (lambda(x) x)) this should return >> "(lambda (x) x)" Any ideas folks Thanks ...

PLT Scheme noob: Boolean and/or aren't procedures?

I'm trying to make a truth-table generator for a digital electronics course because that's how I have fun in my spare time and don't judge me. Anywho, I figured I'd have a hash with the string equivalent of operators as keys, and the Scheme procedures that correspond to those operators as values. E.g. (define operator-table #hash(("...

What are some of the requirements that IronScheme couldn't complete?

According to Wikipedia: "IronScheme, an upcoming Scheme implementation, was planning to build upon the DLR, but decided to abandon this idea because the DLR branch the project used became out of sync with the trunk, and also because the DLR, according to the developers, could not support the majority of the Scheme's requirements" Does a...

Finding if a number is the power of 2 in Scheme

I'm fairly new to Scheme and am attempting to learn it on my own from scratch. I'm stuck on the syntax of this problem. I know that if I want to find out if a number is a power of 2, in C for instance, I would simply do: return (x & (x - 1)) == 0; which would return true or false. How would I be able to convert this into a couple simp...

how to convert a list to num in scheme?

like convert (1 2 3 4) to 1234~ ...