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

When should I use `protect-out` in Racket?

Racket provides protect-out to prevent module exports from being used with eval (or a deconstructed syntax object), unless the module has enough privileges (aka, has a strong enough code inspector). The docs also provide a good example for what it…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
2 answers

define-match-expander

about the define-match-expansion, there are rare materials and example codes to illustrate the concepts. I am having a hard time to "decode" what the documentation says: (define-match-expander id proc-expr) (define-match-expander id proc-expr…
user618815
7
votes
2 answers

What is the usecase of add1 and sub1?

In Racket, there are two Generic Number procedures named add1 and sub1, equivalent to (curry + 1) and (curryr - 1) respectively. Are these procedures for stylistic use or do they have some sort of optimization benefit? What is the history behind…
Winny
  • 1,189
  • 1
  • 16
  • 29
7
votes
3 answers

Cross-compilation in Racket/Scheme language

Is it possible to compile for Windows or Mac OSX while working in Linux for Racket programming language (cross-compile)? DrRacket IDE does not provide any such menu item. Raco help command also did not show any such option: $ raco help make raco…
rnso
  • 23,686
  • 25
  • 112
  • 234
7
votes
1 answer

Struct Properties vs Generics in Racket

Racket seems to have two mechanisms for adding per-type information to structs: generics and properties. Unfortunately, the documentation doesn't seem to indicate when one is preferred over the other. The docs do say: Generic Interfaces provide a…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
2 answers

How to set language to htdp/bsl in REPL

I have the following htdp/bsl program saved as example.rkt: #lang htdp/bsl (+ 1 1) When the above is run using racket example.rkt, the output is as expected (i.e. 2). However, when I try to start an REPL with htdp/bsl as the language (racket -I…
Flux
  • 9,805
  • 5
  • 46
  • 92
7
votes
1 answer

Does the DrRacket interpreter use normal-order evaluation based on SICP Exercise 1.5?

One must decide, based on the value of: (test 0 (p)) where test is defined as : (define (test x y) (if (= x 0) 0 y)) and p is defined as : (define (p) (p)) When I evaluate (test 0 (p)) the interpreter goes into an infinite loop,…
Geoffrey
  • 5,407
  • 10
  • 43
  • 78
7
votes
1 answer

Call `atexit` when linking to libc dynamically on Linux

If I have the following program written in C (compiled with GCC on Debian 8.7), I am able to call atexit() as you would expect: #include void exit_handler(void) { return; } int main () { atexit(exit_handler); return…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
1 answer

Optional arguments and dots in scheme

So, I am trying to see how functions that can accept any number of arguments work? I tried this (define (plus x . xs) (if (null? xs) x (plus (+ x (car xs)) . (cdr xs)))) (plus 1 2 3 4) But is seemed that it wasn't actually applying cdr to…
Theo Belaire
  • 2,980
  • 2
  • 22
  • 33
7
votes
1 answer

Bidirectional HashMap in Racket

Does Racket have a bidirectional hashmap? That is, a hash map that can in constant time, be given a key and look up the value, or given the value and look up the key? I would be happy for an API that looks something like this: #lang racket (define…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
1 answer

Installing packages in Racket

I installed DrRacket, the full version not the minimal but I don't have the packages. When I run this code: #lang racket (provide (all-defined-out)) (require rsound) (play ding) It gives me this error: standard-module-name-resolver: collection…
Theodor Berza
  • 573
  • 3
  • 12
7
votes
3 answers

How can I group optional attributes captured with syntax-parse?

When writing a macro that uses syntax/parse, I have created a splicing syntax class that captures options that may be provided to the macro. These options are all optional, and they may be provided in any order. Using the ~optional ellipsis head…
Alexis King
  • 43,109
  • 15
  • 131
  • 205
7
votes
3 answers

racket to-string function for integer and string

Need to write a to-string function that accepts integer and string. (to-string 3) ; -> "3" (to-string "hello") ; -> "\"hello\"" (to-string "hel\"lo") ; -> "\"hel\\\"lo\"" I managed to do so with: (define (to-string x) (define o…
Albert Netymk
  • 1,102
  • 8
  • 24
7
votes
2 answers

Require identifiers not provided by a module in Racket

Let's say I have some file a.rkt: #lang racket (define a 12) I now want to write some test cases, using the file b.rkt that requires a.rkt: #lang racket (require "a.rkt") a Is there any way I can get b.rkt to recognize the identifier defined in…
Leif Andersen
  • 21,580
  • 20
  • 67
  • 100
7
votes
2 answers

How to format output using racket

How do I format output using racket? I want to output a fixed-width number and fill it with 0 if the width is too small? How can I do it? I have searched the racket documentation but I can only find fprintf, which seems to be unable to do it.
tian tong
  • 793
  • 3
  • 10
  • 21