2D Racket Syntax
docs.racket-lang.org
docs.racket-lang.org
Good for you for getting that, HackerNews. Except for me.
Why isn't the example like this, to show that the notation nests? Or else state clearly that it does not:
(define (same? a b)
#2dcond
╔═════════════╦══════════════════════════════════════════════════════╦═════════════╗
║ ║ (pair? a) ║ (number? a) ║
╠═════════════╬══════════════════════════════════════════════════════╬═════════════╣
║ ║ #2dcond ║ ║
║ ║ ╔════════════════════════╦════════════════════════╗ ║ ║
║ (pair? b) ║ ║ ║ (same (car a) (car b)) ║ ║ #f ║
║ ║ ╠════════════════════════╬════════════════════════╣ ║ ║
║ ║ ║ (same (cdr a) (cdr b)) ║ #t ║ ║ ║
║ ║ ╚════════════════════════╩════════════════════════╝ ║ ║
╠═════════════╬══════════════════════════════════════════════════════╬═════════════╣
║ (number? b) ║ #f ║ (= a b) ║
╚═════════════╩══════════════════════════════════════════════════════╩═════════════╝)
Also, the empty cell in the upper left of #2dcond could be used for specifying the default value, overriding the #f default default.I think it's possible, but I'm not sure. The reader in #2dcond is already isolating the cell, for example in this monstousity:
#lang 2d racket
(require 2d/cond)
(define (same? a b)
#2dcond
╔═════════════╦═══════════════════════╦═════════════╗
║ ║ (pair? a) ║ (number? a) ║
╠═════════════╬═══════════════════════╬═════════════╣
║ (pair? b) ║ " .║ 333 ║
║ ║. " ║ ║
╠═════════════╬═══════════════════════╬═════════════╣
║ (number? b) ║ 444 ║ (= a b) ║
╚═════════════╩═══════════════════════╩═════════════╝)
(same? '(1) '(2)) ;==> " . \n . "
(same? 5 '(2)) ;==> 333
There is a string that start in the fist line of the central cell and ends in the second line of that cell. The string does not include the 333 that is "between" the two double quotes, but it includes some fake spaces (?!). You can even replace the 333 with "333" and each string only get characters inside their own cell (and fake spaces).About the default value, I prefer the empty cell for clarity. The default is to raise an error. In some expressions in Racket the dafault is (void) and in other to raise an error. Both camps have strong opinions. I think the comunity is moving slowly to error, but old stuff have to keep the old behavior for backward compatibility.
The problem are free floating cells. (I don't know if they have a technical name.)
For example
#lang 2d racket
(require 2d/cond)
(define (myfun a b c d e f)
#2dcond
╔═══╦═══╦═══════╦═══╗
║ ║ a ║ b ║ c ║
╠═══╬═══╩═══════╩═══╣
║ d ║ 0 ║
╠═══╣ ╔═══════╗ ║
║ e ║ ║ 1 ║ ║
╠═══╣ ╚═══════╝ ║
║ f ║ ║
╚═══╩═══════════════╝)
(myfun #true #f #f #true #f #f) ;==> 0
(myfun #f #true #f #f #true #f) ;==> 1
In a variant with " " to make a sring, you get #lang 2d racket
(require 2d/cond)
(define (myfun a b c d e f)
#2dcond
╔═══╦═══╦═══════╦═══╗
║ ║ a ║ b ║ c ║
╠═══╬═══╩═══════╩═══╣
║ d ║ " ║
╠═══╣ ╔═══════╗ ║
║ e ║ ║ 1 ║ ║
╠═══╣ ╚═══════╝ ║
║ f ║ " ║
╚═══╩═══════════════╝)
(myfun #true #f #f #true #f #f) ;==> " \n \n \n \n
(myfun #f #true #f #f #true #f) ;==> 1
Should the table parse first the folating cell in the middel or should the " " include the cell as part of the string.Now
#lang 2d racket
(require 2d/cond)
; res, it's an error
(define (myfun a b c d e f)
#2dcond
╔═══╦═══╦═══════╦═══╗
║ ║ a ║ b ║ c ║
╠═══╬═══╩═══════╩═══╣
║ d ║ #2dcond ║
╠═══╣ ╔═══════╗ ║
║ e ║ ║ 1 ║ ║
╠═══╣ ╚═══════╝ ║
║ f ║ ║
╚═══╩═══════════════╝)
(myfun #true #f #f #true #f #f) ;==> ???
(myfun #f #true #f #f #true #f) ;==> ???
This is an error, but imagine that the middel cell has the correct shape. I like the idea of nesting #2dcond but it looks difficult to make a consistet rule when there are floating cells. :(On the one hand, they can significantly reduce the cognitive effort expressing and understanding code with complex relationships, OTOH they're a bit of a nightmare to actually use, especially the ones that use some form of ASCII art.
I wrote a parser for a simple petri net flow diagram that used ASCII art that constructed the state machine between function calls. It worked well until I actually tried to do anything serious with it. The effort required to keep the chart looking tidy quickly outweighs the effort writing a normal pure-code form.
IMO, a more "Pythonic", indentation-based diagram may be better but I think you're restricted then in the types of problems you can express.
As I say, this all needs more research.
from: https://www.subtext-lang.org/ (video here: https://vimeo.com/140738254)
Well, haven't folks been writing/dreaming about this since Herman Hesse's _The Glass Bead Game_? (originally published as Magister Ludi)
The big problem is that there doesn't seem to be an agreed-upon answer for the question:
>What does an algorithm look like?
and the tools which explore this tend to get bounded complexity-wise by screen size and attempts at escaping that complexity either lose expressiveness (presumably we are trying to escape from a "wall of text" but calling modules/functions as text even if it's wrapped up in a pretty box/connected with lines doesn't really do that and if one sticks to one's guns and just connects things in a node editor, well, there are sites for collecting such (but I'll spare you the link).
If folks have other tools in this space to suggest, I'd be glad to try them.
In 2007 I've been learning Java and Python concurrently, and made the following observation: some languages just absolutely suck without proper tooling, while others are pleasant to use even if all you have is MS Notepad. I'm not sure if there's a significant correlation to productivity, but the barrier to entry can definitely be much higher if your IDE can't hold your hand.
Github's markdown tables allow an intermediate form: one can edit tabular source untidily while editing (although it still always renders tidily in a markdown viewer), and then, before committing, run a pretty printer that restores a nice tidy tabular look even in the ascii source.
https://ocw.mit.edu/courses/6-001-structure-and-interpretati...
and reading the matching text:
https://web.mit.edu/6.001/6.037/sicp.pdf
and it's been fascinating seeing each thing get built up from first principles.
Previous discussions here:
https://news.ycombinator.com/item?id=24428907