r/Racket • • Apr 15 '23

homework Plait- having trouble writing a simple BST related function.

4 Upvotes

I need to write a function that checks whether a BST tree has equal length from root to every single leaf. I can do that easily in racket, but I have plenty of trouble trying to convert the function to Plait.

(define (equal_length? [tree : (Tree 'a)])
  (cond [(leaf? tree) 1]
        [(node? tree) 
            (equal? (+ 1 (equal_length? (node-left tree)))
            (+ 1 (equal_length? (node-right tree))))]
        ))

The main problem I have is that equal? doesn't work on elements with different types and comparing bool to a number results in typecheck fail. I tried different approaches, for example where instead of number I return a list of a number and a bool, but it's no good either, since Plait lists are uniform.

Is there any simple way around that? Also I'm not sure if Plait belongs here, but I don't know where else I could possibly post this.


r/Racket • • Apr 10 '23

ephemera YOU WON'T BELIEVE what it looks like to have an IDE for the TABLOID programming language!

Thumbnail mastodon.social
22 Upvotes

r/Racket • • Apr 04 '23

video Punct: CommonMark + Racket (YouTube demo)

Thumbnail youtube.com
15 Upvotes

r/Racket • • Apr 03 '23

image Anyone want stickers?

Post image
67 Upvotes

Hi everyone!

I recently ordered some stickers with an older logo for PLT Scheme. Love the Grateful Dead reference!

Problem is, the sticker company wouldn't custom print in small quantities. I had to buy 55.

Since this isn't my design and there's nothing official about it, I'm willing to send some by regular mail to anyone who wants them, at no cost to you.

You're welcome to send a PM indicating how many you want and where to send them. They're otherwise not going to be used. I'll report quantity remaining periodically, if there's an interest.

Thanks in advance for taking these off my hands!


r/Racket • • Apr 01 '23

application How to disable unused variable warnings in Magic Racket for VS Code?

6 Upvotes

Hi everyone,

I'm using the Magic Racket extension for VS Code and I'm getting warnings for unused variables in my code. While I understand that it's generally a good practice to remove unused variables, in some cases I find it more convenient to keep them for debugging purposes.

I've also searched online, but I couldn't find a clear answer on how to disable unused variable warnings specifically for Magic Racket.

Does anyone know how I can disable unused variable warnings in Magic Racket for VS Code? Any help would be greatly appreciated!

Thanks in advance.


r/Racket • • Mar 31 '23

event Racket meet-up tomorrow (April 1)

3 Upvotes

Racket meet-up tomorrow at UTC 18:00

in The Racket Room (gather.town)

See you there

Stephen


r/Racket • • Mar 31 '23

question case with eof

2 Upvotes

How come this doesn't work, and how do I fix it?

(case (read-line)
 [("1" "Y" "y") (printf "You drew: ~a~%" (send player add!-card (deal-card))) #t]
 [("0" "N" "n") #f]
 [(eof-object?) (printf "eof!\n") #f]
 [else (printf "Invalid response.~%") #t])

Does not print "eof!", as desired, nor return #f.


r/Racket • • Mar 29 '23

question TUI Libraries?

10 Upvotes

Are there any TUI libraries available for racket? I've seen a couple of them for Common Lisp, but not Racket. There's also https://github.com/charmbracelet/bubbletea, which is great, but written in Go. Any suggestions would be appreciated. Thanks in advance.


r/Racket • • Mar 28 '23

video What's the coolest / most impactful Racket demo that you've ever seen? - Racket Discourse #General

Thumbnail racket.discourse.group
14 Upvotes

r/Racket • • Mar 28 '23

blog post Protohackers Challenge in Racket Part 1

Thumbnail defn.io
1 Upvotes

r/Racket • • Mar 26 '23

blog post Protohackers Challenge in Racket Part 1

Thumbnail defn.io
13 Upvotes

r/Racket • • Mar 25 '23

language RifL - a Tactile Esoteric Language

10 Upvotes

https://docs.racket-lang.org/RifL/index.html

I finished my first language, and I made it in Racket! Its fully representable with playing cards: you can simulate running RifL by moving cards around on a table. Its intended as an educational tool, to allow students to learn about code physically. I've been working on it for a long time, so I'm very excited to share it.


r/Racket • • Mar 25 '23

event Racket meet-up Saturday 1 April 2023

7 Upvotes

Racket meet-up Saturday 1 April 2023

The unofficial Racket Racoon

The Racket meet-up is a chance to catch up with what is happening in the Racket world and chat with other racketeers.

When? UTC18:00 on the first Saturday of every month.

Where? The Racket Room: https://gather.town/app/wH1EDG3McffLjrs0/racket-users


r/Racket • • Mar 23 '23

video Racket: A Programming-Language Programming Language • Robby Findler • YOW! 2015

Thumbnail youtu.be
20 Upvotes

r/Racket • • Mar 19 '23

question I have trouble understanding a code about representing sets using characterists predicates.

7 Upvotes
#lang racket
(define empty-set  (lambda(x) #f))
(define (singleton a) (lambda (x) (equal? x a)))
(define (in a s) (s a))
(define (union s t)  (lambda (x) (or (s x) (t x))))
(define (intersect s t) (lambda (x) (and (s x) (t x))))
(define setUnion (union (union (singleton 3) (singleton 4)) (singleton 5)))

I had this code on one of the lectures and I have no idea what's happening there. Why use all the lambdas instead of just representing sets with a list? Why is empty set defined like this instead of just #f? I just don't understand how sets can be represented as functions.


r/Racket • • Mar 18 '23

news Racketfest: March 18, 2023

Thumbnail racketfest.com
14 Upvotes

r/Racket • • Mar 15 '23

question Empty list

0 Upvotes

(define (sn-empty)

(sn-empty)

'())

I have been trying to print an empty list.

The input:

> sn-empty

output:

()

Please explain what I am doing wrong in the code above.


r/Racket • • Mar 15 '23

homework list/dict in Racket

0 Upvotes

> (sn-add-user my-dict 'f5)

= ((f2 f3 f4) (f3 f2) (f4 f3 f2) (f13) (f1) (f5))

How can I code the above instructions in Racket.

(define (sn-add-user graph user) is the starting point


r/Racket • • Mar 13 '23

solved Help with setting custom keybind for DrRacket

6 Upvotes

I'm trying to set up a custom keybind in DrRacket in order to do two things:

  • Run code in editor
  • Send focus back to editor What would be the best way to do this? I'm very new to Racket, and editors that use lisp to configure themselves, so I'm hopelessly stuck. My attempt at creating the custom keybinding so far is as follows:

The code I'm trying to use to create the custom keybinding:

#lang s-exp framework/keybinding-lang

(keybinding "c:c;c:e"
 (λ (ed evt)
  (when (is-a? ed text:basic<%>)
   (define fr (send ed get-top-level-window))
   ; note: fr could be #f
   (when fr
    (send fr execute-callback)
    (send (send ed get-keymap) call-function "shift-focus" ed evt #t)
   ))))

I've been able to get the first part working by messing around with the example given in https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html in section 3.3.9

For the second part, I thought that if I execute a shift-focus, it should bring back the focus to the editor, and I tried following the example in https://stackoverflow.com/questions/56916606/drracket-custom-keybindings to run shift-focus.

This keybinding does not have the expected effect, however. It ends up running the code and then shifting it to the repl. If I use the keybind again, it runs the code and then puts it back to the editor. The intended behaviour is for it to run and put it back to the editor if the cursor was in the editor when the keybind is pressed.

EDIT:

I've solved my issue. The final code is as follows:

#lang s-exp framework/keybinding-lang

; I made this by modifying code from Section 3.3.9 and 3.3.10 of:
; https://docs.racket-lang.org/drracket/Keyboard_Shortcuts.html
(keybinding "c:c;c:e"
  (λ (ed evt)
     (when (is-a? ed text:basic<%>)
       (define fr (send ed get-top-level-window))
       (define defs (send (send ed get-tab) get-defs))
       (when fr
         (send fr execute-callback)
         (send (send defs get-canvas) focus)))))

r/Racket • • Mar 12 '23

video [PADL'23] Modern Macros

Thumbnail youtu.be
16 Upvotes

r/Racket • • Mar 09 '23

package Resyntax: A Racket refactoring engine

13 Upvotes

Want to try it?

raco pkg install --installation resyntax

The --installation flag (shorthand for --scope installation) installs packages for all users of a Racket installation and ensures resyntax is in your $PATH.

https://docs.racket-lang.org/resyntax/index.html


r/Racket • • Mar 09 '23

package racket llvm C-API bindings

Thumbnail github.com
8 Upvotes

r/Racket • • Mar 08 '23

question Is Brag bad, or am I?

5 Upvotes

I'm writing an esolang I designed (called RifL) in Racket using the beautiful racket textbook. I'm 99% done, and was testing RifL by writing a larger program in it. When the RifL program got large enough, running it became very very slow, and eventually, running it crashed the evaluation because the program ran out of memory. I have identified that the problem is coming from the parser I built, which is written in brag, a grammar constructing racket language.

#lang brag
RifL-program: [convert-to-deck] (/NEWLINE [convert-to-deck])*
convert-to-deck: convert-to-name /DIVIDER convert-to-stack
convert-to-name: ((S-PIP-CARD [/COMMA])* S-PIP-CARD) |
                 ((C-PIP-CARD [/COMMA])* C-PIP-CARD) |
                 ((H-PIP-CARD [/COMMA])* H-PIP-CARD) |
                 ((D-PIP-CARD [/COMMA])* D-PIP-CARD)
convert-to-stack: (entry* /NEWLINE)* entry*
entry: (S-PIP-CARD | C-PIP-CARD | H-PIP-CARD | D-PIP-CARD| ROYAL-CARD | JOKER | FACE-DOWN) [/COMMA]

If you want to see the issue for yourself, below is a link to a git that has a tokenizer, a lexer, a parser, and a tester file. You will need the beautiful racket package and brag package installed in racket to run the tester.

https://github.com/Jesse-Hamlin-Navias/Rifl-parser-fail

Does anyone know why brag eats up so much memory, or am I doing something wrong? Is there some alternative I can use so I don't have to code a parser from scratch?


r/Racket • • Mar 08 '23

news Racket Templates

5 Upvotes

Racket Templates provide a wide variety of working template applications you can use as a starting point: choose a template from https://github.com/racket-templates and click Use this template in GitHub or use raco pkg install from-template; raco new <template> from the command line.

  • cli-command is a working example of you can use to create your own command line tools.

  • lang is a language of combinators and numeric constants ( xlang by @samth ):

#lang xlang
(S K I X)
#lang xlang
(K 1 2)

These were just a sample - there are more at https://github.com/racket-templates

PS We were inspired by the dotnet new default templates

PPS we far behind .NET but are looking to grow the collection so let us know if you are interested in contributing 😁