brownplt / code.pyret.org

Website for serving Pyret to folks.
Other
24 stars 44 forks source link

Pyret Blocks (tracking issue) #501

Open schanzer opened 5 months ago

schanzer commented 5 months ago

Now that the pcardune-blocks branch has been merged into horizon, we need a tracking issue to keep tabs on the remaining work.

asolove commented 5 months ago

For item 3, highlighting error locations, see: https://github.com/brownplt/code.pyret.org/pull/502

asolove commented 5 months ago

A couple other topics:

shriram commented 5 months ago

As an aside, note that Pyret for loops are not actually statements! They're genuine expressions. E.g.:

squares = for map(i from range(0, 5)): i * i end
check:
  squares is [list: 0, 1, 2 * 2, 3 * 3, 4 * 4]
end

In Pyret, for is just a very fancy and roundabout way of writing lambda, sorry-not-sorry. (-:

asolove commented 5 months ago

Of course, and thank you for the callout as I was being very imprecise with my language.

What I mean to say is not about semantics but instead:

Lexical syntax As expressions get longer, Blocks world shows them on a single line until it runs out of space, at which point it breaks the line and indents just enough to leave the expression inside the circle of its parent:

image

The question here is whether this automatic line breaking is sufficient and understandable to the intended audience as you make more and more complex nested expressions for things like the flag assignment.

Syntax:

But more importantly, each of the "holes" today only accepts a single expression, and there is no equivalent of Scheme's begin (which is implicit in many contexts in Pyret), so making local definitions and then using them is impossible, whereas it is frequently used in Pyret:

image

This problem maybe does not arise: is blocks for a subset of Pyret that doesn't need nested definitions or the other cases where you want implicit begin?

--

PS: incidentally, two other things that may need adding: today in blocks world, functions can only take a single argument and there is no support for infix operators like is.

schanzer commented 5 months ago

Adam, I so appreciate your thoughtful approach to design. A few responses:

  1. Yes, I do think that blocks are for a subset of Pyret that doesn't need nested definitions. Bootstrap doesn't nest definitions at all, and that's our primary use-case for blocks.
  2. Bootstrap uses only fixed-arity functions, so when Dorai and I designed the block language it was also fixed-arity. But that's definitely not a limitation of Snap! Snap blocks can be defined such that they contain an arbitrary number of holes.
  3. The question of how much "real Pyret syntax" we allow to leak through to blocks is a good one. Snap is shockingly flexible, but it wasn't hard to arrive at Pyret syntax that we couldn't reproduce. The best we could do was create blocks that have all the right syntax, but not in the right place. When I was spec'ing this out, I got stuck on which is worse: blocks looking nothing like Pyret syntax, or blocks looking like badly-indented Pyret syntax.

(3a - keep in mind that it's always easier to add a feature than remove or change it, so I decided to punt on adding Pyret syntax for the first release.)

asolove commented 4 months ago

Emmanuel sent over this file as a benchmark for all the bits of Pyret that need to work in blocks world for it to be demoable.

I spent some time tonight auditing everything in that file and figuring out which bits of it do and don't work in blocks today, so we have a checklist on what is left to figure out.

Things that definitely work

Things I couldn't test

Things that need some work

Questions

Next steps

jpolitz commented 4 months ago

If you want to deploy I'm happy to merge to horizon and you can test with the Google keys + setup at https://pyret-horizon.herokuapp.com

schanzer commented 4 months ago

@asolove from inside the snap submodule, you should be able to run a (full-featured) snap instance without Pyret at all. Dragging transpile.xml into the block palette will load the transpiler, and you can edit, add, or remove features as you see fit. Once you're done, you'll want to export the blocks back to XML.

I found it most useful to keep the original file open in one window, then compare it to the exported transpiler and manually copy over what I wanted. There are some subtleties to the machine-generated XML that will bite you if you replace the file whole-cloth. ;)

Happy to sit down on Zoom with you, if you like!