99cd please-lang-prototype
1010npm install
1111npm run build
12- echo ' { @runtime, context => :context.program.start_time}' | ./please --output-format=json
12+ echo ' @runtime { context => :context.program.start_time }' | ./please --output-format=json
1313```
1414
1515There are more example programs in [ ` ./examples ` ] ( ./examples ) .
@@ -45,7 +45,7 @@ data representation implied by the fact that a value is an atom (e.g. the atom
4545` 2 ` may be an integer in memory).
4646
4747Bare words not containing any
48- [ reserved character sequences] ( ./src/language/parsing/atom.ts#L33-L55 ) are
48+ [ reserved character sequences] ( ./src/language/parsing/atom.ts#L34-L57 ) are
4949atoms:
5050
5151```
@@ -178,13 +178,18 @@ expressions_. Most of the interesting stuff that Please does involves evaluating
178178keyword expressions.
179179
180180Under the hood, keyword expressions are modeled as objects. For example, ` :foo `
181- desugars to ` { @lookup, key: foo } ` . All such expressions have a key ` 0 `
182- referring to a value that is an ` @ ` -prefixed atom (the keyword). Keywords
183- include ` @apply ` , ` @check ` , ` @function ` , ` @if ` , ` @index ` , ` @lookup ` , ` @panic ` ,
184- and ` @runtime ` .
181+ desugars to ` { 0: "@lookup", 1: { key: foo } } ` . All such expressions have a
182+ property named ` 0 ` referring to a value that is an ` @ ` -prefixed atom (the
183+ keyword). Most keyword expressions also require a property named ` 1 ` to pass an
184+ argument to the expression. Keywords include ` @apply ` , ` @check ` , ` @function ` ,
185+ ` @if ` , ` @index ` , ` @lookup ` , ` @panic ` , and ` @runtime ` .
185186
186- Currently only ` @function ` , ` @lookup ` , ` @index ` , and ` @apply ` have syntax
187- sugars.
187+ In addition to the specific syntax sugars shown above, any keyword expression
188+ can be written using a generalized sugar:
189+
190+ ```
191+ @keyword { … } // desugars to `{ 0: "@keyword", 1: { … } }`
192+ ```
188193
189194### Semantics
190195
@@ -210,7 +215,7 @@ function from other programming languages, except there can be any number of
210215` @runtime ` expressions in a given program. Here's an example:
211216
212217```
213- { @runtime, context => :context.program.start_time}
218+ @runtime { context => :context.program.start_time }
214219```
215220
216221Unsurprisingly, this program outputs the current time when run.
@@ -249,7 +254,7 @@ Take this example `plz` program:
249254{
250255 language: Please
251256 message: :atom.prepend("Welcome to ")(:language)
252- now: { @runtime, context => :context.program.start_time}
257+ now: @runtime { context => :context.program.start_time }
253258}
254259```
255260
@@ -259,40 +264,58 @@ It desugars to the following `plo` program:
259264{
260265 language: Please
261266 message: {
262- 0: @apply
263- function: {
264- 0: @apply
267+ 0: "@apply"
268+ 1: {
265269 function: {
266- 0: @index
267- object: {
268- 0: @lookup
269- key: atom
270+ 0: "@apply"
271+ 1: {
272+ function: {
273+ 0: "@index"
274+ 1: {
275+ object: {
276+ 0: "@lookup"
277+ 1: {
278+ key: atom
279+ }
280+ }
281+ query: {
282+ 0: prepend
283+ }
284+ }
285+ }
286+ argument: "Welcome to "
270287 }
271- query: {
272- 0: prepend
288+ }
289+ argument: {
290+ 0: "@lookup"
291+ 1: {
292+ key: language
273293 }
274294 }
275- argument: "Welcome to "
276- }
277- argument: {
278- 0: @lookup
279- key: language
280295 }
281296 }
282297 now: {
283- 0: @runtime
298+ 0: " @runtime"
284299 1: {
285- 0: @function
286- parameter: context
287- body: {
288- 0: @index
289- object: {
290- 0: @lookup
291- key: context
292- }
293- query: {
294- 0: program
295- 1: start_time
300+ 0: {
301+ 0: "@function"
302+ 1: {
303+ parameter: context
304+ body: {
305+ 0: "@index"
306+ 1: {
307+ object: {
308+ 0: "@lookup"
309+ 1: {
310+ key: context
311+ }
312+ }
313+ query: {
314+ 0: program
315+ 1: start_time
316+ }
317+ }
318+ }
296319 }
297320 }
298321 }
@@ -307,19 +330,27 @@ Which in turn compiles to the following `plt` program:
307330 language: Please
308331 message: "Welcome to Please"
309332 now: {
310- 0: @runtime
311- function: {
312- 0: @function
313- parameter: context
314- body: {
315- 0: @index
316- object: {
317- 0: @lookup
318- key: context
319- }
320- query: {
321- 0: program
322- 1: start_time
333+ 0: "@runtime"
334+ 1: {
335+ function: {
336+ 0: "@function"
337+ 1: {
338+ parameter: context
339+ body: {
340+ 0: "@index"
341+ 1: {
342+ object: {
343+ 0: "@lookup"
344+ 1: {
345+ key: context
346+ }
347+ }
348+ query: {
349+ 0: program
350+ 1: start_time
351+ }
352+ }
353+ }
323354 }
324355 }
325356 }
@@ -333,7 +364,7 @@ Which produces the following runtime output:
333364{
334365 language: Please
335366 message: "Welcome to Please"
336- now: "2025-02-14T18:45:14.168Z "
367+ now: "2025-05-13T22:47:50.802Z "
337368}
338369```
339370
0 commit comments