Skip to content

Instantly share code, notes, and snippets.

View jackfirth's full-sized avatar

Jack Firth jackfirth

View GitHub Profile
  • Use xrepl when developing outside DrRacket. Set to automatically start up whenever racket is run at command line.
  • racket-mode for emacs development
  • #lang envy for environment variable configuration
  • #lang debug for "printf debugging"
  • #lang sweet-exp for prettifying requires and provides, or other simple pieces of code where parens are just noise (can be partially used in a file, doesn't need to apply to the whole file)
  • #lang reprovide for modules that just require and provide other modules to group them together
  • Use #lang racket/base instead of #lang racket for libraries, packages, and other re-usable pieces of code, to reduce dependencies
  • Use the -lib packages of libraries for applications to reduce dependencies
  • When designing libraries, avoid documenting and exposing subcollections to allow more flexibility for the library's code to shift around
  • When designing libraries, stick non-exposed modules into a /private subcollection to make any code depending on internals sti
@defproc[(specification [prop property?] [arb arbitrary?] ...) specification?]{
Constructs a runnable, executable, testable @specification-tech[] that tests that
@racket[prop] holds for all inputs from the given @racket[arb]s. The returned
specification can be quickly tested with @racket[check-specification]. Additionally,
the specification can be run and have its results analyzed separately by using
@racket[run-specification].
@quickcheck2-examples[
(check-specification (specification positive? arbitrary-natural))
(check-specification (specification even? arbitrary-natural))
]}
@jackfirth
jackfirth / grammar.rkt
Created October 29, 2015 16:42
Fooling around with grammar definition syntaxes
(define (zero-or-more term)
(one-of term
(sequence-of term (zero-or-more term))))
(define nat-addition-grammar
(grammar [NUMBER (one-of DIGIT
(sequence-of NONZERO-DIGIT (zero-or-more DIGIT)))]
[DIGIT (one-of NONZERO-DIGIT
(literal 0))]
[NONZERO-DIGIT (one-of (literal 1) (literal 2) (literal 3) (literal 4) (literal 5) (literal 6) (literal 7) (literal 8) (literal 9))]

What is the type of a value that promises the following:

  1. It is a struct instance
  2. It has a certain struct property
  3. That struct property has certain restrictions on its value

12 Days of Racket Packages - flexpr

Welcome to 12 Days of Racket Packages! The Racket Package Catalog contains 695 packages at the time of this writing (counting packages in the main distribution). That's a pretty big achievement for such a small community and a package system that's barely two years old. In hopes of helping users find great packages, we're publishing a series of 12 blog posts, once per day, starting today. Each post will detail a single package available in the catalog and describe what you might use it for and what's interesting about it. Extra attention may be paid to "Rackety" features, for instance packages providing a custom #lang. This series is in the spirit of and directly inspired by 24 Days of Hackage.

The flexpr package (source) by Greg Hendershott is a simple package

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 / packages.md
Last active December 11, 2015 22:48
Summary of thoughts on extensions to, implementations of, ideas about, and protocols surrounding Racket package catalogs

Exposition

A package catalog is something that maps package names to package metadata which must include a package source. This decouples the name of a package from where it's source is located, allowing package authors to declare dependencies on names instead of sources and to relocate the source of their package without breaking the dependency specifications of client packages.

Package metadata must include a checksum, but other than that no keys are required for a properly operating package catalog. However many tools (particularly raco pkg) use certain