General Discussions about the API


Postby oliver » Sun Apr 03, 2011 3:47 am

MorphEngine will soon allow a dialect of GolfScript (http://www.golfscript.com) to be run, adding a 3rd language option to MorphEngine-based calculators.

Running transparently within MorphEngine, GolfScript will be callable from JavaScript and RPL.
For example, you will be able to call a little nugget like this
Code: Select all
(credit goes to gnibbler, http://stackoverflow.com/questions/1344352/code-golf-duplicate-character-removal-in-string) to remove all duplicated chars in a string.
Stored in a variable, you may not even know that you're running GolfScript.

In the other direction, GolfScript will be able to call any built-in and user-defined JavaScript and RPL function.
It's as if you suddenly have access to a pretty big (~400 functions; http://naivedesign.com/ND1/ND1_Reference__Function_Summary.html) function library that works with all your GolfScript types (and adds types of its own).
As this substantially augments what you can do in GolfScript, this language dialect receives a new name: "GolfScript/MorphEngine".
(Please use this as language name when doing golfing submissions, to prevent utter confusion.)

For example, this
MorphEngine permutate command in GolfScript
GS_permutate.png (3.35 KiB) Viewed 4672 times

is valid GolfScript/MorphEngine, and will produce:
After eval
GS_permutate_after.png (5.45 KiB) Viewed 4672 times

This functionality will first be available as a shared folder ("GolfScript") extension download for ND1.

Not all arcane minutiae of GolfScript will be supported. For example, you will not be able to reassign the space (" ") character. (Though you will be able to do the almost-as-crazy thing of re-assigning digits.)
Likely, the first release will be usable but incomplete in some respects.

The extension will be released in full source code, so you'll be able to play with it and improve it.

How will this be used?

On the edit line, prefix GolfScript code with "gs:"
GolfScript on edit line
GS_enter.png (2.79 KiB) Viewed 4673 times

The code will then appear as a custom data type (http://naivedesign.com/ND1/ND1_Reference__Custom_Types.html) on the stack.
GolfScript on stack
GS_type.png (3.07 KiB) Viewed 4673 times

Eval to run.
After eval
GS_executed.png (5.93 KiB) Viewed 4673 times

As you'd expect, inputs come from the stack, and outputs go to the stack.

You also have a few other commands available for this data type.
You can see how the script looks like, written in RPL:
Converted to RPL
GS_toRPL.png (3.67 KiB) Viewed 4673 times

And you can concatenate scripts using the "+" key.

How's this implemented?

MorphEngine morphs GolfScript into RPL+ (http://forums.naivedesign.com/viewforum.php?f=9) and blends in functions during the run of the script that provide the expected run-time environment.

How fast will this be?

The original (and, until now, one-and-only) implementation of GolfScript is on Ruby, an interpreted language. It doesn't have a reputation for being a speed demon. (Though this rarely matters.)

GolfScript/MorphEngine gets morphed into RPL+ and will run at RPL+ speeds. In MorphEngine, RPL is byte-compiled into JavaScript, which is JIT'ed in most implementations. (On iOS, you get best performance with Apple's "Nitro" JavaScript engine, shipping with iOS 4.3. and up)
For now, expect GolfScript/MorphEngine to run at quite similar speeds to the Ruby implementation, on the same hardware.

If you're using MorphEngine calls in your GolfScript/MorphEngine code, these will run at very fast speeds. (Much faster than if implemented, if you could, in GolfScript). For example, the permutate function used above will happily produce ~20,000 permutations per second.

The plan (http://forums.naivedesign.com/viewtopic.php?f=2&t=47) is to morph RPL into JavaScript which will provide a big speed boost. At that point, even plain GolfScript may run on a mobile device as fast as under Ruby on the desktop.

Some benchmark results will be posted soon.


If you're excited by this and want access *now*, ping me and I shall oblige.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

GolfScript/MorphEngine and Project Euler

Postby oliver » Sat May 21, 2011 12:01 am

Here're just a few GolfScript/MorphEngine programs that solve Project Euler (http://projecteuler.net) problems.

Code: Select all
#5: 21,tail{lcm}*
#6: 101,tail.{+}*SQ\SQ{+}+-
#7: 2{NEXTPRIME}10000*
#10: 2000000primes{+}*
#18 & #67: →{2{max}DOSUBS+}1-*

Note the use of MorphEngine instructions in otherwise regular GolfScript.

There're currently 53 language options in Project Euler, with GolfScript (so far...) absent. ("J" has a presence.)
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

GolfScript/MorphEngine - Status

Postby Prairie » Sun Nov 20, 2016 2:31 pm


What is the status of GolfScript? Looks pretty interesting. I don't see it as a SharedFolder. Moreover, I don't see a type listed under "calculator.customTypes"


Posts: 26
Joined: Mon Sep 30, 2013 2:47 pm

Re: "GolfScript/MorphEngine"

Postby oliver » Sun Nov 27, 2016 5:51 pm

The latest state is that I released the sources for the project thus far: viewtopic.php?f=11&t=1034

If you paste this into the Injection of your calculator (or create a folder with .injection as shown in some downloadable folders (Color, BigInt, Chem), the new type will install and you'll be able to try the given examples.


P.S. I haven't done testing of this in a while. I should be able to do some of this and release this as a downloadable folder over the holidays.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest