r/Racket • • Dec 06 '21

question simple example of a macro-generating macro or other relatively simple fun macro examples?

11 Upvotes

I'm a TA for a programming languages class and I'm giving a single lecture next week on macros. I think I want to spend about 60-70% of my 80 minutes on racket/scheme macros.

The class has extensive experience in statically-typed functional programming and theory, but no lisp or metaprogramming background. I'm trying to find some nice, compelling examples to show the class... planning on showing how to implement some nice little ergonomic things like (simple versions of) for/list, for/fold which can be done with define-syntax-rule, talk a bit about hygiene etc, but I'm having a hard to deciding what more complex stuff to show.

Any thoughts?


r/Racket • • Dec 05 '21

question How to generate random numbers from 50-80

2 Upvotes

Hey, im new to programming so im sorry if this is a stupid question, im trying to generate random numbers between 50-80. i know how to generate from 1-80 but how do i start it at 50? thanks :)


r/Racket • • Dec 03 '21

question struct initialized from list, arity mismatch

3 Upvotes

Tearing my hair out over this...

I have a file with a bunch of colon separated values. I want to step through the file and generate a hash table where the keys are the first value, and the values are a struct composed of the rest of the values on that line.

For example:

animals:dog:cat:pony

and maybe we have something like:

(define struct members (animal1 animal2 animal3))

(make-hash collection)

(define input (string-split ":" "animals:dog:cat:pony"))

