racket

Racket URL dispatch

I'm trying to hook up URL dispatch with Racket (formerly PLT Scheme). I've taken a look at the tutorial and the server documentation. I can't figure out how to route requests to the same servlets. Specific example: #lang scheme (require web-server/servlet) (require web-server/dispatch) (provide/contract (start (request? . -> . respon...

Racket regular-expression matching

I'm trying to create a regex that matches the inverse of a certain string type (so, strings not ending in ".js", for example). According to the documentation, that should be the expression #rx"(?!\\.js$)", but it doesn't seem to work. To test it out, I have this function: (define (match-test regex) (map (lambda (text) (...

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

What are the best free Scheme implementations that you know about on Windows?

When I wrote best I meant: Speed, Have an IDE, a debugger, Compiling to machine code or some other language, Quality of implementation and, Completeness. ...

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

Find all paths from root to leaves of tree in Scheme

Given a tree, I want to find the paths from the root to each leaf. So, for this tree: D / B / \ A E \ C-F-G has the following paths from root (A) to leaves (D, E, G): (A B D), (A B E), (A C F G) If I represent the tree above as (A (B D E) (C (F G))) then the function g does the trick: (define (paths tree) (cond ...

Why does using cons to create a pair of two lists produce a list and two elements?

I've started learning Scheme, for fun mostly, and because I've never used a functional language before. I chose Scheme because I wanted to read SICP for a long time. Anyway, I'm currently learning about lists, and before that I learned about cons, car and cdr. And there's an example that creates a list of lists with cons, like this : ...

Help with dynamic-wind and call/cc

I am having some trouble understanding the behavior of the following Scheme program: (define c (dynamic-wind (lambda () (display 'IN)(newline)) (lambda () (call/cc (lambda (k) (display 'X)(newline) k))) (lambda () (display 'OUT)(newline)))) As I understand, c will be bound to th...

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

When did the idea of macros (user-defined code transformation) appear?

I have read McCarthy's 1960 paper on LISP and found no reference to anything that's similar to user-defined macros or normal order evaluation. I was wondering when marcos first appeared in programming language history (and also in Lisp history): When was the idea of user-defined code transformation (before interpretation or compilation...

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

Normal order and applicative order evaluation in Scheme

Hi All, For the 1st example given on site: View-Site, my understanding is that normal order evaluates to [6;1;1] and applicative order evaluates to [6;2;2] Can anyone please confirm my assessment? Regards, darkie ...

POST/GET bindings in Racket

Is there a built-in way to get at POST/GET parameters in Racket? extract-binding and friends do what I want, but there's a dire note attached about potential security risks related to file uploads which concludes Therefore, we recommend against their use, but they are provided for compatibility with old code. The best I can fi...