Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Whitespace #207

Merged
merged 1 commit into from
Aug 22, 2015
Merged

Improve Whitespace #207

merged 1 commit into from
Aug 22, 2015

Conversation

0x0dea
Copy link
Contributor

@0x0dea 0x0dea commented Aug 17, 2015

The disassembly of the current program clearly indicates that it was generated by a machine, which is, I think, not in the spirit of the project. This patch replaces the existing program with a more idiomatic one which, in addition to being smaller and faster, masquerades as a sequence of assembly instructions while remaining an executable Whitespace program.

[The disassembly of the current program](https://gist.github.com/0x0dea/f68d381ed844f85fa2bd)
clearly indicates that it was generated by a machine, which is, I think,
not in the spirit of the project. This patch replaces the existing
program with a more idiomatic one which, in addition to being smaller
and faster, masquerades as a sequence of assembly instructions while
remaining an executable Whitespace program.
@rdebath
Copy link
Contributor

rdebath commented Aug 17, 2015

Humm, you're using the extended pick/copy instruction "\s\t\s", most interpreters miss that instruction (and it's "leave" friend). In fact I think only the original v0.3 Haskell one does it and that interpreter is horribly slow, fragile and difficult to compile.

Perhaps a plain "push/outchar" variant ? The one disassembled below is shorter than yours.

BTW: The labels in the original program should probably be interpreted like this ...

ws_label(add);
ws_label(write);
ws_label(write_end);
ws_label(read);
ws_label(read_end);
ws_label(newline);

New version like this ...

ws_push(72);
ws_outc();
ws_push(101);
ws_outc();
ws_push(108);
ws_dup();
ws_outc();
ws_outc();
ws_push(111);
ws_outc();
ws_push(44);
ws_outc();
ws_push(32);
ws_outc();
ws_push(119);
ws_outc();
ws_push(111);
ws_outc();
ws_push(114);
ws_outc();
ws_push(108);
ws_outc();
ws_push(100);
ws_outc();
ws_push(33);
ws_outc();
ws_push(10);
ws_outc();
ws_exit();

@0x0dea
Copy link
Contributor Author

0x0dea commented Aug 17, 2015

I did forget that copy was only added in v0.3, but Pavel Shub's interpreter implements it, and is generally much better than the reference interpreter for the reasons you've cited and more.

I suppose it wouldn't be unwise to forego the use of copy, but I contend that the overly simplistic push/outchar approach fails to sufficiently "demonstrate" the language. It seems appropriate to showcase at least slightly more than the fact that there is a stack and a facility for character output.

It's largely beside the point, but we must be reading different programs: the one I've proposed contains 23 instructions totaling 168 bytes, whereas the numbers for yours are 29 and 199.

@rdebath
Copy link
Contributor

rdebath commented Aug 17, 2015

doh, I forgot you included those "comments".

@leachim6
Copy link
Owner

I'm no expert on this language, which is the basis for this entire project
(learning new stuff!). Which version do you both think best represents the
form and flow of the language itself?

On Mon, Aug 17, 2015 at 4:39 AM, rdebath notifications@github.com wrote:

doh, I forgot you included those "comments".


Reply to this email directly or view it on GitHub
#207 (comment).

@0x0dea
Copy link
Contributor Author

0x0dea commented Aug 18, 2015

The current program does use a more diverse collection of the language's instructions, but it does so "unnaturally", in my estimation. There's quite a bit of redundancy, and‒as @rdebath points out‒the labels have been constructed programmatically, making for a rather unsightly program:

Current program

Contrast that with my proposed program:

My proposal

The comparison isn't particularly authoritative, but I find it rather convincing nonetheless.

Given that most of the other examples simply defer to some print routine, I suppose the suggestion to use nothing more than push and outchar is reasonable, and the resultant program isn't atrocious visually:

@rdebath's variant

Still, I maintain that demonstrating the rudiments of looping in Whitespace better aligns with the project's intent of providing a "feel" for each language.

@rdebath
Copy link
Contributor

rdebath commented Aug 18, 2015

I think that the I would use either the repeated push/outc or the push+loop[pop/out] flavour in a stack language like this. Probably the shorter as speed is likely to be swamped by I/O.

So, I agree, the version by @0x0dea or perhaps the "un-golfed" variant without the PICK command.

leachim6 added a commit that referenced this pull request Aug 22, 2015
@leachim6 leachim6 merged commit 19d49cf into leachim6:master Aug 22, 2015
Dineshkarthik added a commit to Dineshkarthik/hello-world that referenced this pull request Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants