Skip to content

Instantly share code, notes, and snippets.

@jackfirth
jackfirth / package-count.rkt
Created November 4, 2015 04:27
Counts the number of packages at pkgs.racket-lang.org
#lang racket
(require request
fancy-app)
(define (read-from-string s) (read (open-input-string s)))
(define read-response-requester (wrap-requester-response read-from-string _))
(define (header-requester key value requester)
(add-requester-headers (list (format "~a:~a" key value)) requester))

12 Days of Racket Packages - debug

raco pkg install debug

It's the simplest tools that we reach for first. That's why one of the most common ways programmers debug their programs is with printf, display, print, console.log, System.out.println, System.Console.WriteLine, or whatever other console printing tool your language of choice has. It's easy to understand, not too inflexible, and usually good enough. But even for only simple debugging, is that the best a language can do?

Not in Racket! The debug package (source) by Alex Knauth is a unique approach to debugging. Instead of manually writing print statements and formatting strings in the middle of the flow of your code, debug only requires two characters:

@jackfirth
jackfirth / define-exception-type.rkt
Created November 17, 2015 21:31
Utils for exceptions
(define-syntax-rule (define-exception-type id parent-id raise-id)
(begin
(struct id parent-id ())
(define-exception-raiser raise-id id)))
(define-syntax-rule (define-exception-raiser raise-id constructor-id)
(define (raise-id message)
(raise (constructor-id message (current-continuation-marks)))))
(define-syntax-rule (define-parameter-with param-expr with-id)
(define-syntax-rule (with-id new-param-value-expr body ...)
(parameterize ([param-expr new-param-value-expr])
body ...)))
(define-syntax-rule (define-parameter-call-with param-expr call-with-id)
(define (call-with-id new-param-value thunk)
(parameterize ([param-expr new-param-value])
(thunk))))
@jackfirth
jackfirth / package-tags.md
Last active August 13, 2017 17:03
A list of Racket package tags to be used in The Great Catalog Tag War
  • app provides an application for users, rather than a library

  • app-syntax provides a general-purpose #%app syntactic form, such as dictionary lookup through #%app

  • concurrency provides something useful for concurrent programming

  • config something related to configuration, such as reading from env vars or flags

  • crypto something related to cryptography, including hash algorithms and TLS bindings

  • data provides a data structure of some sort

  • datetime something related to dates or times

  • debug something related to debugging programs

@jackfirth
jackfirth / syntax-parse-intro.rkt
Created October 25, 2018 06:42
Intro to using syntax-parse
#lang racket
(require (for-syntax syntax/parse))
;; Macros created with define-syntax are functions from syntax objects to syntax
;; objects. Syntax objects are basically s-expressions + a bunch of binding
;; information and metadata.
;; GRAMMAR: (when-let ([id condition-expr] ...) body ...)
;; Executes body forms if every condition-expr is non-false, and binds the
@jackfirth
jackfirth / mp-racket-links.md
Last active September 23, 2019 21:43
Links + resources for multi-platform Racket
@jackfirth
jackfirth / unused-deps.md
Created March 5, 2019 01:55
Deps reported as unused by `raco setup --unused-pkg-deps` in racket 7.2 (with some packages installed)
raco setup: unused dependencies detected
  for package: "htdp-lib"
  on packages:
   "typed-racket-more"
   "rackunit-typed" for run
raco setup: unused dependency detected
  for package: "string-constants-doc"
  on package:
   "string-constants-lib" for run
@jackfirth
jackfirth / syntax-property-list.md
Created March 6, 2019 22:26
List of syntax properties used by various Racket tools
  • 'disappeared-use
  • 'disappeared-binding
  • 'sub-range-binders
  • 'mouse-over-tooltips
  • 'original-for-check-syntax
  • hidden property used by syntax-original?
  • 'paren-shape
  • 'origin
  • 'protected
  • 'module-language (used by make-meta-reader)
@jackfirth
jackfirth / keybase.md
Created August 8, 2019 03:04
Proof of identity for Keybase

Keybase proof

I hereby claim:

  • I am jackfirth on github.
  • I am notjack (https://keybase.io/notjack) on keybase.
  • I have a public key ASBH2HHhXXPl5IX8fqkKchCqXxDyyxK_UbCO4u69yb_CZgo

To claim this, I am signing this object: