plt-scheme

How do I define functions using Racket/PLT Scheme macros?

I am trying to write a macro that defines a special class of data structure with associated functions. I know this is possible; it is done multiple times in the core language itself. As a specific example, how would I define the define-struct macro in Scheme itself. It needs to create make-struct, struct-<<field>>, etc functions. I tr...

In PLT scheme, can I export functions after another function has been called?

I'm trying to create a binding to libpython using scheme's FFI. To do this, I have to get the location of python, create the ffi-lib, and then create functions from it. So for instance I could do this: (module pyscheme scheme (require foreign) (unsafe!) (define (link-python [lib "/usr/lib/libpython2.6.so"]) (ffi-lib lib)) ...

PLT Scheme Extracting field ids from structures

I want to see if I can map PLT Scheme structure fields to columns in a DB. I've figured out how to extract accessor functions from structures in PLT scheme using the fourth return value of: (struct-type-info) However the returned procedure indexes into the struct using an integer. Is there some way that I can find out what the fi...

Arrays in scheme / Memoization

How can I use arrays in scheme? In particular, I'm attempting to implement a recursive fibonacci procedure using memoization. Do arrays even exist in scheme? If not, how can I implement memoization? ...

Lists as arguments in Scheme

Let's say I have a procedure foo that takes three arguments, and returns a list of them all doubled: (define (foo a b c) (list (* 2 a ) (* 2 b) (* 2 c))) What I'd like to be able to do is create another procedure which accepts a list, and calls foo using the list elements as arguments, like this: (define (fooInterface myList) .....

Multidimensional vectors in scheme?

I earlier asked a question about arrays in scheme (turns out they're called vectors but are basically otherwise the same as you'd expect). Is there an easy way to do multidimensional arrays vectors in PLT Scheme though? For my purposes I'd like to have a procedure called make-multid-vector or something. By the way if this doesn't alrea...

Methods and properties in scheme - is object oriented programming possible in scheme?

I will use a simple example to illustrate my question. In Java, C, or any other OOP language, I could create a pie class in a way similar to this: class Apple{ public String flavor; public int pieces; private int tastiness; public goodness(){ return tastiness*pieces; } } What's the best way to do that with ...

Why do all procedures have to be defined before the compiler sees them?

For example, take a look at this code (from tspl4): (define proc1 (lambda (x y) (proc2 y x))) If I run this as my program in scheme... #!r6rs (import (rnrs)) (define proc1 (lambda (x y) (proc2 y x))) I get this error: expand: unbound identifier in module in: proc2 ...This code works fine though: #!r6rs (import (rnr...

mutation...........

I'm kinda confused..... (define m (list 1 2 3 '(5 8))) (let ((l (cdr m))) (set! l '(28 88))) ==>(1 2 3 (5 8)) (define o (list 1 2 3 '(5 8))) (let ((l (cdr o))) (set-car! l '(28 88))) ==> (1 (28 88) 3 (5 8)) Why does (set! l '(28 88))) not update m? ...

Does Scheme work with Microsoft COM?

I'm new to Scheme -- the functional programming language and I like it a lot for its first-class/higher-order functions. However, my data comes from a COM source with an object-oriented API. I know Scheme and COM belong to different programming paradigms, but I'm wondering if there is any interface or a way for Scheme to connect to a C...

Alternatives when pattern matching in racket (nee PLT Scheme)

I want to match one of the following two lists in Racket (formerly PLT Scheme): '(somename : (_ptr o sometype)) or '(somename : (_ptr io sometype)) As you can see, the only difference is the literals 'o and 'io in the embedded list. I can see two basic ways to do this. Either: (match myexpr [(list name ': (list '_ptr 'o _)) ...

DrRacket, R5RS and the error procedure.

I love DrRacket IDE (formerly DrScheme) but currently i'm building a pet project where i would like to be independent from it, meaning i'm commited to use only R5RS standard procedures. The thing is, in DrRacket there's this procedure called "error" which i would like to continue using but i can't find it in the Standards. What i woul...

String length in Scheme

Hi All, I am not able to understand the error with the code below which simply prints the length of the string: (define codeLen (read)) (display codeLen) (define code (read)) (display code) (string-length code) I am getting an error : string-length: expects argument of type <string>; given a regards, darkie ...

CAR and CDR of a list in Scheme

Hi all, I am confused as to how car and cdr work on lists. Here is an example of what I have tried: (define sample (read)) (display sample) (display (car sample)) (display (cdr sample)) (display (car (cadr sample))) (display (cdr (cdr sample))) On entering the value '(A B C D E F), here is what I get: '(a b c d e f) quote ((a b c d...

Adding an element to List in Scheme

Hi All, Below is my code which takes a car element of a list(carVal) and an list(initialized to empty) as parameters. I want to append the element to the list but the same is not working. (define populateValues (lambda (carVal currVal) (append currVal(list carVal )) (display currVal))) The display shows empty list all...

Using "and" in Scheme

Hey, I'm trying to use and in a cond statement. Basically, instead of simply checking that <exp1> is true before running some code, I need Scheme to check that <exp1> AND <exp2> are true. I understand that (and #t #f) evaluates to #f and that (and (= 10 (* 2 5)) #t) evaluates to #t. Unfortunately, Scheme will not accept (and (eqv? (len...

Recursion & lists in Scheme

I've been trying to learn some programming on my own by working through the textbook How to Design Programs for Scheme. I've gotten through everything until now. Here's the problem: 9.5.5 Develop the function convert. It consumes a list of digits and produces the corresponding number. The first digit is the least significant, ...

Achieving variables in the local syntax in the Scheme environment

How we can achieve variables that we defined in the (local ...) syntax in Scheme? For example in this code below, (define (erkan x) (local ((define y 10)) (* x y))) how can I directly get the value of y ? ...

Missing method in mred:canvas%?

I used MrEd Designer to make a user interface for a Scheme program. It includes a mred:canvas% on which I'd like to plot points using draw-point. It's defined as: (define (naca-ui-init {...} #:airfoil-canvas-class (airfoil-canvas-class canvas%) {...}) and later: (set! airfoil-canvas (new ...

Finding a prime number in Scheme using natural recursion

I'm still plugging away at the exercises in How to Design Programs on my own, but have managed to get stuck again. This time it's question 11.4.7: Develop the function is-not-divisible-by<=i. It consumes a natural number [>=1], i, and a natural number m, with i < m. If m is not divisible by any number between 1 (exclusive) ...