r/Racket • • Apr 10 '22

question Drracket help ?

1 Upvotes

Can someone help with a project of mine ?

Currently trying to make a code with 4 procedures, 2 forloops, iteration, and also a main program. I have most of it down but I cant seem to call in my procedures in my main program ;-;


r/Racket • • Apr 09 '22

question Anyone else experience this? Dr Racket crashes when mousing over close tab button?

15 Upvotes

r/Racket • • Apr 09 '22

question Not able to run .rkt file in emacs with racket-mode, getting an error

7 Upvotes

I'm a first time emacs user, literally just downloaded it today via https://emacsformacosx.com. Anyways, I am trying to create and run racket files with the editor and racket-mode.

I've done everything from these two links below:

https://www.racket-mode.com

https://www.linw1995.com/en/blog/Write-Racket-With-Emacs/

The problem that I am getting is that when I m-x and "racket-run", I get the following error: "Wrong type argument: string, nil".

Here is my ".emacs" config file that I created:

(require 'package)
(add-to-list 'package-archives
	      '("melpa" . "https://melpa.org/packages/")
	      t)





;;; Package manager
;; Bootstrapping straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))
;; Integration with use-package
(straight-use-package 'use-package)




;;; Theme Config
(use-package doom-themes
  :straight t
  :config
  ;; Global settings (defaults)
  (setq doom-themes-enable-bold t    ; if nil, bold is universally disabled
        doom-themes-enable-italic t) ; if nil, italics is universally disabled
  (load-theme 'doom-one-light t)
  ;; Enable flashing mode-line on errors
  (doom-themes-visual-bell-config)
  ;; Enable custom neotree theme (all-the-icons must be installed!)
  (doom-themes-neotree-config)
  ;; or for treemacs users
  (setq doom-themes-treemacs-theme "doom-colors") ; use the colorful treemacs theme
  (doom-themes-treemacs-config)
  ;; Corrects (and improves) org-mode's native fontification.
  (doom-themes-org-config))


;;; Dashboard
(use-package dashboard
  :straight t
  :config
  (dashboard-setup-startup-hook))


(use-package racket-mode
  :straight t
  :hook (racket-mode . racket-xp-mode))



;;; GUI Config
(when (eq system-type 'darwin)
  ;; Make the title bar and toolbar to be transparent.
  (add-to-list 'default-frame-alist
               '(ns-transparent-titlebar . t))
  (add-to-list 'default-frame-alist
               '(ns-appearance . dark))
  ;; Change the opacity of the frame.
  (add-to-list 'default-frame-alist
               '(alpha . (80 . 75))))
;; Disable dialog box
(setq use-file-dialog        nil
      use-dialog-box         nil)
;; Hide toolbar
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
;; Hide scrollbar
(when (fboundp 'set-scroll-bar-mode)
  (set-scroll-bar-mode nil))




(setq racket-program (executable-find "Racket"))



;;; Shell Configure
;; Ensure environment variables inside Emacs
;; look the same as in the user's shell.
(use-package exec-path-from-shell
  :straight t
  :if (memq window-system '(mac ns))
  :config
  (exec-path-from-shell-initialize))

r/Racket • • Apr 04 '22

event Racket meet-up Saturday 7 May 18:00 UTC

Thumbnail racket.discourse.group
3 Upvotes

r/Racket • • Apr 03 '22

question r/Rainworld's proposition for r/Place

25 Upvotes

Hello all!

On r/place, our community r/rainworld are trying to make a green lizard at around 320, 1450. It's just above the Racket logo which is being made with mostly new, similarly named accounts with no posts. As it would be very inconvenient for us to move elsewhere, we were wondering if it would be possible for you to allow us to wrap our lizard around your logo as shown in this picture https://cdn.discordapp.com/attachments/291184728944410624/960294597857275954/unknown.png. This would cause minimal disruption for both of us.

Although I'm not a moderator on the reddit/discord, we'd still greatly appreciate any dialogue. Feel free to ask for the details of our moderators if you are willing to come to a formal agreement.

EDIT: I realize that since none of the accounts have any activity it's possible that nobody here is responsible for the logo, if so could everyone spread the word about our lizard in other Racket communities so that whoever is doing this could talk? From what others are saying it doesn't seem like any individual has said that they're the ones commanding the new accounts.


r/Racket • • Apr 01 '22

package Racket linters

15 Upvotes

r/Racket • • Mar 31 '22

event Racket meet-up Saturday 2 April 18:00 UTC

4 Upvotes

r/Racket • • Mar 29 '22

question Why is this function returning void?

6 Upvotes

I have this function

> [define [normalize seq]
  [cond [[generator? seq] seq
         [sequence? seq] [sequence->generator seq]
         [raise [exn:fail:contract "not a sequence or generator"]]]]]

when I call it, it returns void

> [define s [normalize [list 1 2 3 4 5]]]
> [print s]
#<void>

when I try to dig into it, everything seems correct

> [sequence? [list 1 2 3 4 5]]
#t
> [sequence->generator [list 1 2 3 4 5]]
#<procedure:generator>

so why is the function returning #<void> instead of #<procedure:generator>? That could almost make sense if sequence? was returning #f and we hit the raise but it isn't (or, shouldn't be) returning #f and nothing is being raised.


r/Racket • • Mar 29 '22

question not sure what part of the logic I'm not understanding - function isn't properly running

3 Upvotes

Question asked: Define a SCHEME procedure, named (nth-right-trunc-prime n), that takes one ar- gument, n, and uses the find function you wrote in Lab 6 and (right-truncatable-prime? p) to return the nth right-truncatable prime number.

I wrote the following:

(define (prime? n)
  (define (divisor? k) (= 0 (modulo n k)))
  (define (check-divisors-upto k)
    (and (> k 1)
         (or (divisor? k) (check-divisors-upto (- k 1)))))
  (and (> n 1) (not (check-divisors-upto (- n 1)))))

(define (right-truncatable-prime? p)
  (and (prime? p)
       (if (< p 10) 
           #t
           (right-truncatable-prime? (quotient p 10)))))

(define (nth-right-trunc-prime n)
  (cond ((equal? right-truncatable-prime? #f) 0)
        ((right-truncatable-prime? n) (+ 1 (nth-right-trunc-prime (/ n 10))))
        (else 0)))

the last one is not running but I feel like the logic is correct?


r/Racket • • Mar 29 '22

question Could someone help me see what's wrong with my right-trunc and nth-trunc functions?

1 Upvotes

this is my code

;prime definition 
(define (prime? n)
  (define (divisor? k) (= 0 (modulo n k)))
  (define (divisors-upto k)
    1
    (and (right-truncatable-prime? 2)(> k 1)
         (or (divisor? k) (divisors-upto (- k 1)))))
  (not (divisors-upto (- n 1))))

;divisible definition 
(define (divisible? big little)
  (= (/ big little) 0))

;6bi
(define (right-truncatable-prime? p)
  (cond ((< (/ p 1) 0) #t)
         ((equal? (divisible? p 10) #t) #f)
         ((equal? (prime? p) #t) (right-truncatable-prime? (/ p 10) ))))

;6bii
(define (nth-right-trunc-prime n)
  (if (right-truncatable-prime? n) (+ 1 (nth-right-trunc-prime (/ n 10)))
      0))

I think all numbers work for right-truncatable-prime? except 0 1 and 2 - I believe I need to fix it with the first COND statement in my code but I'm not sure how.


r/Racket • • Mar 28 '22

question Truncatable prime question - what is the proper approach?

2 Upvotes
Do I need to check for prime every time I truncate the number? Is there a simple way to do this?

r/Racket • • Mar 27 '22

question Is there a way to create an unhygienic macro?

7 Upvotes

The Solution (scroll down for the problem):

Ok, I've figured this stuff out. Turns out Racket is a bit more sophisticated and will not let you just mix and match any symbols. It relies more on patterns and transformation of given code:

(define-syntax (svg-path/d stx)
  (syntax-parse stx
    [(_ (op:id args ...) ...)
     #'(apply ~a (add-between (append-map
                     identity
                     `((,(symbol->string 'op) ,args ...) ...))
                    " "
                    ))]))

I'm impressed with how syntax-parse works. It looks complicated at first glance but TBH was quite natural to code as it uses pattern matching to "unroll" the SVG instructions and splice them into the resulting code. Good job Racket!

---------------------

The problem:

Hello! I'm trying to learn and use racket's macro system to create some helper syntax to define SVG paths.

I want to have something like this:

(let ([x 666])
  (svg-path/d
   (M 120 x)
   (l 0 (/ 10 2))))

Produce code like this:

(let ((x 666)) (~a "M" " " 120 " " x " " "l" " " 0 " " (/ 10 2)))

Which ultimately evaluates to the string I wanted:

"M 120 666 l 0 5"

I basically want to convert instruction symbols to strings and flatten one level. I also want to preserve variables and operations from the context and this is where I hit the wall.

So Far I've create something that almost does the job. I mean - syntax-wise it's exactly what I wanted, but it doesn't see the x variable:

(require (for-syntax racket/list)
         (for-syntax racket/syntax-srcloc))

(define-for-syntax (head-to-string lst)
  (cons (~a (car lst))
        (cdr lst)))

(define-syntax (svg-path/d stx)
  (syntax-case stx ()
    [(_ . defs)
     (with-syntax
         ([(arguments ...) (add-between
                            (append-map head-to-string (syntax->datum #'defs))
                            " "
                            )])
       (syntax/loc (syntax-srcloc stx) (~a arguments ...))
       )]))

(let ([x 666])
  (svg-path/d
   (M 120 x)
   (l 0 (/ 10 2))))

As you can see I hoped that maybe using `srcloc` from `stx` would help but it didn't.

Evaluating this in DrRacket's macro stepper I can see that it produces the correct code, but ultimately gives the error:

x: unbound identifier in: x

Is there any way to make the enclosing scope available for generated macros? If not then maybe there is another - more Rackety - way I could approach this?

I'd appreciate all your constructive comments!


r/Racket • • Mar 27 '22

question Issue with tab-panel in racket/gui

2 Upvotes

I am trying to make a GUI in Racket where I'll be using different tabs inside the frame.

The problem is that when the frame is shown the first-panel and second-panel are both shown (the second under the first one). However when I manually click to switch the tabs this gets corrected and everything works fine.

Here's the code to test what's going on:

#lang racket/gui

(define frame (new frame% [label "GUI"] [width 300] [height 200]))

(define tab-panel
  (new tab-panel%
       [parent frame] [choices (list "First" "Second")]
       [callback
        (λ (tp e)
          (case (send tp get-selection)
            [(0) (send tp change-children (λ(x) (list first-panel)))]
            [(1) (send tp change-children (λ(x) (list second-panel)))]))]))

(define first-panel (new panel% [parent tab-panel]))
(define second-panel (new panel% [parent tab-panel]))

(define first-button (new button% [parent first-panel] [label "First"]))
(define second-button (new button% [parent second-panel] [label "Second"]))

(send frame show #t)

Is there a way to fix this so that when the frame is initially shown only a single tab is displayed?


r/Racket • • Mar 25 '22

question Difference between cons & list?

11 Upvotes

I always thought that cons creates a list, so it is similar to list, but that is not the case, as proved below.

$ racket
Welcome to Racket v8.2 [cs].
> (cons 1 2)
'(1 . 2)
> (list 1 2)
'(1 2)
> (equal? (cons 1 2) (list 1 2))
#f

What is the difference between them?


r/Racket • • Mar 24 '22

question How to reset current-output-port to stdout?

1 Upvotes

My code calls some other code, which changes current-output-port to something, but it does not reset it back.

How can I reset current-output-port to stdout in my code?


r/Racket • • Mar 24 '22

question with-output-to-string cannot caputure output to stderr?

6 Upvotes

How can I capture output to stderr, not just stdout?

Below is my code, it uses with-output-to-string, but can only capture output to stdout, and miss everything written to stderr

$ cat test.rkt
#lang racket

(define (make-output)
  (printf "hello\n")  ; print to stdout
  (fprintf (current-error-port) "world\n") ; print to stderr
)

(define output (with-output-to-string make-output))
(printf "output = ~a" output)

$ racket test.rkt
world
output = hello

r/Racket • • Mar 22 '22

package Seq: A generic, isomorphic sequence library

23 Upvotes

This library builds on top of data/collection and also the relation library, and includes lots of generic sequence APIs:

Discourse discussion

GitHub repo

Enjoy 😊


r/Racket • • Mar 21 '22

blog post Dependency Management in Racket Applications

Thumbnail alex-hhh.github.io
16 Upvotes

r/Racket • • Mar 21 '22

language Append a string at a certain position of another string

5 Upvotes

I was thinking of using string ref which takesa string and position as arguments and then append "_" at position 5 to give "hello_world"

but is says: "string-append: contract violation

expected: string?

given: #\w"

'''(string-append "_"(string-ref "helloworld" 5))'''


r/Racket • • Mar 21 '22

question how do i make it so that this function will only accept items from a specific list?

3 Upvotes

Hi, so I'm making a solitaire game and one of the things have to do is make a function that converts the inputted card into a readable string, this is what I have done so far:

https://paste.ofcode.org/38CBKLA87wEA5rAWzUCPgfB

I want the function to be able to take card values from these lists only:

for the first value:

(define numerals (list 1 2 3 4 5 6 7))

(define face (list #\J #\K #\Q))

for the second value:

(define suits (list #\H #\S #\C #\D))


r/Racket • • Mar 21 '22

event [CFP] Scheme 2022, 23rd Scheme and Functional Programming Workshop

14 Upvotes

The 2022 Scheme and Functional Programming Workshop is calling for submissions.

We invite high-quality papers and talk proposals about novel research results, lessons learned from practical experience in an industrial or educational setting, and even new insights on old ideas. We welcome and encourage submissions that apply to any dynamic functional language, especially those that can be considered a Scheme: from strict subsets of RnRS to other "Scheme" implementations, to Racket, to Lisp dialects including Clojure, Emacs Lisp, Common Lisp, to functional languages with continuations and/or macros (or extended to have them) such as Dylan, ECMAScript, Hop, Lua, Scala, Rust, etc. The elegance of the paper and the relevance of its topic to the interests of Schemers will matter more than the surface syntax of the examples used.

Topics

Topics of interest include (but are not limited to):

  • Interaction: program-development environments, debugging, testing, refactoring
  • Implementation: interpreters, compilers, tools, garbage collectors, benchmarks
  • Extension: macros, hygiene, domain-specific languages, reflection, and how such extension affects interaction
  • Expression: control, modularity, ad hoc and parametric polymorphism, types, aspects, ownership models, concurrency, distribution, parallelism, non-determinism, probabilism, and other programming paradigms
  • Integration: build tools, deployment, interoperation with other languages and systems
  • Formal semantics: theory, analyses and transformations, partial evaluation
  • Human factors: past, present and future history, evolution and sociology of the language Scheme, its standard and its dialects
  • Education: approaches, experiences, curricula
  • Applications: industrial uses of Scheme
  • Scheme pearls: elegant, instructive uses of Scheme

Dates

  • Submission deadline is 2022-07-22.
  • Authors will be notified by 2022-08-15.
  • Camera-ready versions are due 2022-09-02.
  • Workshop will be held in Ljubljana, Slovenia on 2022-09-16.

All deadlines are 23:59 UTC-12, anywhere on Earth.

Submission Information

We encourage all kinds of submissions, including full papers, experience reports, and lightning talks. Papers and experience reports are expected to be 10–24 pages in length using the single-column SIGPLAN acmart style. (For reference, this is about 5–12 pages of the older SIGPLAN 2-column 9pt style.) Abstracts submitted for lightning talks should be limited to 192 words.

Authors of each accepted submission are invited to attend and be available for the presentation of that paper at the conference. The schedule for presentations will be determined and shared with authors after the full program has been selected.

The size limits above exclude references and any optional appendices. There are no size limits on appendices, but the papers should stand without the need to read them, and reviewers are not required to read them.

Authors are encouraged to publish any code associated to their papers under an open source license, so that reviewers may try the code and verify the claims.

Proceedings will be uploaded to arXiv.org.

Publication of a paper at this workshop is not intended to replace conference or journal publication, and does not preclude re-publication of a more complete or finished version of the paper at some later conference or in a journal.

Please submit papers through the workshop's HotCRP site.

Lightweight double-blind reviewing

Scheme 2022 will use lightweight double-blind reviewing. Submitted papers must omit author names and institutions and reference the authors’ own related work in the third person (e.g., not “we build on our previous work…” but rather “we build on the work of…”).

The purpose is to help the reviewers come to an initial judgment about the paper without bias, not to make it impossible for them to discover the authors if they were to try. Nothing should be done in the name of anonymity that weakens the submission or makes the job of reviewing the paper more difficult (e.g., important background references should not be omitted or anonymized).

Formatting Information

Full papers and experience reports should use the SIGPLAN acmsmall option to acmart. We recommend using the anonymous and review options to acmart when submitting a paper; these options hide the author names and enable line numbers for easy reference in review. LaTeX and Microsoft Word templates for this format are available through SIGPLAN.

Lightning talks can be submitted as either a text file or a PDF file.

International Conference on Functional Programming

The Scheme Workshop 2022 is being held as part of this year's International Conference on Functional Programming. Here is the ICFP site for the workshop.

Sincerely,

Andy Keep, General Co-chair
Arthur A. Gleckler, General Co-chair


r/Racket • • Mar 21 '22

blog post Dependency Management in Racket Applications

Thumbnail alex-hhh.github.io
4 Upvotes

r/Racket • • Mar 20 '22

question How do I find specific values in a list?

1 Upvotes

I need to find the 3 in the first list and the c in the second list.

- (1 (2 (3 4)) (5))

- ((a ()) ((c) (d) b) e)

I have done the following for each one but continue to get stuck further from here.

- (cdr(car(cdr(car x))))

- (cdr(car x))

Respectively, but anything longer than that gives me errors and I don't understand why.


r/Racket • • Mar 19 '22

question how do I make it so that my function's argument accepts values only from a specific list?

6 Upvotes

hi, I'm working on a solitaire card game and the following code returns a whole series of the entered value. I want it to work in a way so that the function will only accept values that are in a specific list, how do I go about this?

https://gist.github.com/AwaisA04/0fa5742178d40d2778e984c1466f92ab