Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active July 10, 2017 20:53
Show Gist options
  • Save creationix/ab9e99102d2a40c0f82c to your computer and use it in GitHub Desktop.
Save creationix/ab9e99102d2a40c0f82c to your computer and use it in GitHub Desktop.

Revisions

  1. creationix revised this gist Jun 5, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions idea.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Lisp syntax, but using whitespace to remove most parentheses.

    - Every line is wrapped as a list unless it's prefixed with an `@` symbol.
    - Every line is wrapped as a list. Use `do` to get just the value.
    - Empty lines are ignored.
    - Indented lines are concatenated to their parent lists.
    - A pipe (`|`) acts like indentation without wasting whitespace.
    @@ -33,6 +33,6 @@ A recursive Fib function could look like:
    ```lisp
    let fib | λ [n]
    if (n ≤ 2)
    @ 1
    @ ([fib (n - 1)] + [fib (n - 2)])
    do 1
    do ([fib (n - 1)] + [fib (n - 2)])
    ```
  2. creationix revised this gist Jun 4, 2015. 2 changed files with 18 additions and 18 deletions.
    6 changes: 3 additions & 3 deletions idea.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Lisp syntax, but using whitespace to remove most parentheses.
    - Every line is wrapped as a list unless it's prefixed with an `@` symbol.
    - Empty lines are ignored.
    - Indented lines are concatenated to their parent lists.
    - An inline arrow acts like indentation without wasting whitespace.
    - A pipe (`|`) acts like indentation without wasting whitespace.
    - Use square brackets for inline lists.
    - Use round parentheses for infix notation (first two items are swapped)

    @@ -24,14 +24,14 @@ In my modified syntax, this would look like:
    ```lisp
    print "Hello World"
    for [x 10] for [y 10]
    for [x 10] | for [y 10]
    printf "%d + %d = %d" x y (x + y)
    ```

    A recursive Fib function could look like:

    ```lisp
    let fib λ [n]
    let fib | λ [n]
    if (n ≤ 2)
    @ 1
    @ ([fib (n - 1)] + [fib (n - 2)])
    30 changes: 15 additions & 15 deletions syntax.lisp
    Original file line number Diff line number Diff line change
    @@ -10,13 +10,13 @@ for [i 10]
    for [name names]
    print name

    ; Nested loops using syntax
    ; means to assume everything afterwards is indented
    for [y 10] for [x 10]
    ; Nested loops using | syntax
    ; | means to assume everything afterwards is indented
    for [y 10] | for [x 10]
    print x y

    ; Lines starting with @ are not wrapped as lists
    let fib λ [n]
    let fib | λ [n]
    if (n ≤ 2) 1
    @ ([fib (n - 1)] + [fib (n - 2)])

    @@ -46,7 +46,7 @@ let height 30
    let size (width × height)

    ; Cells letine the maze
    let cells map [i size] table
    let cells | map [i size] | table
    ; parent is initially null
    @ parent nil
    ; right and down walls are initially filled
    @@ -58,25 +58,25 @@ let ww (width - 1)
    let hh (height - 1)

    ; Create a list of actions to perform in shuffled order
    let sequence shuffle concat
    map [i size] if ((i % width) < ww) table
    let sequence | shuffle | concat
    map [i size] | if ((i % width) < ww) | table
    @ cell (cells get i)
    @ direction "right"
    map [i size] if ((i ÷ width) < hh) table
    map [i size] | if ((i ÷ width) < hh) | table
    @ cell (cells get i)
    @ direction "down"

    ; Find the root of a set cell -> cell
    let find-root λ [cell] if cell.parent
    let find-root | λ [cell] | if cell.parent
    find-root cell.parent
    @ cell

    for [item sequence]
    let direction item.direction
    let root find-root (cells . i)
    let horizontal ? (item . 0)
    let root | find-root (cells . i)
    let horizontal | ? (item . 0)

    let other find-root (cells . (i + [? (item . 0) 1 width)))
    let other | find-root (cells . (i + [? (item . 0) 1 width)))
    (if (≠ (. root 0) (. other 0))
    (. root 1 other)
    (. (. walls i) (? (. item 0) 0 1) false)
    @@ -85,9 +85,9 @@ for [item sequence]

    let w (width × 2)
    let h (height × 2)
    join "\n" map [y (h + 1)]
    join "" map [x (w + 1)]
    ¿ " " "██" or
    join "\n" | map [y (h + 1)]
    join "" | map [x (w + 1)]
    ¿ " " "██" | or
    ; Four outer edges are always true
    = x 0
    = y 0
  3. creationix revised this gist Jun 4, 2015. 2 changed files with 17 additions and 17 deletions.
    2 changes: 1 addition & 1 deletion idea.md
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ for [x 10] → for [y 10]
    A recursive Fib function could look like:

    ```lisp
    def fib → λ [n]
    let fib → λ [n]
    if (n ≤ 2)
    @ 1
    @ ([fib (n - 1)] + [fib (n - 2)])
    32 changes: 16 additions & 16 deletions syntax.lisp
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ for [y 10] → for [x 10]
    print x y

    ; Lines starting with @ are not wrapped as lists
    def fib → λ [n]
    let fib → λ [n]
    if (n ≤ 2) 1
    @ ([fib (n - 1)] + [fib (n - 2)])

    @@ -41,24 +41,24 @@ set person "name" "Tim"
    ; ██ ██ ██
    ; ██████████████

    def width 30
    def height 30
    def size (width × height)
    let width 30
    let height 30
    let size (width × height)

    ; Cells define the maze
    def cells → map [i size] → table
    ; Cells letine the maze
    let cells → map [i size] → table
    ; parent is initially null
    @ parent nil
    ; right and down walls are initially filled
    @ right true
    @ down true

    ; Define the sequence of index and right/left
    def ww (width - 1)
    def hh (height - 1)
    let ww (width - 1)
    let hh (height - 1)

    ; Create a list of actions to perform in shuffled order
    def sequence → shuffle → concat
    let sequence → shuffle → concat
    map [i size] → if ((i % width) < ww) → table
    @ cell (cells get i)
    @ direction "right"
    @@ -67,24 +67,24 @@ def sequence → shuffle → concat
    @ direction "down"

    ; Find the root of a set cell -> cell
    def find-root → λ [cell] → if cell.parent
    let find-root → λ [cell] → if cell.parent
    find-root cell.parent
    @ cell

    for [item sequence]
    def direction item.direction
    def root → find-root (cells . i)
    def horizontal → ? (item . 0)
    let direction item.direction
    let root → find-root (cells . i)
    let horizontal → ? (item . 0)

    def other → find-root (cells . (i + [? (item . 0) 1 width)))
    let other → find-root (cells . (i + [? (item . 0) 1 width)))
    (if (≠ (. root 0) (. other 0))
    (. root 1 other)
    (. (. walls i) (? (. item 0) 0 1) false)
    )
    )

    def w (width × 2)
    def h (height × 2)
    let w (width × 2)
    let h (height × 2)
    join "\n"map [y (h + 1)]
    join ""map [x (w + 1)]
    ¿ " " "██"or
  4. creationix revised this gist Jun 4, 2015. 1 changed file with 30 additions and 30 deletions.
    60 changes: 30 additions & 30 deletions syntax.lisp
    Original file line number Diff line number Diff line change
    @@ -1,63 +1,63 @@
    -- Standard lisp style syntax, but each line is assumed to be wrapped in parens
    ; Standard lisp style syntax, but each line is assumed to be wrapped in parens
    print "Hello World"

    -- Loop 10 times with i changing from 0 to 9
    -- Indent means to continue parent list, but each line is own sub-list
    ; Loop 10 times with i changing from 0 to 9
    ; Indent means to continue parent list, but each line is own sub-list
    for [i 10]
    print i

    -- Loop over a list of names
    ; Loop over a list of names
    for [name names]
    print name

    -- Nested loops using → syntax
    -- → means to assume everything afterwards is indented
    ; Nested loops using → syntax
    ; → means to assume everything afterwards is indented
    for [y 10] → for [x 10]
    print x y

    -- Lines starting with @ are not wrapped as lists
    ; Lines starting with @ are not wrapped as lists
    def fib → λ [n]
    if (n ≤ 2) 1
    @ ([fib (n - 1)] + [fib (n - 2)])

    -- Object syntax
    ; Object syntax
    obj
    @ name "Tim"
    @ age 33

    -- Object set, get
    ; Object set, get
    get person "name"
    @ person.name
    set person "name" "Tim"

    -- Sample program: maze generator
    -- Sample output for 3x3 maze
    ; Sample program: maze generator
    ; Sample output for 3x3 maze

    -- ██████████████
    -- ██ ██ ██
    -- ██ ██████ ██
    -- ██ ██
    -- ██ ██ ██████
    -- ██ ██ ██
    -- ██████████████
    ; ██████████████
    ; ██ ██ ██
    ; ██ ██████ ██
    ; ██ ██
    ; ██ ██ ██████
    ; ██ ██ ██
    ; ██████████████

    def width 30
    def height 30
    def size (width × height)

    -- Cells define the maze
    ; Cells define the maze
    def cells → map [i size] → table
    -- parent is initially null
    ; parent is initially null
    @ parent nil
    -- right and down walls are initially filled
    ; right and down walls are initially filled
    @ right true
    @ down true

    -- Define the sequence of index and right/left
    ; Define the sequence of index and right/left
    def ww (width - 1)
    def hh (height - 1)

    -- Create a list of actions to perform in shuffled order
    ; Create a list of actions to perform in shuffled order
    def sequence → shuffle → concat
    map [i size] → if ((i % width) < ww) → table
    @ cell (cells get i)
    @@ -66,7 +66,7 @@ def sequence → shuffle → concat
    @ cell (cells get i)
    @ direction "down"

    -- Find the root of a set cell -> cell
    ; Find the root of a set cell -> cell
    def find-root → λ [cell] → if cell.parent
    find-root cell.parent
    @ cell
    @@ -88,23 +88,23 @@ def h (height × 2)
    join "\n"map [y (h + 1)]
    join ""map [x (w + 1)]
    ¿ " " "██"or
    -- Four outer edges are always true
    ; Four outer edges are always true
    = x 0
    = y 0
    = x w
    = y h
    -- Inner cells are more complicated
    ; Inner cells are more complicated
    ? (y % 2)
    ? (x % 2)
    -- cell middle
    ; cell middle
    false
    -- cell right
    ; cell right
    (. (. walls (+ (÷ (- x 1) 2) (× (÷ y 2) width))) 0)
    )
    (? (% x 2)
    -- cell down
    ; cell down
    (. (. walls (+ (÷ x 2) (× (÷ (- y 1) 2) width))) 1)
    -- cell corner
    ; cell corner
    true
    )
    )
  5. creationix renamed this gist Jun 4, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. creationix revised this gist Jun 4, 2015. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion idea.md
    Original file line number Diff line number Diff line change
    @@ -19,11 +19,20 @@ For example, take the following lisp style program:
    )
    ```

    In my modified syntax, this would look like
    In my modified syntax, this would look like:

    ```lisp
    print "Hello World"
    for [x 10] → for [y 10]
    printf "%d + %d = %d" x y (x + y)
    ```

    A recursive Fib function could look like:

    ```lisp
    def fib → λ [n]
    if (n ≤ 2)
    @ 1
    @ ([fib (n - 1)] + [fib (n - 2)])
    ```
  7. creationix revised this gist Jun 3, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion idea.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Lisp syntax, but using whitespace to remove most parenthesis.
    Lisp syntax, but using whitespace to remove most parentheses.

    - Every line is wrapped as a list unless it's prefixed with an `@` symbol.
    - Empty lines are ignored.
  8. creationix revised this gist Jun 3, 2015. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions idea.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    Lisp syntax, but using whitespace to remove most parenthesis.

    - Every line is wrapped as a list unless it's prefixed with an `@` symbol.
    - Empty lines are ignored.
    - Indented lines are concatenated to their parent lists.
    - An inline arrow acts like indentation without wasting whitespace.
    - Use square brackets for inline lists.
    - Use round parentheses for infix notation (first two items are swapped)

    For example, take the following lisp style program:

    ```lisp
    (print "Hello World")
    (for (x 10)
    (for (y 10)
    (printf "%d + %d = %d" x y (+ x y))
    )
    )
    ```

    In my modified syntax, this would look like

    ```lisp
    print "Hello World"
    for [x 10] → for [y 10]
    printf "%d + %d = %d" x y (x + y)
    ```
  9. creationix revised this gist Jun 3, 2015. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions syntax.jkl
    Original file line number Diff line number Diff line change
    @@ -22,10 +22,13 @@ def fib → λ [n]

    -- Object syntax
    obj
    name "Tim"
    age 33
    @ name "Tim"
    @ age 33

    -- Object set, get
    get person "name"
    @ person.name
    set person "name" "Tim"

    -- Sample program: maze generator
    -- Sample output for 3x3 maze
  10. creationix revised this gist Jun 3, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion syntax.jkl
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ print "Hello World"
    for [i 10]
    print i

    -- Loop over the list
    -- Loop over a list of names
    for [name names]
    print name

  11. creationix created this gist Jun 3, 2015.
    110 changes: 110 additions & 0 deletions syntax.jkl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,110 @@
    -- Standard lisp style syntax, but each line is assumed to be wrapped in parens
    print "Hello World"

    -- Loop 10 times with i changing from 0 to 9
    -- Indent means to continue parent list, but each line is own sub-list
    for [i 10]
    print i

    -- Loop over the list
    for [name names]
    print name

    -- Nested loops using → syntax
    -- → means to assume everything afterwards is indented
    for [y 10] → for [x 10]
    print x y

    -- Lines starting with @ are not wrapped as lists
    def fib → λ [n]
    if (n ≤ 2) 1
    @ ([fib (n - 1)] + [fib (n - 2)])

    -- Object syntax
    obj
    name "Tim"
    age 33

    -- Object set, get

    -- Sample program: maze generator
    -- Sample output for 3x3 maze

    -- ██████████████
    -- ██ ██ ██
    -- ██ ██████ ██
    -- ██ ██
    -- ██ ██ ██████
    -- ██ ██ ██
    -- ██████████████

    def width 30
    def height 30
    def size (width × height)

    -- Cells define the maze
    def cells → map [i size] → table
    -- parent is initially null
    @ parent nil
    -- right and down walls are initially filled
    @ right true
    @ down true

    -- Define the sequence of index and right/left
    def ww (width - 1)
    def hh (height - 1)

    -- Create a list of actions to perform in shuffled order
    def sequence → shuffle → concat
    map [i size] → if ((i % width) < ww) → table
    @ cell (cells get i)
    @ direction "right"
    map [i size] → if ((i ÷ width) < hh) → table
    @ cell (cells get i)
    @ direction "down"

    -- Find the root of a set cell -> cell
    def find-root → λ [cell] → if cell.parent
    find-root cell.parent
    @ cell

    for [item sequence]
    def direction item.direction
    def root → find-root (cells . i)
    def horizontal → ? (item . 0)

    def other → find-root (cells . (i + [? (item . 0) 1 width)))
    (if (≠ (. root 0) (. other 0))
    (. root 1 other)
    (. (. walls i) (? (. item 0) 0 1) false)
    )
    )

    def w (width × 2)
    def h (height × 2)
    join "\n" → map [y (h + 1)]
    join "" → map [x (w + 1)]
    ¿ " " "██" → or
    -- Four outer edges are always true
    = x 0
    = y 0
    = x w
    = y h
    -- Inner cells are more complicated
    ? (y % 2)
    ? (x % 2)
    -- cell middle
    false
    -- cell right
    (. (. walls (+ (÷ (- x 1) 2) (× (÷ y 2) width))) 0)
    )
    (? (% x 2)
    -- cell down
    (. (. walls (+ (÷ x 2) (× (÷ (- y 1) 2) width))) 1)
    -- cell corner
    true
    )
    )
    ))
    ))
    ))