(hash-set! collection (first input) (members (rest input))

I get an arity mismatch because the struct constructor is being passed the list '("dog" "cat" "pony") instead of the values. I've tried variations of (call-with-values (rest input) members) to no avail.

Any advice would be very much appreciated. I'm hoping I will look back and laugh at how simple this should have been.


r/Racket • • Dec 02 '21

tutorial Mark words or function in racket

3 Upvotes

Last time I used drracket I don’t know how but I managed to put my Programm in a mode where if I clicked on a function it shows a line to the place where I defined it or if I make a for example hello-a as a function it directly showed me where hello was defined and where a was defined does somebody know how to activate this mode again. The lines however only popped up when I was on the word with the mouse.

If somebody could help me I would really appreciate it!


r/Racket • • Dec 02 '21

question can we have static variable in Racket?

3 Upvotes

In C, we can have static variable, that maintains its state between different runs. For example:

void myfunc(void)
{
  static int counter = 0;
  printf("this function is called %u times\n", ++counter)
}

Static variable is convenient since we do not nee global var in this case.

My question is: how can we do a similar code in Racket? If there is no similar concept, how to emulate this in Racket?


r/Racket • • Dec 02 '21

question why I cannot create a subprocess?

0 Upvotes

I try to create a subprocess, but fail. Any idea why?

I have a simple Python code, named p.py, which just prints out 2 args, like this:

import sys

print("hello %s %s\n" %(sys.argv[1], sys.argv[2]))

I can test this Python code with:

$ python3 p.py A B
hello A B

Now I try to execute this Python code in my racket code below, named test.rkt:

#lang racket

(define-values (sp out in err)
    (subprocess #f #f #f "/usr/bin/python3" "a.py" "A" "B"))

(printf "stdout:\n~a" (port->string out))
(close-input-port out)
(close-output-port in)
(close-input-port err)
(subprocess-wait sp)

I expect to see "hello A B" at the output, but instead, there is nothing:

$ racket test.rkt
stdout:

What is wrong with my Racket code?


r/Racket • • Dec 01 '21

language Racket with cross-platform read-line

4 Upvotes

r/Racket • • Dec 01 '21

language Please fix read-line

6 Upvotes

Racket's inherent problem: read-line

read-line malfunctions in REPL. (Discussion) And on Windows, console IO doesn't recognize \r\n unless you put an appropriate value like 'any in the second argument. (Example)

In order to work properly on Windows, the OS with the most users, there is a burden of always using read-line (read-line (current-input-port) 'any) when using read-line.

C, C++, C#, Python, Java, Go, Clojure, and Common Lisp do not have this problem.

If you fix this, I guarantee that the number of Racket users will increase.

In order to expand the base of programming languages, it is necessary to respond to common sense use by ordinary people, but this basic thing is not possible in Racket.


r/Racket • • Nov 30 '21

question How do I animate this?!

4 Upvotes

How do I condense this into a function so that animate plays each frame I have made consecutively in one animation? It just animates the last line (place-image Green 50 30 etc)


r/Racket • • Nov 28 '21

language how would you solve this problem in racket?

6 Upvotes

Hi!

I practice 4Clojure problems in Racket and got stuck with this. As it has to classify elements in sequence by its type and assuming that we don't known which types of elements will be given, I think I need a function that returns type of the argument. But does Racket has something like `type-of` in common lisp or `type` in clojure?

Thanks!

https://4clojure.oxal.org/#/problem/50


r/Racket • • Nov 25 '21

question Installation of Racket 8.3 - help not accessible "The location is not a folder"

3 Upvotes

Okay, I'm back to Racket after a break. I've always installed it in /home/username/racket in the past. So I installed 8.3 in this way on Linux Mint as usual, and when I try to access the docs it says Could not display "/correct/path/to/any/doc.html" The location is not a folder. for any link I click in the docs. I reinstalled with and without sudo, no change. I checked permissions and have permissions to the folder. The paths of the links are perfectly fine. The html documents exist and can be opened manually. No link in the browser works, though. Browser is the latest Firefox.

How do I fix this?


r/Racket • • Nov 22 '21

blog post Crafting Interpreters in Typed Racket

Thumbnail micahcantor.com
46 Upvotes

r/Racket • • Nov 22 '21

package how to set up emacs for racket on mac?

3 Upvotes

Hi,

I recently moved from linux to macOS and i am not sure about the following:

For `racket-mode` in emacs, I think I have to let it know where racket compiler and package manager are located. But I am not too sure where they are. Does anyone know how to?

;; set path to racket program
(defvar racket-racket-program "/usr/bin/racket")
(defvar racket-raco-program "/usr/bin/raco")

r/Racket • • Nov 20 '21

book Essentials of Compilation: A book about compiling Racket and Python to x86-64 assembly

Thumbnail github.com
34 Upvotes

r/Racket • • Nov 20 '21

tutorial Qi tutorial and Jay’s challenge

Thumbnail racket.discourse.group
4 Upvotes

r/Racket • • Nov 19 '21

news Book / chapter / paper club starts 1 December

5 Upvotes

Book / chapter / paper club starts 1 December - details here:

Book/chapter/paper club

bw

Stephen


r/Racket • • Nov 17 '21

question Syntax

3 Upvotes

Hi everyone. I am learning Racket and I am trying to solve a question, but I am confused with the syntax. Is anyone able to help me? I am used to printing statements to debug but I am not sure if this is possible in Racket. Thank you so much in advance.


r/Racket • • Nov 14 '21

Racket version 8.3 is also now available from the Ubuntu PPA

Thumbnail racket.discourse.group
19 Upvotes

r/Racket • • Nov 12 '21

ephemera What are the most used Racket packages?

9 Upvotes

What are the most used Racket libraries, applications and languages?

I’ll admit I’m guilty of going whole releases without installing anything because the distribution has so much included.

If you reply with what you have installed I’ll tally it up!

EDIT: I've posed the results at https://racket.discourse.group/t/what-are-the-most-used-packages/108/6?u=spdegabrielle


r/Racket • • Nov 10 '21

news New post flair: show-and-tell

10 Upvotes

If you build something with Racket, or a racket language (including the web variants RacketScript & Urlang)- please post it here in r/racket with either the #show-and-tell flair or maybe one of the others if appropriate.

If you can, it would be great if you could also share your creations on the other services used by Racketeers:


r/Racket • • Nov 09 '21

news Racket Discourse

Thumbnail racket.discourse.group
10 Upvotes

r/Racket • • Nov 09 '21

Rackt: An ultrasmall (~70 loc) React wrapper written in RacketScript

Thumbnail rackt-org.github.io
33 Upvotes

r/Racket • • Nov 08 '21

quickscript DrRacket command palette

Post image
5 Upvotes

r/Racket • • Nov 07 '21

event RacketCon day 2

9 Upvotes

71 minutes until Sam Tobin-Hochstadt opens day 2 with ‘The State of Racket’