Talk:PHAWN

From Esolang
Jump to navigation Jump to search

There seem to be a few mistakes in the instruction descriptions, judging by the examples. Here are suggested corrections:

> Push the number preceding the instruction (Pop if moving left)
} Input (Output if moving left)

A few other things aren't clear:

  • Should it be legal to pop from an empty stack? What would happen?
  • How does the program counter progress should it encounter a comment?
  • Are arbitrary instructions allowed between the number to be pushed and the instruction to push it, or only more push instructions?

-- Smjg 23:26, 27 October 2007 (UTC)

I made the corrections you suggested. As for your questions:
  • When the interpreter wants to pop from an empty stack the instruction is simply ignored. So if you want to perform the add instruction and there is only 1 value in the stack, nothing will be popped and the instruction skipped.
  • The program never enters a commented region. The interpreter should not load the entire program before any execution begins. If a comment is detected, an end of line character should be place and the next line should be loaded. Once all the lines are loaded (into an array of lines or a 2 dimensional array of characters, however you program the interpreter) then execution begins.
  • When a number is encountered it is stored as it's own variable until a push instruction is requested or another number is found. If another number is found the old value is discarded and the new one takes it's place.
StapleGun 10:24, 4 November 2007 (UTC)


Any chance the output could be made so that it wouldn't print a new-line after every printed character? For example value 10 could work as a new-line (as is usual in esolangs). I'm only asking this because I want to write a quine in this and it's impossible if a new-line is printed after every character. :) Cool lang. --Keymaker 19:08, 31 October 2007 (UTC)

It already has support for this. Push the value 10 or 13 onto the stack, switching the output mode to character (With the & symbol) and outputing the value on the top of the stack will print a new line. Here's an example code.

$&10>{#

That will simply print a new line.

I also forgot to mention it in the article (I'll edit it now) that when you pop a value it is placed in the register for the next value to push. For example, the following code push 26 onto the stack and will eventually print it even though the last number in the register was 17. This allows you to duplicate values because when you push a value, it does not clear the register.

$26>17<>>>{#

The number 26 will be printed and the stack will be [26, 26].

StapleGun 08:02, 1 November 2007 (UTC)

No, no, I meant that the interpreter, when I'm running it (on a Windows machine), prints a new-line after every single output command! This program:
&67>66>65>{{{#
prints out
A
B
C
instead of what I'd like,
ABC
So that is what I meant, I meant that only, say, value 10 should print a new-line, and other printing happen without it. Or is it just the fault of my Python version or environment? --Keymaker 10:23, 1 November 2007 (UTC)
Also, what is the PHAWN file extension? --Keymaker 22:43, 1 November 2007 (UTC)


Hmm, looks like I just programmed it wrong. I'll have to fix that. I had never seen a line of Python code before I start writing that interpreter so I'll have to figure out a wa to make it print correctly. As for the file extension, I'm not quite sure, perhaps PHN. A quick search on file-extensions.org only produces 4 results so I think it's suitable.

If you place a comment at the end of the print lines in the Output sub routine, it will print it all on the same line but it will have spaces after each character, I don't know how to get around this unless everything is printed at the end of program execution. I'm not sure that's what I want to happen though.

I also added multiply and divide instructions as I though they should be helpul and I'll upload the new interpreter source code.

StapleGun 05:58, 2 November 2007 (UTC)

I'm no Python expert myself, only know some bits and pieces, but I replaced your output code with this when I was building my quine (which was finished yesterday and I guess I can now upload soon as I know the file extension):
        if mode == 0:
            sys.stdout.write(str(data))
        else:
            sys.stdout.write(chr(data))
That should do the trick. --Keymaker 10:01, 2 November 2007 (UTC)
Your output method works great. I'll modify the source and upload it. I'd like to see your Quine as well, that should be interesting as I haven't thought about one in PHAWN yet.
StapleGun 11:24, 2 November 2007 (UTC)

Quine

Here's the mentioned PHAWN quine: http://koti.mbnet.fi/yiap/programs/phawn/kquine.phn --Keymaker 11:52, 2 November 2007 (UTC)

That's wonderful! I'll post it on the main page under your name. StapleGun 11:54, 2 November 2007 (UTC)