Questions tagged [racket]

Racket is an extensible multi-paradigm programming language in the Lisp/Scheme family.

Racket is a general purpose, multi-paradigm programming language in the Lisp/Scheme family. One of its design goals is to serve as a platform for language creation, design, and implementation. The language is used in a variety of contexts such as scripting, general-purpose programming, computer science education, and research.

Racket Programming Books

Racket documentation is well written and directly accessible from within the DrRacket IDE. It has two great tutorials: one on web applications and one about systems programming.

A great tutorial on macros.

History: Racket was initially called PLT Scheme.

Questions about BSL, HTDP, and other student languages should go into the racket-student-languages tag instead.

5811 questions
7
votes
1 answer

Racket as scripting language in a game engine

I would like to add scripting capabilities to my C++ game engine. I have Engine.exe, Physics.dll, Audio.dll and I'm adding Scripting.dll which is a high-level Racket wrapper. Engine.exe loads Physics.dll and sets up physics world, loads Audio.dll…
7
votes
2 answers

Avoid displaying 3 time a struct

I have define a struct as below, (struct vector (x y z) #:methods gen:custom-write [(define (write-proc vector port mode) (let ([print (if mode write display)]) (write-string "<") (print (vector-x vector)) (write-string…
mathk
  • 7,973
  • 6
  • 45
  • 74
7
votes
1 answer

RackUnit source location inside of macros

I am building a set of rackunit tests, where the actual test-case and check-equal? function is defined in a macro. The code looks something like this: #lang racket (require rackunit rackunit/text-ui) (define-syntax (my-test=? stx) …
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
1 answer

"unbound identifier in module" error in Racket

I'm writing a function in Racket, using DrRacket: (define (same-parity a .b) (let ((remain (remainder a 2))) (define (recur-part remain-list) (cond ((= remain (remainder (car remain-list) 2)) (append remain-list (list (car…
Leo
  • 492
  • 1
  • 5
  • 15
7
votes
2 answers

Racket REPL and Submodules

Is there an easy way for me to load a submodule in the current file in racket-mode in emacs? For example if I have the following file #lang racket (define (foo x) x) (module+ sub (define (bar x y) x)) and I hit f5 in racket-mode to start…
Max New
  • 182
  • 8
7
votes
1 answer

How would I make this Racket code DRYer?

I'm porting a Python script to Racket as a learning experience, and I have this function: (define (check-status) (define git [find-executable-path "git"]) (define-values (ckot out in err) (subprocess #f #f #f git "checkout" "-q"…
Jonathan
  • 539
  • 4
  • 15
7
votes
1 answer

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) …
josh
  • 997
  • 1
  • 8
  • 13
7
votes
5 answers

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,…
fingerprint211b
  • 1,176
  • 12
  • 24
7
votes
3 answers

If else clause or cond in Racket

I am trying to write a simple program in Racket that prints 1 if the value of a is > 1, prints 0 if the value of a = 0 and -1 if a < 0 . I wrote the following but looks like it is not taking care of the third condition. Actually, I have not included…
user3400060
  • 299
  • 3
  • 9
  • 23
7
votes
4 answers

Returning from a function inside when statement

All I'm trying to do is use a when statement to return a value :( I want the functionality of: if(x) return y And I'm trying to use: (when (x) y) But the when statement is not evaluating in a way that exits the function and return y. It just…
Roguebantha
  • 814
  • 4
  • 19
7
votes
1 answer

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…
Cam
  • 14,930
  • 16
  • 77
  • 128
7
votes
1 answer

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…
Inaimathi
  • 13,853
  • 9
  • 49
  • 93
7
votes
1 answer

What is this hashtag in the Racket code?

I have the following code: (plot (function sin (- pi) pi #:label "y = sin(x)")) But while solving SICP I did not encounter such a construct: #:label "y = sin(x)" What does the hash tag mean?
user1932898
7
votes
3 answers

Macro-defining macro in Racket?

In Common Lisp it is relatively easy to create a macro-defining macro. For example, the following macro (defmacro abbrev (short long) `(defmacro ,short (&rest args) `(,',long ,@args))) is a macro-defining macro, because it expands to another…
Racket Noob
  • 1,056
  • 1
  • 8
  • 16
7
votes
2 answers

printf %6.2f in scheme or racket?

How do you get a printf %6.2f in scheme or racket, as you would in C? Right now all I have is printf "The area of the disk is ~s\n" ( - d1 d2), but I can't format the output to a specific floating point format. Thanks
user3161399
  • 253
  • 2
  • 6