scheme

Little Schemer eqlist? function - alternate version?

Hi, I'm going through the "Little Schemer" book, and doing the various functions. Generally I end up with the same version as the books, but not for eqlist?, which is a function to test the equality of two lists. I've tried testing my version and it passes anything I throw at it. Yet it's slightly different from the "Little Schemer" ...

Chez Scheme allocation: --program vs --script

Hello, Consider this bit of Chez Scheme code: (import (chezscheme)) (define (list-enumerate ls val proc) (let loop ((ls ls) (return? #f) (val val)) (if (or (null? ls) return?) val (call-with-values (lambda () (proc val (car ls))) (lambda (return? val) (loop (cdr ls) return? val)...

Inheritance classes in Scheme

Now I research OOP-part of Scheme. I can define class in Scheme like this: (define (create-queue) (let ((mpty #t) (the-list '())) (define (enque value) (set! the-list (append the-list (list value))) (set! mpty #f) the-list) (define (deque) (set! the-list (cdr the-list)) (if (= (length t...

Scheme Programming finding items in nested loops

I have the following items (define itemslist (list 'a1 'b2 'c3 (list 'z1 'z2) 'd5 'e6)) My method to find items is below (define find-item (lambda (item itemslist) (cond ((null? itemslist) #f) ((list? (car itemslist)) (cond ((null? itemslist) #f) (else (find-item item (car itemslist))))...

Traversing Scheme function as a list

Isn't it possible to treat functions in Scheme as any other list? Basically, what I want do to is something like this: (define (foo) "hello") (cdr foo) ; or similar, should return the list ((foo) "hello") I've found a similar discussion about this, and I feel a bit disappointed if this is not possible with Scheme. If so, why is th...

What are circular lists good for (in Lisp or Scheme)?

I note that Scheme and Lisp (I guess) support circular lists, and I have used circular lists in C/C++ to 'simplify' the insertion and deletion of elements, but what are they good for? Scheme ensures that they can be built and processed, but for what? Is there a 'killer' data structure that needs to be circular or tail-circular? ...

What are some good resources for learning how to implement Scheme Macros?

I've written a Scheme-ish language compiler/vm in JavaScript. http://github.com/z5h/zb-lisp Dybvig's "Three Scheme Implementations" paper (available on my github) was hugely important in getting stuff like tail-call-optimization, call/cc and other things working. I'm thinking about adding some type of macro support. And wondering if the...

Getting reference to the JavaScript Function object behind an operator

Here is a lisp procedure that simply adds 'a' to the absolute value of 'b': (define (a-plus-abs-b a b) ((if (> b 0) + -) a b)) I think this is beautiful, and I am trying to find the best way of writing this in JavaScript. But my JavaScript code is not beautiful: var plus = function(a,b) { return a + b; }; var minus = function(...

Scheme early "short circuit return"?

I'm trying to find out how I can do an "early return" in a scheme procedure without using a top-level if or cond like construct. (define (win b) (let* ((test (first (first b))) (result (every (lambda (i) (= (list-ref (list-ref b i) i) test)) (enumerate (length b))))) (when (and (not (= test 0)) result) ...

Generating list of million random elements

How to efficiently generate a list of million random elements in scheme? The following code hits maximum recursion depth with 0.1 million itself. (unfold (lambda(x)(= x 1000000)) (lambda(x)(random 1000)) (lambda(x)(+ x 1)) 0) ...

How to create and add elements in a list in Scheme?

I want to define a method that take an integer as input and creates dynamically a list of all descending integer numbers to zero. I find trouble into calling method for the n-1 element ...

Fermat factorization method limit

I am trying to implement Fermat's factorization (Algorithm C in The Art of Computer Programming, Vol. 2). Unfortunately in my edition (ISBN 81-7758-335-2), this algorithm is printed incorrectly. what should be the condition on factor-inner loop below? I am running the loop till y <= n [passed in as limit]. (if (< limit y) 0 (factor-inn...

Vector addition of lists

If I had a N lists each of length M, how could I write a nice clean function to return a single list of length M, where each element is the sum of the corresponding elements in the N lists? (starting to learn lisp - go easy!) ...

How to determine if CNF formula is satisfiable in Scheme?

Program a SCHEME function sat that takes one argument, a CNF formula represented as above. If we had evaluated (define cnf '((a (not b) c) (a (not b) (not d)) (b d))) then evaluating (sat cnf) would return #t, whereas (sat '((a) (not a))) would return (). You should have following two functions to work: (define comp (lambda (lit) ; ...

Suggest resources for learning Scheme.

I'll be starting a new job soon where Scheme is heavily used. I currently do not know Scheme, but my employer assures me that is not a problem. Regardless I'd like to hit the ground running and have a working knowledge of the language before my start date. So I'm looking for good resources from which to learn Scheme. I have had minim...

How to Design Programs: An Introduction to Programming and Computing -- teacher guide access

Hello -- I'm a biologist switching careers, and trying to learn programming as a result. I stumbled upon the aforementioned book on Amazon, which jived with my liberal arts background. Despite my great satisfaction with the didactic approach, I was frustrated to see that the answers to the exercises are restricted to teachers only. A...

How to import .class file in a .java file?

Hi, What i need to do is as follows: I have a bigloo scheme program (*.scm), then using the bigloo frameworks jvm a class file is generated. I want to use this .class file from a .java file. That is, i need to import this(.class) file as i want to use some functions defined in the scheme file which is now a .class file. How do i do it...

Scheme how do you remove the first element from a list?

How do i remove the first element from a list in scheme say it looks something like '((apple bob car) (cat dig) (e))) how would i just get rid of "apple" and leave the rest alone? ...

Rewriting UNIX cal(1)

Hello, Today I was testing out SRFI 19 and wrote a simple version of the UNIX cal(1) command. Here's a version in R6RS Scheme which runs in Ikarus, Ypsilon, and Larceny. A few example runs. Schemers: How would you write it? Use your favorite implementation. Ruby and Python: I'm guessing that y'all have elegant date and time libraries...

Cartesian product in Scheme

I've been trying to do a function that returns the Cartesian Product of n sets,in Dr Scheme,the sets are given as a list of lists,I've been stuck at this all day,I would like a few guidelines as where to start. ----LATER EDIT ----- Here is the solution I came up with,I'm sure that it's not by far the most efficent or neat but I'm only ...