match-plus by Alexis King allows definition of functions which pattern-match their arguments
multi-id by Georges Dupéron allows giving the same identifier multiple roles (as an identifier macro, macro, type expander, match expander etc.) with a concise syntax
Possible features:
pattern matching
(def (list a (cons b c) d) '(1 (2 . 3) 4))
b ; => 2
Multiple binding forms in one go (requested by Greg: private e-mail):
(def id 42
(list a b c) (list 1 2 3)
(values in out) (tcp-connect "host" 3000))
Define case functions in several chunks:
With pattern-matching
(def+ (f '()) 0)
(def+ (f (cons x l)) {1+ (f l)})
Syntactic sugar haskell-style (requested by Robby):
"define"-transformers for attaching meta-information to definitions, like documentation, tests, contracts, types, etc
Give a single identifier multiple meanings (can leverage the multi-id package, requested by @jsmaniac)
(def+ id 42)
(def+ (id a b) (+ a b))
(def+ (id . rest) (append* . rest))
(def+ [stx (id a {~optional b})] #''foo)
(def+ [stx (id . x:id)] #''bar)
(def+ [type-expander (id A)] #'(Pairof A A))
(def+ [match-expander (id A)] #'(cons A A))
id ; => 42
(apply id '(1 2)) ; => '3
(apply id '((1 2) (3 4) (5 6 7))) ; => '(1 2 3 4 5 6 7)
(id 'a 'b) ; => 'foo
(id . xxx) ; => 'bar
(ann '(1 . 2) (id Number))
(match '(1 . 2)
[(id (? number?)) #t]
[_ #f]) ; => #t
Meta def & def* trans for more expansion (docs and test), static info (types), and def transformers (types), maybe syntax — transformer (can change define to define-syntax/etc) vs expander
(expands to a different syntax) — no ability to add args to functions! — See private e-mail
def+'s default is to use match (while def/def*'s default is to not use match)
(def+ (length '())
0)
(def+ (length (cons x xs))
{(length xs) + 1})
(def+ [contract length] (-> list? nat?))
(def+ [doc (length l)]
@{A most excellent function
for discovering the length of lists.})
(def+ [examples length]
{(length '()) \defs 0}
{(length '(a b c)) \defs 3})
(def+ [provide length])
Question by @jsmaniac: why not use match everywhere (i.e. in def/def* too)?
Syntactic sugar using =:
#lang remix
a b = (values 1 2)
c (d . e) = (values 3 (cons 4 5))
(let x y = (values 1 2)
z (t w) = (values 3 (cons 4 5))
in ;; optional, just for clarity
;; and disables use of `=` as a binding form after the `in`
(+ x y z t w)) ;; => 15
(def+ (f x y)
a = {x + y}
b = {x - y}
(* a b))
(f 4 6) ;; => -20
See also:
Possible features:
Give a single identifier multiple meanings (can leverage the multi-id package, requested by @jsmaniac)
=
: