Hacker News new | past | comments | ask | show | jobs | submit login
2D Racket Syntax (racket-lang.org)
88 points by veqq 53 days ago | hide | past | favorite | 15 comments



I love how this is upvoted to 33 and no comments. It's okay to just shut up and admire sometimes.

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 tried your example in DrRacket and it does not nest :(

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.


I wonder how hard it is to fix that it doesn't nest? Clearly, the algorithm pulls out a multi-line piece of code out of a boxed cell. The #2dcond is a piece of multi-line syntax. Maybe it's one-liner fix in the code. Unless something like the box recognition logic is confused by nested box material.


Sorry for the long delay, but I needed some time to think about it and to draw it.

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. :(


2D languages are an under-researched area of SW dev, IMHO, But I applaud this effort.

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.


> The effort required to keep the chart looking tidy quickly outweighs the effort writing a normal pure-code form.

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.


on that note: line numbers in Basic were a kludge, but they were a kludge which meant one could develop without even having a line, let alone a full screen, editor.


> The effort required to keep the chart looking tidy quickly outweighs the effort writing a normal pure-code form.

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.


Emacs’ org-mode has a pretty fantastic table prettifier and evaluator — it’s almost like a mini ASCII Excel


I like to consider myself a visual person, so this is something I'm very interested in, and have posted about a fair bit here (and elsewhere), so my apologies to folks seeing my thoughts below again.

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.


Edwards subtext had table centric representation of logic iirc.


ps: here's an oopsla paper https://www.subtext-lang.org/OOPSLA07.pdf (go to page 13 and further for screenshots)

from: https://www.subtext-lang.org/ (video here: https://vimeo.com/140738254)


Racket and Scheme are full of these things that appear a little unhinged but then you realize that it's all built from a few very simple principles.


I am listening to the MIT OCW lecture "Structure and Interpretation of Computer Programs" EDIT: which uses Scheme

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

https://news.ycombinator.com/item?id=36475852

https://news.ycombinator.com/item?id=40698906


obligatory mention of "analogue literals": http://web.archive.org/web/20110714020203/http://weegen.home...




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: