Structured Piet programming?

View previous topic View next topic Go down

Structured Piet programming?

Post  skwirl42 on Thu Aug 06, 2009 11:39 am

I've been thinking about how to make structured Piet programs, since it'd make for better reusability. One thought is to have a sort of function scheme much like in C, where the return address and arguments are placed on the stack. When a function is finished, it can then pass along into a common dispatch area that will use the return "address" to direct program flow to the appropriate spot. Calling a function would work much the same way, put its "address" on the stack, then enter a function dispatching area.
avatar
skwirl42

Posts : 7
Join date : 2009-08-06

View user profile

Back to top Go down

Re: Structured Piet programming?

Post  Batmanifestdestiny on Sat Aug 08, 2009 8:20 pm

That would be very interesting! You could draw a loop with a special series of codels in it that turns the black codel at the end of the line into whitespace, so that conditional loops could be possible!
avatar
Batmanifestdestiny
Admin

Posts : 21
Join date : 2009-07-15

View user profile http://piet.forumotion.com

Back to top Go down

Re: Structured Piet programming?

Post  skwirl42 on Sat Aug 08, 2009 8:31 pm

I don't think Piet allows self-modifying code. If you check out my avatar, the little rainbow part in the bottom right is a "print string" function that outputs what's on the stack until it hits a null character. It's essentially a conditional loop, since it loops around until a condition is met. Wink It's not the most elegant Hello World program, but it's the most structured I've seen. Wink

I guess with my preference for structured programming, I just tend towards that kind of thing, even when writing in languages that don't directly support it. ie Piet and assembly.
avatar
skwirl42

Posts : 7
Join date : 2009-08-06

View user profile

Back to top Go down

Re: Structured Piet programming?

Post  Batmanifestdestiny on Mon Aug 10, 2009 2:01 pm

that's very interesting!

Until I saw your code, I had yet to see structured coding, but maybe I'm not looking hard enough.
avatar
Batmanifestdestiny
Admin

Posts : 21
Join date : 2009-07-15

View user profile http://piet.forumotion.com

Back to top Go down

Re: Structured Piet programming?

Post  skwirl42 on Mon Aug 10, 2009 2:07 pm

I think perhaps the 99 bottles of beer on samples page uses somewhat structured programming. I'd have to run it through npiet or something to see what the actual instructions are. I don't know that there's anyone who can reliably read Piet directly from the graphic. Wink Certainly not me.
avatar
skwirl42

Posts : 7
Join date : 2009-08-06

View user profile

Back to top Go down

Re: Structured Piet programming?

Post  captncraig on Fri Sep 18, 2009 5:59 pm

I've thought about this before. I have two ideas...
The first is something like this:

Imagine each line of color is a "subroutine". The black squares direct the flow back to the next "function" to be run. Most of the black squares define a channel back to a new routine, and each routine more or less selects where it will go to next based on where it places the block to the right of itself. Here routines 1 and 3 will goto 4 when they're done, 2 goes to 1, 4 goes to 5, and 5 goes to 2. With this setup, any function can go to any other function when it is done, but it must be known beforehand which. You may be able to do something clever with branches to make it work more dynamically, but it gets really confusing for me really fast. Maybe it could be machine generated though.

My favorite solution though would be to extend the language (maybe use half steps, maybe somehow incorporate alpha, maybe replace a current command) to include a call stack.
A jump command can pop two values and go to that x, y coordinate, pushing the current, x, y, dp, cc onto the call stack.
A return can then pop the last value from the call stack and jump there. It would be complicated, but may actually make it much much easier to do interesting things.

captncraig

Posts : 5
Join date : 2009-09-18

View user profile

Back to top Go down

Re: Structured Piet programming?

Post  Batmanifestdestiny on Fri Sep 25, 2009 4:03 pm

I really like the thought of jump commands! maybe there could just be a command that stores the coordinates as codel number and then another command to jump to that codel number? that would be awesome.
avatar
Batmanifestdestiny
Admin

Posts : 21
Join date : 2009-07-15

View user profile http://piet.forumotion.com

Back to top Go down

Re: Structured Piet programming?

Post  moonshadow on Thu Jun 17, 2010 5:24 pm

You really don't need to alter the Piet spec to implement any of these. Piet is already Turing complete. Check this out, for instance - it was generated from this source. You can have your jumps, loops, even recursive functions with what there is already. You just need to think about it in the right way - which is surely the whole point of choosing to work within the constraints of an esoteric language rather than, oh, C++ Wink

moonshadow

Posts : 2
Join date : 2010-02-27

View user profile

Back to top Go down

Re: Structured Piet programming?

Post  Batmanifestdestiny on Sun Jun 20, 2010 5:28 pm

moonshadow wrote:You really don't need to alter the Piet spec to implement any of these. Piet is already Turing complete. Check this out, for instance - it was generated from this source. You can have your jumps, loops, even recursive functions with what there is already. You just need to think about it in the right way - which is surely the whole point of choosing to work within the constraints of an esoteric language rather than, oh, C++ Wink

O_O Wow, that's pretty cool!


By the way, unless mtptl starts making posts relevant to the topic and isn't just using their posts to have spam in their signature, they're going to get banned. Wink
avatar
Batmanifestdestiny
Admin

Posts : 21
Join date : 2009-07-15

View user profile http://piet.forumotion.com

Back to top Go down

Re: Structured Piet programming?

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum