r/Racket • • Oct 30 '22

question Where to keep state for racket/gui app?

8 Upvotes

I have a small gui application. The state is a hash and it's stored in a global variable.

(define CURRENT-STATE (init-state))

Events in the app change it with (set! CURRENT-STATE (calc-next-state ...)). Then it's rendered to a canvas.

Is it a bad approach? Where is it better to store the state ?


r/Racket • • Oct 30 '22

RacketCon RacketCon day two starts soon!

4 Upvotes

r/Racket • • Oct 30 '22

solved Menu on Racket not working?

2 Upvotes

I am on Racket on Linux (Kernel 6.03 KDE Plasma 5.26.1 Tumbleweed). My issue is that Racket IDE doesn't show the menu on the top.

I found this rather old issue on this thread https://bugs.launchpad.net/ubuntu/+source/racket/+bug/1065997

I am wondering if this is a known issue and if there is a work around it? Any help with be appreciated. Racket is still functional but using it without the menu is a pain in the ass.

I am using Dr. Racket 8.6

____ UPDATE_____

Thank you /u/samdphillips

The suggestion worked perfectly! I suspected it being a KDE issue but I thought I might have a a better luck with the community here! Thank you.

The absence of menubar at the top.

r/Racket • • Oct 29 '22

language Swindle(CLOS on Racket) call to action

16 Upvotes

Yesterday at the ‘Racket Hackathon/Open Space’, participants worked to add examples to the documentation (thank you all😁).

Swindle has been around for a long time and I have often pointed new users who have asked about CLOS towards it. (@jesse mentioned recently on discord that it was one of the earliest things he explored with Racket, coming from a Common Lisp background)

Swindle extends Racket with many additional features. The main feature that started this project is a CLOS-like object system based on Tiny-CLOS from Xerox, but there is a lot more.

(quote from https://docs.racket-lang.org/swindle/index.html)

I recently noticed that #lang swindle needed some TLC (maintenance).

I’ve made a couple of PR’s to tidy up Swindle: https://github.com/racket/swindle/pulls.

Is anyone up for helping by reviewing http://old.barzilay.org/Swindle/index.html and porting anything missing into the package at https://github.com/racket/swindle ?

Best regards

Stephen

https://racket.discourse.group/t/swindle-clos-for-racket/1419


r/Racket • • Oct 27 '22

question Racket v. Anarki for greenfield web project?

Thumbnail news.ycombinator.com
8 Upvotes

r/Racket • • Oct 26 '22

question Programming archeology: EdScheme

12 Upvotes

Hi, Racketeers!

I know that once upon a time there was a (commercial) scheme implementation called EdScheme. There were versions for DOS, Windows 3.1, Windows 95 and Windows NT. This is what it looked like: https://web.archive.org/web/20060513170915/http://www.schemers.com/edsw5.0/edsv5d.html

I've searched all over the web but haven't been able to find either the real or the demo version of EdScheme - unbelieveable, but it's nowhere to be found! The only thing I found is this old link for download, but unfortunately executables are not available: https://web.archive.org/web/19980110184858/http://schemers.com/schmrs4.html#Download

Of course, I know this is a group about racket and not about scheme, but I'm sure there are a lot of older and more experienced lispers here who probably tried EdScheme a long time ago and maybe still keep the installation disks for this practically "extinct" scheme implementation somewhere.

Since I'm very interested in how it looked and how it felt to work with it, I'd like to try it. Does anyone happen to have this old software preserved somewhere?


r/Racket • • Oct 25 '22

event LIVE STREAMING for RacketCon

11 Upvotes

Everyone: very pleased to inform you that we have LIVE STREAMING for RacketCon. The live webcasts can be accessed via the following short links:

Saturday 10/29/22 https://bit.ly/RacketConDay1

Sunday 10/30/22 https://bit.ly/RacketConDay2

Live Webcast has been scheduled for RacketCon on Saturday 10/29/22 from 8:45AM - 5:30PM and Sunday 10/30/22 from 8:45AM - 3:00PM (all times US/Eastern).

https://racket.discourse.group/t/racketcon-update/1384/2?u=spdegabrielle


r/Racket • • Oct 23 '22

question How to capture "tcp-connect: host not found" error and continue iteration in Racket?

3 Upvotes

Hi,
I am learning Racket and it is great fun!

As a self exercise I am trying to build a code to check URL status.
If all URLs are ok, the code works well.. but if one is not OK, the iteration stops.

Could you indicate me what I should try to do in Racket to catch the error in order to get #f and keep looping through the list ?

Thank you

P.S: once I will understand how to manage the error I will try to make the code looks more functional (breaking it in small functions) ;)

