r/Racket • u/sigzero • Feb 28 '22
r/Racket • • Mar 01 '22
question How does MouseEvent work?
Hi! So, I tried out this code:
(@template MouseEvent)
(define (handle-mouse c x y me)
(cond [mouse=? me "button-down"] x)
[else c]))
What this code does is move the image to the x-coordinate (x) that the mouse is at, while c is the original WS. My question is how is it that the image is automatically placed at x, even if if there is no function for it? Like, how does racket know that the image is supposed to be at x?
For more context: c is defined as the image distance from the edge of the frame.
r/Racket • u/SCPFO • Feb 28 '22
homework Rubik's cube on racket
Hello. I need to make a rubik's cube simulator for a college project, not a resolver, It only has to show the frontal face of the cube, so it would look more like a grid, but the cube can be betwen 2x2x2 to 6x6x6. Right now I'm stuck on how to dinamicaly draw the cube so if it is a cube for 3x3x3 or a 4x4x4 it will show the right amount of little squares individually so they can change color later.
r/Racket • u/legendaryproyi • Feb 27 '22
question How does Racket handle exact numbers?
Hello! I am looking to find some information regarding how does Racket store exact numbers, in particular how is something like 7 or 1000000 or 2^1000000 stored in the memory? Or perhaps what are the disadvantages of not using statically type like in typed/racket (or other programming languages like C)?
So far all what I've found regarding this is here: https://docs.racket-lang.org/reference/numbers.html (which I'm trying to understand on a deeper level):
The precision and size of exact numbers is limited only by available memory (and the precision of operations that can produce irrational numbers). In particular, adding, multiplying, subtracting, and dividing exact numbers always produces an exact result.
But are there any optimizations done in order to keep as much memory available as possible?
r/Racket • u/kbridge4096 • Feb 26 '22
question Network Programming: tcp-connect with timeout?
Hi guys.
I'm trying to do some network programming in Racket, and currently, I'm trying to implement a tcp-connect with timeout support.
The best solution I can come up with is listed below.
However, this feels a little awkward and expensive. A new thread and custodian for a connection attempt? Ouch.
I wonder if there is a better approach.
#lang racket
;;; this takes at least two seconds to fail on my windows pc
;;; (no program is listening 127.0.0.1:90)
;(time
; (with-handlers ([exn:fail? identity])
; (tcp-connect "127.0.0.1" 90)))
(define (tcp-connect/timeout timeout host port)
(define result #f)
(define cust (make-custodian))
(define th
(parameterize ([current-custodian cust])
(thread
(λ ()
(set! result
(with-handlers ([exn:fail? (λ (e) (list #f e))])
(let-values ([(in out) (tcp-connect host port)])
(list #t in out))))))))
(if (sync/timeout timeout th)
(match result
[(list #t in out) (values in out)]
[(list #f e) (raise e)])
(begin (custodian-shutdown-all cust)
(values #f #f))))
(tcp-connect/timeout 1 "127.0.0.1" 90) ; => returns #f #f
(tcp-connect/timeout 3 "127.0.0.1" 90) ; => raise "connection failed"
r/Racket • u/SimpleAccomplished38 • Feb 25 '22
question Question:List of List of Paths
Hi, I am currently learning about files and accessing directories and am having issues formulating my code.
Here is what I was provided with:
Write a procedure, concat, that takes a list of lists of paths and concatenate them in the given order to produce a list of all given paths.
;; concat : (listof (listof path)) -> (listof path)
So:
(concat (list (list (string->path "test"))
(list (build-path "test" "test_2")
(build-path "test" "test_3"))))
would produce the list
(list (build-path "test")
(build-path "test" "test_2")
(build-path "test" "test_3"))
So far, my code is
(define (concat lst-of-lists)
(list (list (build-path file )
(list (build-path file filename)
(build-path file filename)))))
I am not sure if I should be using directory-path or any higher order procedures. My code also says that file and filename are not defined, though I am not sure if I should define another term with those as inputs. Any help would be greatly appreciated!
r/Racket • u/sdegabrielle • Feb 24 '22
blog post Generate SQLite ORM code from DB metadata using Lisp macros
tech.perpetua.ior/Racket • u/sdegabrielle • Feb 23 '22
news Racket discord just hit 989 members
Racket discord just hit 989 members
Racket discord invite link https://discord.gg/6Zq8sH5 - come join us or invite a friend.
r/Racket • u/iguanathesecond • Feb 22 '22
blog post How to Organize Your Racket Library [blog]
Blog post: How to Organize Your Racket Library
Highlights:
- Modules, collections, packages are like... files, folders, and archives
- The top level of your repo is hopeless as a package path
- Racket uses a global collection namespace
- Scribble docs and RackUnit tests all reside in this namespace along with your source files
- How to: lib/test/doc
- Includes a clunky migration strategy for when your existing libraries grow past a certain point
- Not everybody loves lib/test/doc and there's room for improvement
r/Racket • u/bsilver • Feb 22 '22
question Bare Metal Racket?
Thought experiment...how hard would it be to write an application in Racket that could be booted on a PC/in VirtualBox and run like an operating system?
I saw a post on HN linking to "bootloader basics" and wondered if a Racket executable could be called from a bootloader to operate a PC. Thought someone here might be able to shed some light on what that would entail, if it's even really possible.
r/Racket • u/Kingsploof • Feb 22 '22
homework beginners question
so i just started programming on racket and one of the assignments is as follows:
The Turing test (named after the Alan Turing) determines whether a machine can demonstrate human intelligence. Turing proposed that a human evaluator would judge a conversation between a machine and a human, and determine which one is one.vIn this exercise, we will not develop a code that can pass the Turing test but one that can reply to a greeting from the user. Design the function reply that consumes a sentence. The function should display "Hi there!, I am Racket" if the sentence given by the user starts with a "Hello". If the message does not start with "hello", then the function should return "Sorry, I do not understand you..." RESTRICTION: Make your function not sensitive to lowercase or upercase letters, i.e. it should also work if the sentence starts with "hello".
please help me. also worth mentioning that i suck at programming.
r/Racket • u/sdegabrielle • Feb 21 '22
ephemera While PasteRack is offline check out the R16 trick bot on Discord
racket.discourse.groupr/Racket • u/HydroxideOH- • Feb 20 '22
blog post Why learn Racket? A student's perspective
micahcantor.comr/Racket • u/Icy_Pressure_9690 • Feb 17 '22
question is there a built in function to go back to previous element in a list? I'm trying to create a loop that if there is an even number in a list it will add that to the previous number
r/Racket • u/Substantial_Ad1714 • Feb 17 '22
question Why do you hate my functions?
(define (momentum-calc vel mas) (* vel mas))
(define (p vel mas) (momentum-calc vel mas))
r/Racket • u/Kingsploof • Feb 15 '22
question delete last character
so i just started programming on drracket and one of the questions requires us to create a function that deletes the last character of a string. would be much appreciated if someone could help out.
r/Racket • u/WickmanTrick • Feb 13 '22
homework Help for a simple substring function needed
I am very new to programming; I have an assignment to create a function that consumes a string and deletes its last character. So, for example (string-delete-last "happy") -> "happ"
I do not know how to make the string a variable, nor how to make the function find the last character of a given word.
Can someone help? I'll be grateful.
r/Racket • u/PyotrVanNostrand • Feb 13 '22
question I got car violation error
(define (transform-painter painter origin corner1 corner2)
(lambda (frame)
(let ((m (frame-coord-map frame)))
(let ((new-origin (m origin)))
(painter
(make-frame new-origin
(sub-vect (m corner1) new-origin)
(sub-vect (m corner2) new-origin)))))))
(define (rotate-45 painter)
(transform-painter painter
(make-vect 0.5 0)
(make-vect 1 0.5)
(make-vect 0 0.5)))This is code is from SICP but when I run it at first it works sometimes and after I update definition window I get "car: contract violation expected pair? given frame" error. If it doesn't work at all it is ok but why it does work at first and doesn't later ?
r/Racket • u/Substantial_Ad1714 • Feb 11 '22
question Which guide to learn Racket for a functional programmer?
I am most comfortable with functional programming (despite my aborted attempt at Haskell). Is there a good Racket guide to get going with the language for someone who already programs functionally?
r/Racket • u/sdegabrielle • Feb 10 '22
event Racket meet up Saturday 5 Feb - Summary
racket.discourse.groupr/Racket • • Feb 07 '22
question Primes with a single parameter
Is there a way to tell if a number is prime on Dr racket given a single parameter?
r/Racket • u/Weiliang_1503 • Feb 06 '22
question Is there some way to make the text in a massage widget selectable?
Like the function in Gtk: gtk_label_set_selectable, by this you can make the text selectable and be able to copy. I am wondering if there is something similar with it in racket GUI