Skip to content

Instantly share code, notes, and snippets.

View shhyou's full-sized avatar
💭
Alive

shuhung shhyou

💭
Alive
View GitHub Profile
@shhyou
shhyou / racket_tips.md
Created August 29, 2021 20:18 — forked from sschwarzer/racket_tips.md
Racket tips and tricks

Racket tips and tricks

These are extracted from discussions I triggered on the Racket Slack. Thanks to everyone who participated in the discussion threads! :-)

Conversion to boolean

Use (and value #t) to convert a value to its boolean equivalent.

Entering a module in the Racket REPL

#lang racket/base
(require (for-syntax racket/base
syntax/parse)
racket/stxparam)
;; (bind x-id e-expr)
;; Bind x-id to some string in e-expr
;; Expands to a expression that constructs a hash
;; table storing e-expr in a field
#lang racket/base
(require (for-syntax racket/base)
syntax/parse/define)
(let ()
(define-syntax-parse-rule (define-sum S)
(define (S n)
(if (= n 0) 0 (+ n (S (- n 1))))))
@shhyou
shhyou / solver.rkt
Created July 20, 2021 13:41
A tiny example for launching the Z3 process and interact with S-expression in SMTLIB syntax
#lang racket/base
(require racket/match)
(provide current-solver-path
call-with-solver
solve)
(define current-solver-path (make-parameter (find-executable-path "z3")))
import Control.Applicative
import Control.Monad
main = putStrLn "Hello, World!"
data Void
data Cont r a = Cont ((a -> r) -> r)
unCont (Cont m) = m
#lang racket/base
(require (for-syntax racket/base
racket/syntax
syntax/parse))
(define-syntax (define-constant stx)
(syntax-parse stx
[(_ name:id
(~optional (~and #:evaluate evaluate-kw))
#lang pollen
◊(define lam "\\lambda")
$◊lam x . \, ◊mathit{function \, body}$
◊textnormal{◊textbf unapplied text command}
#lang pollen
◊(define lam "\\lambda")
$◊lam_k\\nabla g_k(x)$
#lang racket/base
(require racket/generator
racket/stream
racket/sequence)
(define (make-iter-gen xs ys)
(generator
()
(for ([x (in-list xs)])
@shhyou
shhyou / 0-env.rkt
Last active February 18, 2021 13:07
Compilation-time Environment
;; Exporting free identifier table operations that close over a global map
#lang racket/base
(require racket/list
syntax/id-table)
(provide env-ref env-has-id? env-add!)
(define id-table (make-free-id-table))