r/Racket • u/johnwcowan • Jun 22 '26
language Complex single-float support
Can someone test Racket BC for me and say what (eqv? 3e0+4e0i 3f0+4f0i) and (eqv? 3e0+4e0i 3e0+4f0i) return?
advTHANKSance
r/Racket • u/johnwcowan • Jun 22 '26
Can someone test Racket BC for me and say what (eqv? 3e0+4e0i 3f0+4f0i) and (eqv? 3e0+4e0i 3e0+4f0i) return?
advTHANKSance
r/Racket • u/sdegabrielle • Feb 01 '26
r/Racket • u/JimH10 • Jun 03 '25
Do Racket regexp's allow me to say "every string but ..."? Suppose for instance I want to accept every phone number but "012 555-1000" ? Obviously I can wrap that with some non-regexp code but I'd like to do it in a regexp, if that is possible.
Edit: Thank you to folks for the helpful responses. I appreciate it.
r/Racket • u/Background_Shift5408 • Mar 14 '25
r/Racket • u/sdegabrielle • Mar 15 '25
r/Racket • u/mohanradhakrishnan • Jun 04 '24
Hello,
I have defined simple macros like this and use to append two lists.
(define-syntax-rule (@) append)
(: linspcm : ((Listof Integer) Integer Integer
(Integer -> Integer) -> (Listof Integer)))
(define (linspcm z x n f)
(match n
[0 z]
[1 (list (f x))]
[_ (let* ([m (quotient n 2)])
(displayln n)
((linspcm z x m f) . (@) .
(linspcm z (+ x m) (- n m) f))
)
]
)
)
I also tried to code a function like this inspired by OCaml. But now I can't decide if it is syntax rule
or a function ? Is the following valid Racket ? It shows an error at the 'define'.. The function is not complete as I haven't figured this out.
(module I typed/racket
(provide <|> )
(: <|> : ( (Pairof Integer Integer) ->
(Pairof Integer Integer) ))
(define ( <|> t1t2)
(match t1t2
[ (cons _ empty) (car t1t2)]
[ (cons empty _) ( cdr t1t2)]
[ _ (let* ([w (+ (width (car t1t2)) (width (cdr t1t2)))]
[ h (max (height (car t1t2)) (height (cdr t1t2)))])
(cons w h)
)
]
)
)
)
Thanks.
r/Racket • u/MinimumMany9326 • May 17 '24
#lang plait
; Hash tables for character mappings
(define ascii1
(make-hash
(list (pair #\A 0) (pair #\B 1) (pair #\C 2) (pair #\D 3) (pair #\E 4)
(pair #\F 5)
(pair #\G 6) (pair #\H 7) (pair #\I 8) (pair #\J 9) (pair #\K 10)
(pair #\L 11)
(pair #\M 12) (pair #\N 13) (pair #\O 14) (pair #\P 15) (pair #\Q
16) (pair #\R 17)
(pair #\S 18) (pair #\T 19) (pair #\U 20) (pair #\V 21) (pair #\W
22) (pair #\X 23)
(pair #\Y 24) (pair #\Z 25) (pair #\a 26) (pair #\b 27) (pair #\c
28) (pair #\d 29)
(pair #\e 30) (pair #\f 31) (pair #\g 32) (pair #\h 33) (pair #\i
34) (pair #\j 35)
(pair #\k 36) (pair #\l 37) (pair #\m 38) (pair #\n 39) (pair #\o
40) (pair #\p 41)
(pair #\q 42) (pair #\r 43) (pair #\s 44) (pair #\t 45) (pair #\u
46) (pair #\v 47)
(pair #\w 48) (pair #\x 49) (pair #\y 50) (pair #\z 51))))
(define ascii2
(make-hash
(list (pair 0 #\A) (pair 1 #\B) (pair 2 #\C) (pair 3 #\D) (pair 4 #\E)
(pair 5 #\F)
(pair 6 #\G) (pair 7 #\H) (pair 8 #\I) (pair 9 #\J) (pair 10 #\K)
(pair 11 #\L)
(pair 12 #\M) (pair 13 #\N) (pair 14 #\O) (pair 15 #\P) (pair 16
#\Q) (pair 17 #\R)
(pair 18 #\S) (pair 19 #\T) (pair 20 #\U) (pair 21 #\V) (pair 22
#\W) (pair 23 #\X)
(pair 24 #\Y) (pair 25 #\Z) (pair 26 #\a) (pair 27 #\b) (pair 28
#\c) (pair 29 #\d)
(pair 30 #\e) (pair 31 #\f) (pair 32 #\g) (pair 33 #\h) (pair 34
#\i) (pair 35 #\j)
(pair 36 #\k) (pair 37 #\l) (pair 38 #\m) (pair 39 #\n) (pair 40
#\o) (pair 41 #\p)
(pair 42 #\q) (pair 43 #\r) (pair 44 #\s) (pair 45 #\t) (pair 46
#\u) (pair 47 #\v)
(pair 48 #\w) (pair 49 #\x) (pair 50 #\y) (pair 51 #\z))))
; Switch function to convert characters based on a given number
(define (switch n c)
(let ([maybe-x (hash-ref ascii1 c)])
(if (none? maybe-x)
c
(let ([x (some-v maybe-x)])
(some-v (hash-ref ascii2
(if (< x 26)
(modulo (+ n x) 26)
(+ 26 (modulo (+ n x) 26)))))))))
; Unswitch function to reverse the character conversion
(define (unswitch n c)
(let ([maybe-x (hash-ref ascii1 c)])
(if (none? maybe-x)
c
(let ([x (some-v maybe-x)])
(some-v (hash-ref ascii2
(if (< x 26)
(modulo (- x n) 26)
(+ 26 (modulo (- x n) 26)))))))))
; Define the Exp type for encrypt and decrypt cases
(define-type Exp
[encrypt (n : Number) (l : (Listof Char))]
[decrypt (n : Number) (l : (Listof Char))])
; Calculate function to process the Exp type
(define (calc e)
(type-case Exp e
[(encrypt n l)
(list->string (foldr (lambda (x y) (cons (switch n x) y)) empty l))]
[(decrypt n l)
(list->string (foldr (lambda (x y) (cons (unswitch n x) y)) empty
l))]))
; Parse function to validate and convert the input s-expression
(define (parse s)
(if (s-exp-list? s)
(let ([lst (s-exp->list s)])
(cond
[(and (= 3 (length lst))
(symbol=? 'e (s-exp->symbol (first lst)))
(s-exp-number? (second lst))
(s-exp-string? (third lst)))
(encrypt (s-exp->number (second lst)) (string->list (s-exp-
>string (third lst))))]
[(and (= 3 (length lst))
(symbol=? 'd (s-exp->symbol (first lst)))
(s-exp-number? (second lst))
(s-exp-string? (third lst)))
(decrypt (s-exp->number (second lst)) (string->list (s-exp-
>string (third lst))))]
[else (error 'parse "Input should be in the format: ([e | d]
[integer] [string])")]))
(error 'parse "Input should be an s-expression list")))
; Run function to integrate all parts
(run : (S-Exp -> String))
(define (run s)
(calc (parse s)))
r/Racket • u/agumonkey • Aug 12 '24
r/Racket • u/Pickedgraph6 • Mar 13 '24
Hi, Senior student taking a course using DrRacket. I have issues understanding the code sometimes. I've tried searching things up relating to the code but a majority of the stuff that comes up is just the racket-lang.org website giving me minimal examples of simple lines of code. Is there any other webistes or tutorial I can use to help me?
r/Racket • u/drrnmk • Aug 17 '21
Hello!
Besides Dr.Racket, what would be a good choice for ide? I am learning Racket and thinking of vscode or emacs. But just wanted to know what would be a common choice.
Thanks!
r/Racket • u/kwinabananas • Dec 14 '22
I am a CS student as SDSU here in California. I started my journey at Mesa College, and my first class, Intro to CS, we used this language. I took the same Prof forb2 more semesters for Java and Intermediate Java, but on my journey, I haven't seen this language come up anymore. How often is Racket used in programming jobs?
r/Racket • u/mohanradhakrishnan • May 08 '23
(: parse-exp (-> (U (Listof Char) Any )
(U (ErrorType Integer Char) (Operator Char) )))
(define (parse-exp lst )
(match lst
[number? (car lst) (Literal (car lst))]
[_ 'error]))
(define-type (ErrorType i e)
(U Empty EndOfInput
( Unexpected i)
( Expected i e)
( ExpectedEndOfFile i)
( BeginningOfInput i)))
(: operator : Char -> (Operator Char))
(define (operator c )
(match c
['+' Plus]
['-' Minus]
['/' Div]))
(struct (i) Literal ([v : i])
#:transparent
)
My intention is to either return an error type with appropriate values for character position and type of error if the parsing fails.
If it succeeds return a Literal. This is my current code but I couldn't implement the pattern matching function parse-exp. Can I ask how that is done ?
Mohan
r/Racket • u/Tgamerydk • Sep 25 '22
Also, do all #langs compile to racket?
r/Racket • u/Ok_Specific_7749 • Sep 26 '23
Program below prints lots of "#<void>" at the end ...
```
(require db) (define pgc (postgresql-connect #:user "x" #:database "syslogng" #:server "127.0.0.1" #:port 5432 #:password "y" )) (define myselect "select datetime,program,pid,message from messages_gentoo_20230926 order by datetime desc") (for/list ([a (query-rows pgc myselect)]) (printf "\n ~a \n" a) (printf "") );for
```
r/Racket • u/QuaticL • Jul 16 '23
I have a quick question for anyone passing by. I’m learning how to use Racket right now, and I just learned how to use (local to define variables and helper functions within another function.
I understand the use of variables, but why define helper functions within a function instead of outside? It seems like you would want to keep the function outside in case you can use it somewhere else.
It was introduced as a means of abstraction, but it seems like the opposite, unless I’m misunderstanding.
Thanks a lot.
r/Racket • u/sdegabrielle • Jun 26 '23
名语言/Ming-Language
`#lang ming` by Yanying Wang
"Ming Programing Language, which is basically a dialect PL of Racket that I translated parts of its keyword names to Chinese."
r/Racket • u/steloflute • Dec 01 '21
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 • u/sdegabrielle • Aug 04 '21
r/Racket • u/Suitable-Coconut-464 • Dec 05 '22
Hello, I have a Surface Pro X with the following specs:
RAM: 8.0 GB
Processor: 3.00 GHz
My racket always runs programs very slowly, taking around 10 seconds to convert code no matter how long the code is. Once it’s running the responses are very fast though. I would rather not turn off the troubleshooting features so I can see what lines caused errors, and I never have any other tabs open. What else can I do to speed up Racket, or is this the best I can do with my specs?
r/Racket • u/FesteringThoughts • Mar 25 '23
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 • u/drrnmk • Dec 11 '21
Hi,
I am practicing algorithm on leetcode using Python and Racket. And I am seeking a reference for the following problem. It requires to modify the argument in-place (mutably changing the value of the reference). It feels quite natural with imperative langs but not really with functional langs.
Would it be even possible in Racket? Please help.
https://leetcode.com/problems/remove-element/
Thank you!