scheme

How can I check if a variable exists in Scheme?

Is there a way to check if a variable exists in Scheme? Even doing things like (if variable) or (null? variable) cause errors because the variable is not defined. Is there some function that returns whether or not a variable exists? ...

east asian language is broken when I make Executable in DrRacket(language is scheme)

hello~! I'm using DrRacket for Scheme Programming. for I'm not a person who use native English, I need to print out east asian language. there is no problem when I press run button in IDE. east asian language is printed well. but when I make an Executable file, and execute, east asian characters were broken when program prints out. ...

Is there an equivalent of Common Lisp's *print-circle* in Scheme?

I'm working on a deque in Scheme (SICP exercise 3.23) and I've got a simple doubly-linked list implementation I would like to test out, but I can't seem to find out how to print out a circular list in Scheme (mit-scheme and mzscheme/racket). In CL there is a flag print-circle for this sort of thing, is there anything equivalent in Schem...

What is the difference between an atom and a symbol in Common Lisp?

Are there any differences between what in Common Lisp you'd call an atom, and a symbol? Do these differences extend to other languages in the Lisp family? (I'm aware that atom has a different meaning in Clojure, but I'm interested in the boundaries of what is a symbol.) ...

Why the bleep isn't my continued fraction approximating properly?

Reading through more SICP and I'm stuck on exercise 1.3.8. My code works properly for approximating 1/phi, but doesn't work for approximating e - 2. (define (cont-frac n d k) (define (frac n d k) (if (= k 0) 1.0 (+ (d k) (/ (n (+ k 1)) (frac n d (- k 1)))))) (/ (n 1) (frac n d k))) (define (eulers-...

Equivalent of Scheme's dynamic-wind in Ruby

Ruby has continuations... does it have a dynamic-wind construct like Scheme? ...

GIMP - Scripting a canvas resize

Hello all, Just started using GIMP today. When I resize the canvas manually in GIMP (so that it's smaller than the image size) it lets me move the image around so that I can "change" the viewable area. How do I replicate this in a script? In other words, I want the script to pause at the canvas resizing step and let me position the imag...

Mechanics of variable capture with define-macro in Scheme

Hello, Consider this unhygienic Scheme macro: (define-macro for (lambda (i i1 i2 . body) (let ((start (gensym)) (stop (gensym)) (loop (gensym))) `(let ((,start ,i1) (,stop ,i2)) (let ,loop ((,i ,start)) (if (< ,i ,stop) (begin ,@body ...

What is wrong with my scheme code?

The function I wrote for SICP 2.20 is: (define (same-parity x . y) (if (null? (car y) '() (if (= (even? (car y)) (even? x)) (cons (car y) (same-parity (cons x (cdr y)))) (same-parity (cons x (cdr y)))))) And then I try to call it with (same-parity 1 2 3 4 5 6 7) The error I get is: "The object #t, passed as the fir...

Arithmetic with Church Numerals.

I am working through SICP, and the problem 2.6 has put me in something of a quandary. In dealing with Church numerals, the concept of encoding zero and 1 to be arbitrary functions that satisfy certain axioms seems to make sense. Additionally, deriving the direct formulation of individual numbers using the definition of zero, and an add-1...

Question about SICP chpt 4.1 : How does (analyze expr) help speed up eval?

I'm reading the following section of SICP http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1.7 According to the text, the following transformation of eval will improve offers a performance improvement, since an expression that gets evaluated many times will only be analyzed once? (define (eval exp env) ((analyz...

Scheme: Convert Code to picture

Hello Everyone, I have a weird Scheme question. This is a part of something bigger that I'm helping a friend with. I need to convert a Tree:Data into an image that accurately represents the tree (I'm sorry I don't have a sample image to show just yet). Please let me know if you have any ideas for this (and/or if you have questions) so...

Can you translate these 2 examples from Functional Languages 101 ? (Scheme -> Clojure)

Got these examples I would like to understand but they are in Scheme. I would like them in Clojure :D Example 1 - counting the length of a list (define length (lambda (ll) (cond ((null? ll) 0) (#t (add1 (length (cdr ll))))))) Exemple 2 - square each element of a list (define squares (lambda (li) (co...

Order of execation of commands in Scheme

Hi ! I am writing a program in scheme, that uses recursion to walk through the list, and stop at certain pointer, when counter reaches a certain number N (define (functX N lst) (define counter 1) (cond [(empty? lst) empty] [(negative? N) empty] [(< (length lst) N) empty] [(<= counter N) ((set! counter (+ counter 1))...

I have a variable that holds an expression. e.g: (> 1 2), how do i evaluate it?

So I wrote this code. How do i get the x in the if statement to evaluate? at the moment, x always succeeds, and the if statement never fails. (define expand (lambda (exp) (cond ((symbol? exp) exp) ((pair? exp) (case (car exp) ((and) (if (null? (cdr exp)) '(quote #t) (if (null? (cddr exp)...

Turning list-of-lists into set of lists in scheme?

Is there a general way to take a list of items and flatten it to depth zero? Eg: ((+ 1 2) (+ 3 4) (+ 4 5)) -> (+ 1 2) (+ 3 4) (+ 4 5) ...

Rebinding parameters to a function call in scheme>

I'm a bit of a scheme newbie and I'm trying to do write a function that takes a function name, and and an expression and binds the function name as the first argument of the expression. IE: Something like: (bind-function-name '+ '(param 'a "First")) Would produce a lambda that evaluates (param '+ 'a "First") Best I've come up wit...

Parameters for Structs in Scheme

I have this struct for people: (define-struct person ( first ; a string: first name last ; a string: last name sex ; a symbol: 'male, 'female eyes ; a symbol: 'blue, 'brown', 'green hair ; a symbol: 'blonde, 'brown, 'black, 'red mother ; a person: empty if not known f...

Creating Lists from files in Scheme

I've worked out how to read in the file and it works using the following code: (define p (read(open-input-file "starbucks4.sxml"))) But how do i store p as a list with elements separated by \n characters. Thanks. ...

Scheme looping through list

I am trying to write some code that will loop through a list and add like terms. For example if the input was ((2 1) (3 4) (5 3) (2 4)) the the result would be ((2 1) (5 4) (5 3)) but I am having trouble with the code. I'm trying to cons the cdr of the input list to a null list and then just compare the car of the list to the car of the ...