chalk-diagrams / chalk

A declarative drawing API in Python
MIT License
275 stars 13 forks source link

Right side operators #17

Open srush opened 2 years ago

srush commented 2 years ago

One thing I have been needing a lot is right-headed version of composition. I am not sure of the language for this in terms of monoids, but I want it to be like :

d1 / d2 where the origin stays at d2 instead of moving to d1.

I was thinking of notating this like

d1 // d2 , but maybe that is confusing. I guess the alternative would be to have a left facing below operator d2 \ d1 if that is possible in python.

Any thoughts.

danoneata commented 2 years ago

Thinking out loud. I would have liked \, but I don't think it's useable (here is the list of available operators in Python). On the other hand,floordiv (//) seems like a good option: it has the advantage of having an obvious mnemonic (/ keeps the origin of the first argument; // keeps the origin of the second argument). Maybe I would have liked it to be a single character (to facilitate aligning the code and make it easier on the eye), but this is a lesser aspect.

I assume we want a similar pair of operators for horizontal composition as well. So, if at all possible, it would be nice to achieve some consistency across the two types of compositions (vertical v and horizontal h). With this in mind, here are some options:

   origin at
   1 2
h: * **
v: / //

or maybe something like this:

   origin at
   1 2
h: & |
v: / %

(I usually associate & with first and | with second, maybe due to the short-circuit evaluation of the booleans. Although, after looking at this second option, I feel there are too many symbols to remember...)