-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.rhm
515 lines (471 loc) · 14.9 KB
/
index.rhm
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#lang rhombus
import:
rhombus/collect
lib("rhombus/scribble/private/rhombus-spacer.rhm") open
"private/html.rhm" open
"private/slide_show.rhm" open
"private/rhombus.rhm" open
meta_label:
rhombus open:
except str // workaround spacer limitation, for now
only_meta 0:
rhombus/meta open
def name_font = "'Cooper-Hewitt'"
def text_font = "'Charter-Racket', serif"
def text_size = "14pt"
span.def namefont:
~font_family: name_font
~font_size: "40pt"
span.def prose:
~font_family: text_font
~font_size: text_size
span.def small_prose:
~font_family: text_font
~font_size: "12pt"
div.def prose_column:
~font_family: text_font
~font_size: text_size
~max_width: "40em"
~margin: "auto"
div.def slideshow_container:«»
a.def next:«»
a.def prev:«»
div.def numbertext:«»
div.def mySlides:«»
span.def dot:«»
div.def text:«»
span.def tt:
~font_family: "'Fira-Mono', monospace"
div.def column:
~margin_left: "3em"
~margin_right: "3em"
~display: "flex"
~flex_direction: "column"
~align_items: "left"
~max_width: "20em"
div.def row:
~display: "flex"
~flex_direction: "row"
~align_items: "top"
a.def button:
~padding: "10px"
~padding_top: "13px"
~border_radius: "3px"
~background_color: "#3e5ba9"
~color: "white"
~font_family: name_font
~font_size: "14pt"
~text_decoration: "none"
~transform: "skew(-0.3rad)"
~align_self: "start"
~white_space: "nowrap"
div.def tabular:
~display: "grid"
~grid_template_columns: "repeat(2, auto)"
~max_width: "22em"
fun code(stx :: Syntax):
stx.to_source_string(~keep_prefix: #true, ~keep_suffix: #true)
def examples:
[
(@rhombusblock_etc():
// simple syntax for everyday tasks
class Rect(left, top, right, bottom)
fun area(r):
let w = r.right - r.left
let h = r.bottom - r.top
w*h
area(Rect(0, 0, 10, 5))
// ⇒ 50
),
(@rhombusblock_etc():
// pattern matching on objects, lists, and maps
class Rect(left, top, right, bottom)
fun rect_like_to_rect(v):
match v
| Rect(_, _, _, _): v
| {"LT": [l, t], "RB": [r, b]}: Rect(l, t, r, b)
| {"TL": [t, l], "BR": [b, r]}: Rect(l, t, r, b)
rect_like_to_rect({"LT": [0, 2], "RB": [10, 5]})
// ⇒ Rect(0, 2, 10, 5)
rect_like_to_rect({"TL": [0, 2], "BR": [10, 5]})
// ⇒ Rect(2, 0, 5, 10)
),
(@rhombusblock_etc():
// `:` for nesting, `|` for alternatives,
// `::` for type-like checked annotations
fun repeat(str :: String, n :: NonnegInt) :: List:
if n == 0
| []
| [str] ++ repeat(str, n-1)
repeat("hello", 3)
// ⇒ ["hello", "hello", "hello"]
repeat(3, "hello")
// ⇒ error: 3 is not a String
),
(@rhombusblock_etc():
// ellipses to create and use repetitions
fun all_same([str0, str, ...]):
all(str0 == str, ...)
all_same(["hello", "hello", "hello"])
// ⇒ #true
all_same(["hello", "goodbye", "hello"])
// ⇒ #false
),
(@rhombusblock_etc():
// pattern matching in all binding positions
class Posn(x, y)
fun flip_all([Posn(x, y), ...]):
[Posn(y, x), ...]
flip_all([Posn(1, 2), Posn(3, 4)])
// ⇒ [Posn(2, 1), Posn(4, 3)]
flip_all([Posn(5, 6)])
// ⇒ [Posn(6, 5)]
),
(@rhombusblock_etc():
// efficient functional data structures
class Tree(val, children :: List.of(Tree)):
method flatten(): // O(N lg N) for N `val`s
for fold(lst = [val]) (child in children):
// because append with `++` is O(lg N)
lst ++ child.flatten()
Tree(1, [Tree(2, [Tree(4, [])]),
Tree(3, [Tree(5, [])])])
.flatten() // ⇒ [1, 2, 4, 3, 5]
),
(@rhombusblock_etc():
// syntax as data
fun interp(e):
match e
| '$(n :: Number)': n.unwrap()
| '$lhs ... + $rhs ...':
interp('$lhs ...') + interp('$rhs ...')
| '$lhs ... * $rhs ...':
interp('$lhs ...') * interp('$rhs ...')
interp('1 + 3 * 4') // '' quotes syntax, not a string
// ⇒ 13
),
(@rhombusblock_etc():
// macros
expr.macro '$left but_first $right':
'block:
$right
$left'
println("there") but_first print("hi ")
// ⇒ prints "hi there"
),
(@rhombusblock_etc():
// macros for binding positions and much more
class Rect(left, top, right, bottom)
bind.macro 'OriginRect($right, $bottom)':
'Rect(0, 0, $right, $bottom)'
fun area(r):
match r
| OriginRect(r, b): r*b
| Rect(l, t, r, b): (r-l)*(b-t)
area(Rect(0, 0, 10, 5))
// ⇒ 50
)
]
def usual_head:
@List(
meta:
~content: "text/html; charset=utf-8"
~http_equiv: "content-type"
style:
@str|{@import url("https://docs.racket-lang.org/manual-fonts.css");}|
style:
slide_show_style
style:
all_styles()
script:
slide_show_script
)
fun write(dest, doc):
println("writing " +& dest)
Port.Output.using ~file dest:
~exists: #'truncate
println("<!DOCTYPE html>")
write_html(doc)
fun rhombus_header(title):
div:
~style: (css:
~display: "flex"
~flex_direction: "row"
~align_items: "center")
img:
~src: "rhombus-logo.svg"
~width: 470 / 4.0
~height: 329 / 4.0
~style: (css:
~vertical_align: "middle")
span:
~style: (css:
~margin_top: "20px"
~vertical_align: "middle"
~padding_left: "10px")
namefont:
title
write(
"index.html",
html:
head:
usual_head
title:
@str{The Rhombus Programming Language}
body:
div:
~style: (css:
~display: "flex"
~flex_direction: "column"
~align_items: "center"
~padding_top: "10px")
rhombus_header("Rhombus")
div:
~style: (css: ~padding: "20px")
prose:
@str{Rhombus is a general-purpose programming language that is easy to use and}
" "
a:
~href: "goal.html"
"uniquely customizable"
@str{.}
div:
~style: (css:
~display: "flex"
~flex_direction: "row")
prev:
~onclick: "plusSlides(-1)"
"\u276e"
slideshow_container:
for List (example in examples):
mySlides:
pre:
typeset(example)
next:
~onclick: "plusSlides(1)"
"\u276f"
div:
~style: (css: ~text_align: "center")
for List (example in examples,
i in 1..):
dot: ~onclick: "currentSlide(" +& i +& ")"
row:
~style: (css: ~padding_top: "3em")
column:
div:
~style: (css:
~display: "flex"
~flex_direction: "row"
~align_items: "center")
img:
~src: "racket-logo.svg"
~width: 50
~height: 50
~style: (css: ~padding_right: "0.5em")
div:
prose:
"Built on "
a:
~href: "http://racket-lang.org/"
"Racket"
div:
small_prose:
"... which means that Rhombus is compiled to machine code on-the-fly, "
"benefits from a mature tool chain and package system, "
"and has many practical libraries within reach."
div:
~style: (css: ~padding_top: "0.5em")
small_prose:
"Why a new language? See "
a:
~href: "goal.html"
"Rhombus Goals"
"."
tabular:
~style: (css:
~gap: "1em"
~justify_items: "start")
button:
~href: "download.html"
@str{Download}
small_prose:
"Rhombus is ready for "
b:
~style: (css:
~white_space: "nowrap")
"early adopters"
"."
button:
~href: "https://docs.racket-lang.org/rhombus/index.html"
@str{Documentation}
div:
~style: (css: ~margin: "0.25em 0 0 0")
small_prose:
"Includes a "
a:
~href: "https://docs.racket-lang.org/rhombus/Quick_Start.html"
"Quick Start"
"."
button:
~href: "https://github.com/racket/rhombus"
@str{Work in Progress}
small_prose:
"Complete and stable enough to be useful, but not all done."
)
write(
"download.html",
html:
head:
usual_head
title:
@str{Getting Rhombus}
body:
div:
~style: (css:
~display: "flex"
~flex_direction: "column"
~align_items: "center"
~padding_top: "10px")
rhombus_header("Download")
div:
~style: (css:
~max_width: "600px"
~margin: "2em 0 0 0")
prose:
@str{Two options for installing Rhombus:}
p:
~style: (css:
~margin: "2em 0 0 0")
row:
button:
~href: "https://users.cs.utah.edu/plt/rhombus-snapshots/"
@str{Install a snapshot Racket with Rhombus included}
p:
small_prose:
"This is a good option if you don’t already have Racket"
"—at least, in the short term and for common machine types."
" The snapshot-specific package catalog will eventually expire,"
" unlike a regular Racket distribution."
p:
~style: (css:
~margin: "2em 0 0 0")
row:
button:
~href: "https://download.racket-lang.org/"
@str{Install a regular Racket distribution}
p:
prose:
"Then, install the "
b:
tt: "rhombus"
" package in one of these ways:"
ul:
li:
p:
prose:
"In DrRacket, choose “Install package...” from the “File” menu"
p:
prose:
"Enter "
b:
tt:
"rhombus"
" as the package to install."
li:
p:
prose:
"On the command line, run "
p:
~style: (css:
~margin_left: "2em")
prose:
b:
tt:
"raco pkg install rhombus"
p:
small_prose:
"This is a good option if you already have Racket,"
" need more install options, or need longer-term support."
)
write(
"goal.html",
html:
head:
usual_head
title:
@str{Rhombus Goals}
body:
div:
~style: (css:
~display: "flex"
~flex_direction: "column"
~align_items: "center"
~padding_top: "10px")
rhombus_header("Rhombus Goals")
prose_column:
p:
@str{Modern programming languages reflect a consensus on basic
constructs, including functional abstraction,
lexically scoped variables, closures, objects, and pattern matching. Why, then,
are we creating yet another general-purpose programming language?}
p:
@str{Beyond the basics, there are still more good ideas for programming constructs
than can fit in any one language specification. Furthermore, specific domains benefit
from language support that is tailored to the domain.}
" "
i: "Language extensibility"
" "
@str{helps to balance the competing goals of a manageable language size versus fit-to-purpose
for a wide range of tasks.}
p:
@str{Many newer languages include a}
" "
i: "macro system"
" "
@str{to enable extensibility, but
few would argue that the new batch of macro systems have achieved the
expressiveness and fluidity of macros as they exist within the
Lisp tradition, which includes}
" "
a:
~href: "https://racket-lang.org/"
"Racket"
@str{. At the same time, that expressiveness has been difficult to detangle
from Lisp’s minimalistic, parenthesis-oriented notation.}
p:
@str{Rhombus is designed to be}
ul:
li:
p:
@str{approachable and easy to use for everyday purposes (that do not need macros),
which in part means a conventional syntax; and}
li:
p:
@str{as extensible as Racket, while making Racket's state-of-the-art facilities
more consistent and accessible to a wide audience.}
p:
~style: (css: ~margin_top: "2em")
@str{More resources:}
ul:
li:
a:
~href: "https://www.youtube.com/watch?v=hkiy1rmKA48"
"Recorded talk"
" from OOPSLA’23"
li:
a:
~href: "https://doi.org/10.1145/3622818"
"Rhombus: A New Spin on Macros without All the Parentheses"
li:
a:
~href: "https://dl.acm.org/doi/10.1145/3127323"
"A Programmable Programming Language"
)
fun install(path :: Path):
let to = path.name()
println("copying " +& to)
filesystem.copy(path, to, ~exists_ok: #true)
install(collect.file_path(~collect: "icons",
~file: "racket-logo.svg"))
install(collect.file_path(~collect: "rhombus-icons",
~file: "rhombus-logo.svg"))