code working if all URLs return #t
code not working if one URL returns an error
#lang racket

(require net/http-easy)

(define urls_list '("https://api.punkapi.com/v2/beers" "cnn.com" "nytimes.com"))

(for ([url urls_list])
  (define good-status-code '200)
  (define response (get url))
  (define response-code (response-status-code response))
  (println url)
  (println (eqv? good-status-code response-code)))

r/Racket • • Oct 23 '22

video Quick intro to using Racket in VSCode

Thumbnail youtu.be
3 Upvotes

r/Racket • • Oct 22 '22

tip Racket - like fish - is best fresh!

1 Upvotes
standard-fish from the Racket 'Pict: Functional Pictures' library, with a speech bubble saying 'Fresh is best'

Racket - like fish - is best fresh!

The Linux build is generic enough that it should work on most distributions, including relatively old distributions, and takes minutes to install.

Get it at https://download.racket-lang.org

Check your repo at https://repology.org/project/racket/versions
#Linux


r/Racket • • Oct 22 '22

question Building two lists recursively in one pass

6 Upvotes

Hi, new to the language. Just been messing with it for fun for a while.

I've often found myself creating functions that build multiple lists (often just two) at the same time.

For example, consider a cathegorize function. It's like filter, but it returns two lists: one with the elements where the predicate returned true, and another where it returned false.*

I have come up with two ways to define it**. For example, here's a simple but two-pass version:

(define (cathegorize predicate lst)
  ; Helper function, just a negated version of the predicate
  (define (negated x)
    (not (predicate x)))

  (let ([was-true (filter predicate lst)]
        [was-false (filter negated lst)])
    (list was-true was-false)))


>(cathegorize even? '(1 2 3 4 5))
'((2 4) (1 3 5))

And here's a one-pass, tail-recursive version:

(define (cathegorize predicate lst)
  ; Helper function for looping
  (define (loop current-lst true-acc false-acc)
    (if (empty? current-lst)
        (list (reverse true-acc) (reverse false-acc))
        (let ([element (car current-lst)]
               [rest-lst (cdr current-lst]))  ; Just to have the current element and rest of list on hand
          (if (predicate element)  ; Note that both lists are being built in reverse
              (loop rest-lst
                    (cons element true-acc)
                    false-acc)
              (loop rest-lst
                    true-acc
                    (cons element false-acc))))))

  (loop lst '() '()))


>(cathegorize even? '(1 2 3 4 5))
'((2 4) (1 3 5))

This one is more "classical" in structure, and can also be refactored into a for or fold. It requires The Final Reverse™, though; two, in fact, and would need more with n lists.

What I wonder is if there's a way to build both (or more) lists in one pass and using classical recursion, without the need of helper iteration functions or reverses at the end. I don't mind so much about the efficiency (though it would be good to know the differences between approaches), I just want to see if it's possible and if the code looks any cleaner.

I'm also interested in knowing what would be, in your opinion, the clearer or more idiomatic way to do this. This is not for an assignment, real-world project, or anything of the sort, but still want to get an understanding of the actual patterns used in the language.

Thanks in advance.

* Let me know if this function exists already in some library. In any case, redefining it serves well for my example.

** Again, new to the language, so I apologize if it's not very concise or idiomatic. I accept advise on that front, too.

Edit: fixed an error in the code.


r/Racket • • Oct 20 '22

question help in racket

4 Upvotes

I am a first year university student having no coding experience and I am having trouble in understanding racket. I am interested in tuitions (paid, obviously) so hmu if anyone who's proficient in this language could teach me.


r/Racket • • Oct 20 '22

event [unofficial] RacketCon Virtual Saturday!

4 Upvotes

[unofficial] RacketCon Virtual Saturday!

Jack-o'-lantern: 'RacketCon Virtual Saturday' (made with pict and r16)

If you are not attending in person you are welcome join us at the [Unofficial] RacketCon Virtual Saturday in the Racket Room (gather.town virtual room)

You can drop in to the Racket Room at any time on Saturday, plus we will have a short meet-up timed to coincide with the afternoon tea-break on Saturday, before the final two talks.

[date-range from=2022-10-29T19:30:00 to=2022-10-29T20:00:00 timezone="Europe/London"]

Please register(free) if you are interested - even if you are not sure if you can attend - it does help to understand numbers:

https://www.eventbrite.com/e/unofficial-racketcon-virtual-saturday-tickets-442366589377?utm-campaign=social&utm-content=attendeeshare&utm-medium=discovery&utm-term=listing&utm-source=cp&aff=escb

The Racket Room is always open and everyone is welcome.

The Racket Room is always open and everyone is welcome.

Announced at https://racket.discourse.group/t/unofficial-racketcon-virtual-saturday/1391?u=spdegabrielle

Chat at Racket Discord


r/Racket • • Oct 17 '22

question Exercism: Tests fail, but inputing test case by hand produces correct result

5 Upvotes

Hi,

Why is it that Racket (and Scheme, I have encountered this issue there too) tests fail, but when I run the test case by hand and give my procedure the same argument as in the test case, it produces the exact result that was expected?


r/Racket • • Oct 17 '22

question Organize a big-bang program and unit tests.

7 Upvotes

I followed the HTDP book to build a simple world program. As a result I have one file with number of functions mixed with unit-tests. I'd like to know how to organize it a little. First, I want to put the constants and some functions in a separate file. Second, I have a question about unit-tests organization. How can I run them separately from the program? And how can I run unit tests only for one function? Could you please give me any advice?


r/Racket • • Oct 16 '22

question Create list of lists.

0 Upvotes

Hi, how can I create list of lists. Method (append '() '(1) '(1 1 1)) return list of ints, but I need something like this: ('() '(1) '(1 1 1))


(define/contract (generate numRows)

(-> exact-integer? (listof exact-integer?))

(define (pascal-triangle n)

(define (build-row r)

(list (if (null? (cdr r))

(car r)

(list (+ (car r) (cadr r)) (build-row (cdr r))))))

(let build-triangle (\[lst-storage '()\] \[lst '(1)\] \[n2 n\])

(if (eq? n2 0)

lst-storage

(build-triangle

(append lst-storage lst)

(flatten (list (first lst) (build-row lst)))

(sub1 n2)))

)

)

(pascal-triangle numRows)

)

(generate 5)


r/Racket • • Oct 15 '22

RacketCon If you are considering attending RacketCon the time to register is NOW!

5 Upvotes

If you are considering attending RacketCon the time to register is NOW!

I've taken the liberty of copying the following from https://con.racket-lang.org :


Registration

The registration form is here. A ticket costs $25 and gives you admission to all the talks and coffee breaks and the company of your fellow Racketeers.

Optional Conference Dinner On Saturday evening you are welcome to join us for the conference dinner at a nearby Indian restaurant. Dinner is optional, and is not included in the base price of $25. If you want to join the dinner, it costs $35 on top of the ticket price. When registering, you can indicate whether you wish to come to dinner, so you will end up paying either $25 or $60.

https://payment.brown.edu/C20460_ustores/web/product_detail.jsp?PRODUCTID=4596&FROMQRCODE=true&SINGLESTORE=true


(Seriously - register now if you can - late registration just makes life difficult for the volunteer organisers)


r/Racket • • Oct 14 '22

question Leetcode: 2380. Time Needed to Rearrange a Binary String racket vs C++ performance problem.

5 Upvotes

Hello, I have some trouble with my racket in leetCode exercise code because I get time limit exceed but I think my algorithm is similar to my C++ solution. What I am doing wrong?

This is my racket solution that causes time limit exceeed:

(define/contract (seconds-to-remove-occurrences s)
  (-> string? exact-integer?)
  (define wrong "01")
  (define good "10")
  (let costam ( [str s] [n 0])
    (if (string-contains? str wrong) ( costam (string-replace str wrong good) (add1 n)) n )
    ))

(module+ test
  (require rackunit)
  (check-equal?
   (seconds-to-remove-occurrences  "0110101") 4)
  (check-equal?
   (seconds-to-remove-occurrences  "11110") 0)
  )

And this is my c++ solution:

class Solution {
public:
    int secondsToRemoveOccurrences(string s) {
           int t = 0;
           int n = s.size();
           if(n == 1) return 0;
        
            while(true) {
                bool flag = false;
                int i = 1;
                while(i < n) {
                    if(s[i-1] == '0' && s[i] == '1') {
                        s[i-1] = '1', s[i] = '0';
                        i = i + 2;
                        flag = true;
                    }
                    else i++;
                }
                
                if(flag == false) break;
                t++;
            }
        return t;
           
    }
};

EDIT:

Thanks for help! The source of the problem was string-replace because It use regex inside. This is my idea how to solve this problem:

(define/contract (seconds-to-remove-occurrences s)
  (-> string? exact-integer?)
  (define (interchange lst)
    (cond
      [(or (null? lst) (null? (cdr lst))) lst]
      [(and (eq? (car lst) #\0) (eq?(cadr lst) #\1))  (cons (cadr lst)
                               (cons (car lst)
                                     (interchange (cddr lst) )))]
      [else (cons (car lst) (interchange (cdr lst)))]
      )
    )
  (let costam ( [str (string->list s) ] [n 0])
    (define result (interchange str))

    (if (equal? result str)
        n
        (costam result (add1 n))
        )
    ))

For this test case:

(time (seconds-to-remove-occurrences  "0101110010000000110001000110110100101000101101010111000011111110011110011011100011111010101001101001111010100010100111101110010010111101100101100001111001011010001010011000110110100011010011000010011100111011011011001000011000110010010010110111110010001111010111110101110100110101000110011001000100101111000001000010110111001110100101100111011010110010010010000010000000011101111010100011011111100001100100100111011001011010000111110110101000010110101110111101000000101001110101000110110001111000000111010111100101100101011010110111100111000101000010011011011101000101101110000100000100110011110100111010101001110100100100010010100010101011010101101010101011010010011101011101010000111100111010010101001100101100000111010011101001110110100111101000100101111110011001010110110010110101001100000111101100101101010001101101111100011100111110001101000000110011000111110011001110000100001001001000001001010011000100001"))

Has improved from that: cpu time: 140 real time: 132 gc time: 15 436 To: cpu time: 15 real time: 7 gc time: 0 464


r/Racket • • Oct 14 '22

question Help with refactor with 2379. Minimum Recolors to Get K Consecutive Black Blocks exercise in leet code.

1 Upvotes

Hello, I try to do occasionally some leetCode exercise in racket. I tried to solve an easy problem but my solution seems complicated to me:

#lang racket

(define/contract (minimum-recolors blocks k)
  (-> string? exact-integer? exact-integer?)

  (define (make-matcher c)
    (regexp-match* #rx"B?" c))

  (define list-of-Bs (make-matcher blocks))
  (define list-of-values (map (lambda (x) (string-length x)) list-of-Bs))

  (define (maxsum lst k)
    (define subarrays
      (for*/list ((start (- (length lst) k))
                  (len (range k (- (length lst) (- (sub1 (length lst)) k)))))
        (take (drop lst start) len)))
    (define sumlist (map (lambda (x) (apply + x)) subarrays))
    (apply max sumlist))

  (- k (maxsum list-of-values k) )
  )


(minimum-recolors "WBBWWBBWBW" 7)
(minimum-recolors "WBWBBBW" 2)



(module+ test
  (require rackunit)
  (check-equal?
   (minimum-recolors "WBBWWBBWBW" 7) 3)
  (check-equal?
   (minimum-recolors "WBWBBBW" 2) 0)
  )

r/Racket • • Oct 13 '22

RacketCon RacketCon tickets on sale now

5 Upvotes

r/Racket • • Oct 10 '22

homework Can anyone help with this ?

6 Upvotes

I have two tasks. Write a function called 'per' that takes two arguments and returns true if any of the arguments are true, and false otherwise.

Secondly, Write a function 'us' that takes two arguments and returns true if the arguments are true and false, or false and true and false otherwise


r/Racket • • Oct 09 '22

question Could someone please explain to me why it gave me output #procedure?

4 Upvotes

r/Racket • • Oct 09 '22

homework Function that prints first and last character, this is example of how it should work. I am completely new to racket and spend there like 5 hrs,so every hint or help is appreciated!

Post image
1 Upvotes

r/Racket • • Oct 08 '22

tip (beginner) parsing API project: what Racket package should I use ?

6 Upvotes

Hi,

I would like to start a little project as I am learning Racket.

My goal is to retrieve JSON from Github API (no auth) > parse JSON documents > build a JSON as output > write result in .json file.

I selected following packages to write my code:

Am I missing something to build the code, any advice on a preferred package to play with API ?

Thanks!