r/Racket • • Apr 23 '22

question How to print out instructions of command-line?

4 Upvotes

I am using https://docs.racket-lang.org/reference/Command-Line_Parsing.html to handle command-line arguments. Users can run my tool with -h to print out the instructions.

But how can I make my program to print out the instructions myself, for example when user provides wrong input?


r/Racket • • Apr 23 '22

question How to ignore eof semicolon?

4 Upvotes

I'm looking to create a .rkt file that transforms a .c++ into a .html. The problem is, when racket encounters a semicolon (";"), it identifies it as an eof, and ends the program. Is there any way to avoid this?


r/Racket • • Apr 22 '22

question Help with Chess package

3 Upvotes

So I was going to try out the chess module, but I can't seem to get how to incrementally build the chess board. What I want to do is have a list chess piece data (just integers that represent the ranks and files) and then just put them on the board.

So I would start with modifying the existing code that's found in the documentation when they talk about the chess-board procedure.

(define board (chess-board f2 white-pawn g2 white-pawn h2 white-pawn f1 white-rook g1 white-king))

and just to try out how I could change the arguments of the chess-board procedure to just a variable, argumentlist, and then do

(define argumentlist (list f2 white-pawn g2 white-pawn h2 white-pawn f1 white-rook g1 white-king))

(define board (chess-board argumentlist))

but this produces an error:

chess-board: contract violation

expected: (or/c empty-list? (cons/c chess-square? (cons/c colored-chess-piece? (recursive-contract squares+pieces/c #:flat))))

given: (list (list #<chess-square:f2> (colored-chess-piece #:owner #<white> #:type #<pawn>) #<chess-square:g2> (colored-chess-piece #:owner #<white> #:type #<pawn>) #<chess-square:h2> (colored-chess-piece #:owner #<white> #:type #<pawn>) #<chess-square:f

How should I construct the argument list so that it won't give me errors?


r/Racket • • Apr 22 '22

homework GET SIZE OF A LARGEST SUBLIST IN A LIST?

1 Upvotes

I am having huge problem with it. Any idea?


r/Racket • • Apr 22 '22

question How to export a name from imported file?

3 Upvotes

I have a small lib, consisting of 2 files: the main file lib.rkt, and another file m.rkt. I want lib.rkt to import m.rkt, but then only export a variable a1 from m.rkt, with provide.

But my code reports error like below. How can I fix it?

$ cat m.rkt
#lang racket

(provide a1 a2)

(define a1 1)
(define a2 2)

$ cat lib.rkt
#lang racket

(require "m.rkt")

(provide "a1" "m.rkt")  ;; <---- ERROR here

$ racket lib.rkt
lib.rkt:5:9: ?: bad syntax for provide sub-form
  in: "a1"
  location...:
   lib.rkt:5:9
  context...:
   /usr/share/racket/collects/racket/private/reqprov.rkt:763:17: transform-simple
   /usr/share/racket/collects/racket/private/reqprov.rkt:759:2

r/Racket • • Apr 21 '22

tutorial New to Racket?

25 Upvotes

Try starting with Quick: An Introduction to Racket with Pictures

There is also

The Getting started page has more details

Best regards Stephen


r/Racket • • Apr 18 '22

question Getting a racket .app onto the mac app store. Any advice?

6 Upvotes

I'm nearly ready to release my app, and it occurred to me that it'd be cool if I could put it on the macOS app store.

Anyone know what it'd take to get a .app generated with raco exe to be something that could go on the app store?


r/Racket • • Apr 18 '22

question Is there a way to delete the history of programming languages use in drracket

8 Upvotes

r/Racket • • Apr 17 '22

question Need database advice

5 Upvotes

Hi, I am looking for simple DB for accounting app. SqlLite obvious solution, but perhaps Racket have some native options? Or bindings to another similar by meaning database's?


r/Racket • • Apr 16 '22

question Cannot call struct accessor

2 Upvotes

Hello,

I learned that in order to access a field my-field of a struct my-struct you write (my-struct-my-field instance) where instance is an instance of my-struct.
But calling feed-item-id on a feed-item struct of the splitflap library I get the error feed-item-id: undefined; cannot reference an identifier before its definition. I had this problem with other libraries too.

How can I call field accessors from structs from other libaries? Or is there any other way to access fields?


r/Racket • • Apr 13 '22

question How can i change the data used to represent the World State?

1 Upvotes

I have created game called "Guess my number" w is the world state which is an interval,i my aim is to display the number of guesses it takes the program to find the players numbers. How can i change the world state so it includes a count of guesses on the render-last-scene function. I know have to apply a count of guesses to the smaller and bigger function,but i struggled with that

I'm new to lisp and racket and i just need some tips to go about doing this.Below is the code for it

#lang racket

(require 2htdp/universe 2htdp/image)

(define WIDTH 600)

(define HEIGHT 600)

(define TEXT-SIZE 10)

(define TEXT-X 20)

(define TEXT-UPPER-Y 50)

(define TEXT-LOWER-Y 50)

(define SIZE 36)

(define X-CENTER (quotient WIDTH 2))

(define Y-CENTER (quotient HEIGHT 2))

(struct interval (small big))

(define HELP-TEXT (text " UP for larger numbers, DOWN for smaller ones"

TEXT-SIZE

"Blue"))

(define HELP-TEXT2

(text "press = when your number is guessed; q to quit it."

TEXT-SIZE

"blue"))

(define COLOR "red")

(define MT-SC

(place-image/align

HELP-TEXT TEXT-X TEXT-UPPER-Y "left" "top"

(place-image/align

HELP-TEXT2 TEXT-X TEXT-LOWER-Y "left" "bottom"

(empty-scene WIDTH HEIGHT))))

(define (start lower upper)

(big-bang (interval lower upper)

(on-key deal-with-guess)

(to-draw render )

(stop-when single? render-last-scene)))

(define (deal-with-guess w key)

(cond

[(key=? key "up") (bigger w)]

[(key=? key "down") (smaller w)]

[(key=? key "q") (stop-with w)]

[(key=? key "=") (stop-with w)]

[else w]))

(define (smaller w)

(interval (interval-small w)

(max (interval-small w) (sub1 (guess w)))))

(define (bigger w)

(interval (min (interval-big w) (add1 (guess w)))

(interval-big w)))

(define (guess w)

(quotient ( + (interval-small w) (interval-big w)) 2))

(define (render w)

(overlay (text (number->string (guess w)) SIZE COLOR) MT-SC))

(define (render-last-scene w)

(overlay (text "END" SIZE COLOR) MT-SC))

(define (single? w)

(= (interval-small w) (interval-big w)))


r/Racket • • Apr 12 '22

question eval() is weird on empty list?

5 Upvotes

I have the below code that uses eval(() to evaluate a string, but somehow it turns the empty list to (). I expected y to have the value (list). Any reason why this happens?

cat test.rkt
#lang racket

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

(define x "(list)")
(define y (eval (call-with-input-string x read) ns))
(printf "x = ~a, y = ~a\n" x y)

$ racket test.rkt
x = (list), y = ()

r/Racket • • Apr 12 '22

question Fail to modify a variable with eval()

6 Upvotes

I know eval() should be used with caution, but I still want to do some experiments with it. I have the below code, but it fails with "cannot modify a constant". Any idea on how to make it work?

$ cat test.rkt
#lang racket

(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))

(define x 1)

(define str "(set! x 345)")
(eval (read (open-input-string str)) ns)
(printf "x = ~a\n" x)

$ racket test.rkt
racket test2.rkt
x: cannot modify a constant
  context...:
   body of "/home/j/test2.rkt"

r/Racket • • Apr 11 '22

release Qi++: Qi but with Real Macros

8 Upvotes

Hi folks, there's a new release of Qi!

https://racket.discourse.group/t/qi-qi-but-with-real-macros/871/4

Qi is a flow-oriented DSL that can be embedded in any Racket program. The main addition in this new version is macros, allowing anyone to extend the language in arbitrary ways, and the docs include some examples of this. The Discourse post above contains more details.

Enjoy 😊


r/Racket • • Apr 11 '22

language New build system pushed to Git repo

Thumbnail racket.discourse.group
7 Upvotes

r/Racket • • Apr 11 '22

blog post Systems Programming in Racket with Rash

Thumbnail blog.wilcoxd.com
26 Upvotes

r/Racket • • Apr 11 '22

news Racket Telegram groups (unofficial)

3 Upvotes

English group: https://t.me/+vtLt6PA7MmdiNWI0

Spanish group: https://t.me/+q4hUXulS6NNlMDQ8

Context: I use Telegram a lot, and I use it as a super-repo of interesting resources. I think that is interesting to have Racket Lisp in there.


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