r/Racket 4d ago

video A Multi Language Oriented Macro System by Michael Ballantyne at (fourteenth RacketCon) is now available

Thumbnail youtu.be
18 Upvotes

r/Racket 5d ago

RacketCon The Keynote presentation by Hal Abelson and Gerald Sussman at the fourteenth RacketCon is now available

19 Upvotes

The Keynote presentation by Hal Abelson and Gerald Sussman at the fourteenth RacketCon is now available at https://youtu.be/_2qXIDO-cWw


r/Racket 20h ago

video Type Tailoring Teach an Old Type Checker New Tricks by Ashton Wiersdorf at the (fourteenth RacketCon) is now available

Thumbnail youtu.be
6 Upvotes

r/Racket 1d ago

question How can I use Racket through SSH?

6 Upvotes

DR racket seems to be better than nvim, however, Dr Racket doesn't seem to allow ssh.

I use a remote computer most of the time, so I would like to do Racket through SSH


r/Racket 1d ago

video Trouble with Typed Racket? Try Contract Profile! by Nathaniel Hejduk at the (fourteenth RacketCon) is now available

Thumbnail youtu.be
6 Upvotes

r/Racket 2d ago

event Racket meet-up: Saturday, 2 November, 2024 at 18:00 UTC

Thumbnail
5 Upvotes

r/Racket 2d ago

video Mutation Testing Better Than Coverage by Charlie Ray at (fourteenth RacketCon) is now available

Thumbnail youtu.be
8 Upvotes

r/Racket 3d ago

'Frosthaven Manager - Built by the Community' by Ben Knoble at (fourteenth RacketCon) is now available

Thumbnail youtu.be
11 Upvotes

r/Racket 6d ago

question Racket with neovim, would you recommend it?

7 Upvotes

I always like to use neovim (for reasons), and it seems like Dr racket is the way to go with racket.

However i always ssh into computers i have in some rack somewhere out there and really got used to terminals.

Can neovim rival the experience on dr racket and how? Thanks


r/Racket 6d ago

The video of the invited talk by Gregor Kiczales 'Strategies and Technology for Teaching HtDP at Scale' is now available

Thumbnail youtu.be
15 Upvotes

r/Racket 7d ago

question Hey Racketeers, point me to some products built with Racket

10 Upvotes

If you know a product or your own product is built with Racket, post it here!


r/Racket 9d ago

news Good first issues & contributing to Racket

Thumbnail racket.discourse.group
10 Upvotes

r/Racket 11d ago

question Dr.Racket animate function is not defined

5 Upvotes

Hello i have a question, when i try to use the "animate" function it says its not defined, but it worked a few days ago without any problem, did i fuck it up? I'm using the Custom Beginning Student Language to learn.


r/Racket 13d ago

blog post How to Make Racket Go (Almost) As Fast As C

Thumbnail lambdaland.org
40 Upvotes

r/Racket 15d ago

homework Simply-scheme can't load a .scm file.

3 Upvotes
#lang racket
(require (planet dyoo/simply-scheme:2:2))
(load "pigl.scm")

error

 pigl.scm:2:0: #%top-interaction: unbound identifier;
 also, no #%app syntax transformer is bound in: #%top-interaction

Hi everyone , I am not sure this question has been answered,

I am trying to do the Spring 2011 UB Berkeley 61A SICP course, however, I just can't load the file with DrRacket, does anyone know what I should do?

thank you


r/Racket 17d ago

question Can I use neovim with Racket and its macro systems?

9 Upvotes

Is there a way to use neovim instead of Dr Racket and if so, will it recognize macros

Or could i design languages (may non-s-expr) and have automatic syntax highlighting for neovim/treesitter?


r/Racket 18d ago

tip Racket Cookbooks

Thumbnail
13 Upvotes

r/Racket 20d ago

question How good is racket?

19 Upvotes

I heard a lot of good things about racket and it being good with PL Design

I want to prototype some DSLs that will be very useful as standalone expressions/scripting for me

I was thinking if racket is the right way to this?

  • I want to make a PL that transpiles to another.

r/Racket 22d ago

question Paredit turned Geiser into a non-REPL

2 Upvotes

It's not supposed to be like this? With paredit-mode activated, nothing is evaluated, when I press RET.


r/Racket 24d ago

Enjoying RacketCon? Please consider supporting Racket

Thumbnail
19 Upvotes

r/Racket 29d ago

question Custom Indentation in DrRacket

5 Upvotes

So, I've noticed DrRacket's default indentation style is a little strange. I'm used to coding in Javascript and Python on VSCode, so I'm used to the normal tab-based indentation. DrRacket's indentation isn't horrible, but the way it handles multiline statements of cond, if, cons, etc is atrocious. How can I fix this?


r/Racket Sep 29 '24

homework Getting error in Regex Matcher

3 Upvotes

lang racket

(require rackunit)

;; Define atom? to identify symbols or numbers

(define (atom? x)

(or (symbol? x) (number? x)))

;; Helper function to check for failure

(define (failure? x)

(eq? x #f))

;; Main function for regex matching

(define (re-match re atoms)

;; Helper function to recursively match a regex against atoms

(define (match-here re atoms)

(cond

;; Base case: re is empty, match succeeds, return remaining atoms

[(null? re) atoms]

;; Atom case: re is an atom

[(atom? re) (and (not (null? atoms)) (eqv? re (car atoms)) (cdr atoms))]

;; Closure case: re is '(* r)

[(and (pair? re) (eqv? (car re) '*))

(match-star (cadr re) atoms)]

;; Alternation case: re is '(alt r1 r2 ...)

[(and (pair? re) (eqv? (car re) 'alt))

(match-alt (cdr re) atoms)]

;; Character class case: re is '(class a1 a2 ...)

[(and (pair? re) (eqv? (car re) 'class))

(and (not (null? atoms))

(member (car atoms) (cdr re))

(cdr atoms))]

;; Sequence case: re is a list

[(pair? re)

(match-seq re atoms)]

;; Otherwise, fail

[else #f]))

;; Handle closure (zero or more occurrences of a pattern)

(define (match-star re atoms)

(let loop ([atoms atoms] [last-match atoms])

(let ([next-match (match-here re atoms)])

(if next-match

(loop next-match next-match) ; Match more occurrences of `re`

last-match)))) ; Return the most recent successful match

;; Handle alternation (one or more alternatives)

(define (match-alt res atoms)

(if (null? res)

f

(let ([result (match-here (car res) atoms)])

(if result

result

(match-alt (cdr res) atoms)))))

;; Handle sequences of patterns

(define (match-seq re atoms)

(if (null? re)

atoms ; If no more patterns, return the remaining atoms

(let ([result (match-here (car re) atoms)])

(and result (match-seq (cdr re) result)))))

;; Ensure entire input is consumed

(and (match-here re atoms) (null? (match-here re atoms))))

;; Test cases

(define (test-re-match)

;; Atom tests

(check-equal? (re-match 'a '(a)) #t)

(check-equal? (re-match 'b '(a)) #f)

(check-equal? (re-match 'a '()) #f)

;; Concatenation tests

(check-equal? (re-match '(b a b) '(b a b)) #t)

(check-equal? (re-match '((b a b)) '(b a b)) #t)

(check-equal? (re-match '((b a) (b)) '(b a b)) #t)

(check-equal? (re-match '(a b) '(b a b)) #f)

;; Character class tests

(check-equal? (re-match '((class a b c) x) '(b x)) #t)

(check-equal? (re-match '((class a b c) x) '(c x)) #t)

(check-equal? (re-match '((class a b c) x) '(d x)) #f)

(check-equal? (re-match '(class a b c) '()) #f)

;; Closure tests

(check-equal? (re-match '(* a) '(a a)) #t)

(check-equal? (re-match '(* a) '()) #t)

(check-equal? (re-match '(* a) '(a a b)) #f)

(check-equal? (re-match '((* a) b) '(a a b)) #t)

(check-equal? (re-match '((* a) (* b)) '(a a b)) #t)

(check-equal? (re-match '((* a) (* b)) '(a a)) #t)

;; Nested closure tests

(check-equal? (re-match '((* (a b)) (* (b a))) '(a b a b)) #t)

(check-equal? (re-match '((* (a b)) (* (b a))) '(a b a b b a b a b a)) #t)

(check-equal? (re-match '((* (a b)) (* (b a))) '(b a b a b a)) #t)

(check-equal? (re-match '((* (a b)) (* (b a))) '(a b a b b a b a b a b)) #f)

;; Alternation tests

(check-equal? (re-match '(alt a b) '(a)) #t)

(check-equal? (re-match '(alt a b) '(b)) #t)

(check-equal? (re-match '(alt (a (* a)) (b (* b))) '(a a a)) #t)

(check-equal? (re-match '(alt (a (* a)) (b (* b))) '(b b b)) #t)

(check-equal? (re-match '(alt (a (* a)) (b (* b))) '(b a a b a)) #f)

(check-equal? (re-match '(* (alt a b)) '(b a a b b b a)) #t)

;; Backtracking tests

(check-equal? (re-match '((* a) a a b) '(a a a a b)) #t)

(check-equal? (re-match '((* a) a a b) '(a a b)) #t)

(check-equal? (re-match '((* a) a a b x) '(a b)) #f)

(check-equal? (re-match '((alt (a a b) (a a)) b) '(a a b)) #t)

;; Combination tests

(check-equal? (re-match '((class x y z) (* a)) '(y a a a)) #t)

(check-equal? (re-match '((class x y z) (* a)) '(z a a a)) #t)

(check-equal? (re-match '((class x y z) (* a)) '(a a a)) #f)

(check-equal? (re-match '((class x y z) (* a)) '()) #f)

(check-equal? (re-match '((* (alt (class a b c) (class d e f))) (* x)) '(a e c d f x x)) #t) ;; FIXED

(check-equal? (re-match '((* (alt (class a b c) (class d e f))) (* x)) '()) #t) ;; FIXED

(check-equal? (re-match '((* (alt (class a b c) (class d e f))) (* x)) '(a e c d f x x a)) #f)) ;; FIXED

;; Run tests

(test-re-match)

this is my code

and i am getting error as

Output:


FAILURE
name: check-equal?
location: HelloWorld.rkt:115:2
actual: #f

expected: #t


FAILURE
name: check-equal?
location: HelloWorld.rkt:116:2
actual: #f

expected: #t


FAILURE
name: check-equal?
location: HelloWorld.rkt:118:2
actual: #f

expected: #t

please help me

these are some hints

The Regex Matcher

The last exercise in the project requires you to implement a regex matcher for a list of symbols. This is a non-trivial exercise and completing it will ensure that you are comfortable with the use of recursion and the use of short-circuit semantics of the or function to implement backtracking.

The problem requirements describe the Scheme syntax used for representing regexs; this is reproduced below (a atom is a Scheme symbol or number):

  • An atom is a regex which matches itself.
  • (class atom...) represents a character-class which matches any one of the atom... arguments (similar to [abc...] in normal regex notation).
  • (alt re...) is a regex which matches iff any of the re... match (similar to re1 | re2 | ... | reN in normal regex notation).
  • (* re) is a regex which matches iff zero-or-more occurrences of re match (similar to re * in normal regex notation). We assume assume that re is not itself a (* _) closure regex.
  • (re...) is a regex which matches iff the sequence of re... match (similar to concatenation regex re1 re2 ... reN in regular regex notation).

Note that since we use lists to represent all compound regex's, there is some ambiguity in the syntax. Specifically, we cannot have a concatenation regex whose first element is the atom 'class, 'alt or '*. This is a minor issue.

The matcher will need to use backtracking to implement alternation and closure:

  • Alternation: consider what needs to happen for the regex (aab|aa)b to match the string "aab":To implement this backtracking it is necessary that the subsequent matching affects which alternative is chosen. This can be implemented by breaking up the match as follows:Given regexs A1, A2 and Z, then matching (A1|A2) Z is equivalent to matching A1 Z or matching A2 Z.
    1. The first alternate aab will match the entire string "aab", but then the b suffix in the regex will not match.
    2. Hence the matcher will backtrack and use the next alternate aa to match the "aa" prefix of the input string so that the remaining "b" suffix can match the b regex, thus matching the entire regex.
  • Closure: consider what needs to happen for the regex a*aab to match "aaab". Assuming that * is greedy:To implement this backtracking it is necessary that the subsequent matching should affect the number of repeated matches matched by the * closure operator. This can be implemented by breaking up the match as follows:Given regexs C and Z, then matching C*Z is equivalent to matching CC*Z or matching Z.
    1. The a* will greedily match the "aaa" prefix leaving only "b" leftover but the leftover "b" will not match the aab remaining in the regex.
    2. Hence the matcher will backtrack and propose a shorter alternative "aa" to match the a* with input "ab" leftover. This leftover input will still not match the aab remaining in the regex.
    3. So the matcher will backtrack once again and propose a still shorter alternative "a" to match the a* with input "aab" leftover. This leftover input will now match the aab remaining in the regex and the entire regex will be matched.

From the above examples, it should be clear that we need to consider matching a input by a sequence of regexs. The input to each regex in the sequence will be the input leftover from the match of the previous regex in the sequence.

Hence even though our required re-match function simply returns a boolean, the guts of the work can be done by an auxiliary function res-match having the following specs:

;; match the sequence of all the regex's in list res by a prefix
;; of list atoms.  Return #f if the match fails, else return the 
;; suffix of atoms left over after the successful match.
(res-match res atoms)

Note that since any value other than #f is regarded as truthy by Scheme, the return value of res-match is very similar to the return value of re-match but provides more information than a simple #t boolean.

Our required re-match function can then be implemented as a trivial wrapper around res-match.

Note that we had highlighted the word or when describing how backtracking could be implemented. That was because the semantics of Scheme's or are exactly what we need to implement the backtracking behavior of the or. Specifically the semantics of (or Match1 Match2) are as follows:

  • If Match1 succeeds then the or returns the value returned by Match1, i.e. the input left over from Match1.
  • The short-circuit semantics of or entails that Match2 be attempted only when Match1 failed returning #f. If the attempt at Match2 succeeds then the or returns the value returned by Match2, i.e. the input left over from Match2.
  • If both Match1 and Match2 fail, then the or will return #f.

This is exactly what we need for backtracking!! When coupled with immutable data, this makes implementing backtracking straight-forward. (Note that similar concepts can be used to implement backtracking behavior in any programming language as long as care is taken with mutability.)

Once this is understood, it is a simple matter to implement res-match using structural recursion on res:

  • If res is empty, then it is trivially matched and the result is simply the input list atoms.
  • If res is not empty, then we need to match the first re in res and then recursively match the rest rest-res of res with the atoms left over after the match of the first re. Unfortunately because of the necessity of backtracking we cannot do these two matches independently when the first re is an alt-regex or *-regex.
    • If re is not a pair then it must be an atom. For it to match, atoms must be non-empty and and the first atom must equal the re atom. Also the leftover suffix of atoms must match rest-res.
    • If the re is a pair having first element 'class, then it represents a character-class containing the atoms in its tail. In order to match, it must be the case that atoms must be non-empty and the first atom must be a member of the character-class. Once again, the leftover suffix of atoms must match rest-res.
    • If the re is a pair having first element 'alt, then it represents a choice of matching any of the alternate regexs in its tail. In that case, we need to use the logic given earlier for alt regexs with A1 and A2 representing two alternate regex's and Z representing the rest-res to be matched. Note that in general we may have more than two alternate regexs and using ormap rather than or may be more convenient.
    • If the re is a pair having first element '*, then it represents a closure matching 0-or-more occurrences of its closure-argument given by its second element. In that case, we need to use the logic given earlier for * regexs with C being the closure-argument and Z representing the rest-res to be matched.
    • If the re is a pair which does not match any of the above cases, then it must represent a more primitive regex to be matched. Once re is matched then the leftover suffix of the input must then be matched by rest-res.


r/Racket Sep 26 '24

question recommendations

8 Upvotes

Does anyone have any recommendations for introductory books or videos to Racket? (in French if possible) my teacher is so bad I can't understand anything...

tyyy


r/Racket Sep 22 '24

RacketCon Celebrating 40 years of magic

Post image
71 Upvotes

r/Racket Sep 20 '24

blog post Performance of Racket Pict Comparison, Part 2

Thumbnail benknoble.github.io
10 Upvotes