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

Advice on translating code from very unrelated languages (in this case Scheme to Python)?

Reasoning: I'm trying to convert a large library from Scheme to Python Are there any good strategies for doing this kind of conversion? Specifically cross-paradigm in this case since Python is more OO and Scheme is Functional. Totally subjective so I'm making it community wiki ...

using lambda instead of let in scheme

Hey, In SICP 1.2.1 there is a function that makes a rational number, as follow: (define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g)))) I'm just curious how you can implement the same thing using lambda instead of let, without calling GCD twice. I couldn't figure it out myself. ...

In SICP exercise 2.26 using DrScheme, why does cons return a list, instead of a pair of lists?

In SICP exercise 2.26, this Scheme code is given: (define x (list 1 2 3)) (define y (list 4 5 6)) Then this cons call is given: (cons x y) I expected a pair of lists would result, ((1 2 3) (4 5 6)) but the interpreter gives, ((1 2 3) 4 5 6) ...a list with 4 elements, the first being a list. Why is y treated differently? I've tried...

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

What is the meaning of this Scheme

Hi, I am new to Scheme, by looking at the Exercise 1.5 of SICP, what is the meaning/usage of this expression? (define (p) (p)) Thanks! ...

What the heck is the "Structure and Interpretation of Computer Programs" cover drawing about?

What the heck is the Structure and Interpretation of Computer Programs cover drawing about? I mean I know what "eval", "apply", and 'λ' all mean, but I'm having a hard time deciphering the rest of the picture. Who the heck is the maiden? Does she work for the wizard? Why the heck is she pointing at the table? Is she pointing at that...

How do I write a scheme macro that defines a variable and also gets the name of that variable as a string?

This is mostly a follow-up to this question. I decided to just keep YAGNI in mind and created a global variable (libpython). I set it to #f initially, then set! it when init is called. I added a function that should handle checking if that value has been initialized: (define (get-cpyfunc name type) (lambda args (if libpyt...

scheme2lisp::define function and pass it as parameter

Hi! I need to translate some code from Scheme to Common Lisp. Now, I have something like this: (defun sum (term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) b)))) (defun sum-int (a b) (defun (ident x) x) (sum ident a 1+ b)) but it produces errors. * - DEFUN: the name of a function must be a symbol, not (I...

Are there any Python reference counting/garbage collection gotchas when dealing with C code?

Just for the sheer heck of it, I've decided to create a Scheme binding to libpython so you can embed Python in Scheme programs. I'm already able to call into Python's C API, but I haven't really thought about memory management. The way mzscheme's FFI works is that I can call a function, and if that function returns a pointer to a PyObj...

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

What's the point of lambda in scheme?

I am learning scheme. I know how to use both lambda and let expressions. However I'm struggling to figure out what the point is of using lambda. Can't you do everything with let that you can with lambda? It would be especially helpful to see an example of a situation where a lambda expression is a better choice than let. One other thi...

Scheme standard functions?

Where can I find a list of the scheme standard functions and descriptions for how to use them? ...

Scheme define/lambda shorthand

In Scheme, how can I make use of the define/lambda shorthand for nested lambda expressions within my define? For example given the following procedure... (define add (lambda (num1 num2) (+ num1 num2))) One can shorten it to this: (define (add num1 num2) (+ num1 num2)) However, how can I shorten the following function simi...

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

Why are most S-Expression languages dynamically typed?

How come most Lisps and Schemes are dynamically typed? Does static typing not mix with some of their common features? ...

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

Do you have to use display to output stuff using r6rs?

Background: I am new to scheme, and am using DrScheme to write my programs. The following program outputs 12345 when I run the program as r5rs: 12345 However the following program outputs nothing (it's an r6rs program): #!r6rs (import (rnrs)) 12345 That being said, I can get it to output 12345 by doing this: #!r6rs (import (rnrs...