When is language-oriented programming valuable?
When you want to become rich enough to donate a building to your alma mater.
When you want to reduce the notation.
1 | #rx"^fo+(bar)*$"
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #lang scribble/manual @(require (for-label json)) @title{jsonic: because JSON is boring} @author{Roxy Lexington} @defmodulelang[jsonic] @section{Introduction} This is a domain-specific language that relies on the @racketmodname[json] library. In particular, the @racket[jsexpr->string] function. If we start with this: @verbatim|{ #lang jsonic [ @$ 'null $@, @$ (* 6 7) $@, @$ (= 2 (+ 1 1)) $@ ] }| We'll end up with this: @verbatim{ [ null, 42, true ] } |
1 2 3 | #lang pollen My DSL ◊link["https://pollenpub.com"]{Pollen} is a language for making online books. And never again typing angle brackets. |
When you want enlarge the notation.
1 2 3 | #lang pollen/markdown I am **so** excited to be student #◊(* 6 7) at [Racket School]("https://school.racket-lang.org"). |
1 2 3 4 | #lang brag bf-program : (bf-op | bf-loop)* bf-op : ">" | "<" | "+" | "-" | "." | "," bf-loop : "[" (bf-op | bf-loop)* "]" |
See also: Unicode prep language
When the program is largely configurational.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #lang info (define collection "jsonic") (define version "1.0") (define scribblings '(("scribblings/jsonic.scrbl"))) (define test-omit-paths '("jsonic-test.rkt")) (define deps '("base" "beautiful-racket-lib" "brag" "draw-lib" "gui-lib" "br-parser-tools-lib" "rackunit-lib" "syntax-color-lib")) (define build-deps '("scribble-lib")) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #lang riposte $productId := 41966 $qty := 5 $campaignId := 1 $payload := { "product_id": $productId, "campaign_id": $campaignId, "qty": $qty } POST $payload cart/{uuid}/items responds with 200 $itemId := /items/0/cart_item_id GET cart responds with 200 |
When you want to create notation usable by nonprogrammers (or lazy programmers).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #lang txtadv-demo ===VERBS=== north, n "go north" south, s "go south" get _, grab _, take _ "take" ===THINGS=== ---cactus--- get "You win!" ===PLACES=== ---meadow--- "Welcome to the Cactus Game! You're standing in a meadow. There is a desert to the south." [] south desert ---desert--- "You're in a desert. There is nothing for miles around." [cactus] north meadow ===START=== meadow |
Hybrids are possible.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #lang lindenmayer racket ## axiom ## X ## rules ## X -> F[+X]F[-X]+X F -> FF ## variables ## n=7 θ=20 ============================================= (require lindenmayer/turtle) (provide (all-from-out lindenmayer/turtle) X) (define (X turtles variables) turtles) |
To computer scientists, notation is boring, because they study programs, not people. S-expressions often suffice.
In the real world, it’s important, because software is a tool, so the ergonomics matter. S-expressions often don’t suffice.