xkcd Phone: Application Programming Language

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

xkcd Phone: Application Programming Language

Postby hppavilion1 » Sat Jan 02, 2016 12:02 am UTC

This language is only semi-serious, but development is actually planned

XKCDs 1363 and 1465 introduced us to the xkcd phone: A cell phone with features that you would never want.

To date, as far as I can tell, no language has been introduced to allow us to make apps for the xkcd phone or xkcd phone 2. This is not in line with the rest of the smartphone industry, which (in the case of Apple, at least) has been introducing cell phones designed specifically to tailor to their devices. I propose that we, the xkcd community, design and implement an awful, awful programming language (but still one that is better than Vista) designed for programming apps for the xkcd phone and xkcd phone 2.

This language, which is yet to be named, would incorporate features that no one would ever want and be a huge pain to learn, as it would be entirely unlike other programming languages. Unlike the hardware that runs it, however, it would not just use silly features that make no sense (e.g. variables are subject to genetic drift); it would instead be more like a programming language from a strange, alternative universe where Ghandi won World War VI+IIi.

Implementation

The language will be implemented initially in Python (on Anaconda 3.4) using PLY as its lexer and parser. The source code will be initially be made available on GitHub as development progresses under the GPL. The GUI will be based on PyQt5 and files will be sandboxed for safety.

Ideas

  • OO, but not classy (According to wikipedia, "There is significant diversity in object-oriented programming, but most popular languages are class-based", implying that classiness is not what makes OO OO, so we can invent something entirely batshit insane and use that instead).
  • Relativistic concurrent programming (what happens first/whether two events are simultaneous is relative) (if we can get it to work)
  • Much GUI
  • Instead of if-then, a REPEAT loop that accepts a real number n and repeats n times (for the decimal component of n, whether it executes an extra time is a random chance based on that decimal)
  • Call-with-excluded-middle-continuation (Sort of like Call/cc, but not based on Pierce's law), or perhaps something even stranger
  • Too much of the Curry-Howard Correspondence
  • Strange operators
  • Fully-fledged libraries
  • Builtin regex that is nothing like normal regex
  • Pattern matching
  • Diads instead of monads? If that makes any sense.

Significant Questions

  • Semicolon/curly brackets, whitespace, or START..END?

Contact

I don't have the best memory, and thus am likely to forget about this project soon and not visit this forum if not reminded. It's not that I don't care, it's just that my mind is a confusing place that I often lose things in.

If you are interested in this project but can't get me online, check #esoteric on Freenode. I often hangout there under the nick hppavilion[1]. If I'm not online, I'm sure one of the denizens would be likely to pass the message (or just @tell me with Lambdabot. That's probably preferable.)

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

Re: xkcd Phone: Application Programming Language

Postby hppavilion1 » Sat Jan 02, 2016 1:34 am UTC

In this post, I would like to cover the alternatives to classical, classy OO supported by the xkcd phone language.

Getting something straight

OO does not imply classes. While most languages that support OO typically use classes, that is not the only way that an OO language can be implemented- for an example of an OO language construct that is OO but doesn't use, see JavaScript's prototypes- that's prototype-oriented programming, a type of OO.

What is OO then? OO, at its basic form, is a programming language being based off of objects. This means that the language supports little collections of named things- data ("fields") and code ("methods")- that can be used for programming. Methods can access the data in the object with the concept of "self" or "this", while whether an outside source can access fields depends on the language and on the implementation.

Now, the most intuitive way to implement these is, of course, classes usually. However, this language can't be- bleck- normal! It's for the xkcd phone, that would be an atrocity! As such, this post sets out a subset of the possible alternatives to classy OO that could be used in this language.

Prototypes

The most common type of unclassy OO is prototypes. Instead of being based on classes which can be called with a constructor to produce objects, prototypical programming works by cloning existing objects that serve as "prototypes" to gain their behavior.

To create a new object, one must clone an existing prototype object; for example, to create a Dachshund, one might clone a Dog object, which was either cloned from an Animal object or made ex nihilo (from nothing, based on a literal). This means that objects, essentially, inherit from other objects as opposed to being made from classes.

Groups

Let's try something else. What if, instead of having an abstract sort of object thing that can be used to create actual objects based on a structure, we declared all of the possible values for the object at runtime? This seems to be in line with the mathematical construct of the group: a mathematical object that has a (potentially-infinite) set of elements and one (or, in our case, one or more) operation.

A group might be declared something like this:

Code: Select all

group StrangePoint2D [{-2, -1, 0, 1, 2}, {-1, 0, 1}] { // A point that is a tuple of an integer from -2 to 2 (inclusive) and -1 to 1 (inclusive). This is equivalent to `group [{(-2, -1), (-2, 0), (-2, 1), (-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 0), (0, 1), (1, -1), (1, 0), (1, 1), (2, -1), (2, 0), (2, 1)}]`, but more concise.

   // No constructor is needed (or allowed) because it's generated as a tuple automatically.

   operation add (us, them) => us[0]+them[0], us[1]+them[1];  // Add the x and y (will crash if an overflow occurs). Defines the + infix operation as well. Because groups have closure, one need not specify that it's a StrangePoint2D; it automatically feeds the output tuple to StrangePoint2D (in fact, it'll crash if you try to return something /without/ closure).

   operation sub (us, them) => us[0]-them[0], us[1]-them[1];  // Subraction (- infix operation). Also note that the us[n] and them[n] are only accessible from within an operation, method or attribute; there's no way to get it without a method for it. Also, note that operations must ALWAYS accept the right number of arguments, and it automatically has the required type for closure. Methods do not have this constraint.
   
   operation neg (me)       => -me[0], -me[1];  // Negation (- prefix operation)
   
   operation inc (me)       => me[0]++, me[1]++; // Increment x and y values (++ prefix/postfix operation)
   operation dec (me)       => me[0]--, me[1]--; // Decrement x and y values (-- prefix/postfix operation)
   
   method acrossOrigin (me) := neg;  // neg is equivalent to reflecting across the origin
   
   method acrossX (me) => me[0], -me[1];  // reflect across x-axis
   method acrossY (me) => -me[0], me[1];  // reflect across y-axis
   method swap (me) => me[1], me[0];  // Swap x and y locations
   
   method incx (me) => me[0]++, me[1];  // Increment x but not y
   method decx (me) => me[0]--, me[1];  // Decrement x but not y
   method incy (me) => me[0], me[1]++;  // Increment y but not x
   method decy (me) => me[0], me[1]--;  // Decrement y but not x
   
   attr x (me) => me[0];  // Declare what the "x" attribute is (for the sp := StrangePoint2D(-1, 0), sp.x==-1)
   attr y (me) => me[1];  // Declare what the "y" attribute is (for the sp := StrangePoint2D(-1, 0), sp.y==0)
};


Type Building

Custom Types are a glorious idea I had when making the aptly-named langauge TypeMaker. The idea behind custom types is that you have to deal with the low-level data yourself, instead of just creating a struct or whatever. Custom Types are declared with the following syntax:

Code: Select all

[abstract] type <name> ("<" [{<name> ","} <name> ":"] <data> ">" && ["(" <name> ")"] ) ":"


If the abstract keyword is present, then the type cannot be used on its own. The name is a traditional name matching the standard name regex, and the following data in angled brackets tells the code what data is to be allocated for it. If the type is abstract, the data can be prefixed by a comma-separated list of variables terminated with a colon to tell the abstract type what its child types can decide. The part in parentheses, which is optional, gives the supertype. The data itself is of the form:

Code: Select all

{<name> ["[" ()<int>|<name>)"]" ","}<name> ["[" ()<int>|<name>)"]"]

And tells it what the individual data is. The outer <name>s tell it what data is being used, most commonly bit or byte, and the inner names or variable tell it how much at once. The total amount of data in bits should be a power of 2.

The body of the type is strange and convoluted, but it essentially provides a list of operations and rewrite rules to tell the program how to treat the data when operated on. For example, add inside the abstract type UnsignedInteger (which is the supertype for Bool, UnsignedCrumb, UnsignedNybble, UnsignedByte, UnsignedShort, UnsignedWord, UnsignedLong, and UnsignedScientific) is defined like this:

Code: Select all

   declare op Add: +  # Create a new operator with the "+" symbol called Add
    Add style: infix, left, 2  # Add is a left-associative infix binary operator
    Add type: UnsignedInteger, UnsignedInteger -> UnsignedInteger  # Declare the type of the operation "+". Takes two UnsignedIntegers and returns an UnsignedInteger
    Add evaluation: bitwise, backward, ignore, treatAs0  # Determine the style of evaluation. In this case, it is a bitwise operator that works from the end and ignores leftover flags (overflows, in this case). treatAs0 is special for abstract types where multiple different types can be added: it treats unfilled values as 0
    Add flags: carry  # Create the carry flag
 
    # The following few lines are just declarations for bit combinations and flags
    Add rule: [0, 0] -> 0  # Two zeros added equal zero
    Add rule: ([0, 1] | [1, 0]) -> 1  # | can be used to alternate combinations
    Add rule: [0, 0], carry -> 1  # Two zeros added when the carry flag is true equals 1
    Add rule: ([0, 1] | [1, 0]), carry -> 0, carry 
    Add rule: [1, 1], carry -> 1, carry
    Add rule: [1, 1] -> 0, carry # Two ones added when carry is set returns 0 with the carry flag set


Other ideas

Have an idea you think is better? Or, for the purposes of the language, worse? Suggest it below!

commodorejohn
Posts: 958
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: xkcd Phone: Application Programming Language

Postby commodorejohn » Sat Jan 02, 2016 2:49 am UTC

I always assumed that the systems language of the xkcd Phone would be INTERCAL...
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

BedderDanu
Posts: 39
Joined: Tue Jan 14, 2014 6:18 am UTC

Re: xkcd Phone: Application Programming Language

Postby BedderDanu » Wed Jan 06, 2016 12:58 am UTC

I wonder if there is a way to bake a Entity-Component-System into the language as the OO implementation, if that even makes sense.

User avatar
Wildcard
Candlestick!
Posts: 251
Joined: Wed Jul 02, 2008 12:42 am UTC
Location: Outside of the box

Re: xkcd Phone: Application Programming Language

Postby Wildcard » Thu Jan 07, 2016 10:24 am UTC

hppavilion1 wrote:
Significant Questions

  • Semicolon/curly brackets, whitespace, or START..END?

That's an easy one:

Expressions should go from START to }
start to ) will also work but START to ) will be interpreted as a comment.

Statements should go from { to END

Removing special character meanings (a la bash single quotes) will be done by adding three space-characters followed by a tab at the beginning of the line.
There's no such thing as a funny sig.

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

Re: xkcd Phone: Application Programming Language

Postby hppavilion1 » Thu Jan 07, 2016 7:44 pm UTC

Wildcard wrote:
hppavilion1 wrote:<snip>

That's an easy one:

Expressions should go from START to }
start to ) will also work but START to ) will be interpreted as a comment.

Statements should go from { to END

Removing special character meanings (a la bash single quotes) will be done by adding three space-characters followed by a tab at the beginning of the line.

Brilliant! I'm implementing!

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

Re: xkcd Phone: Application Programming Language

Postby hppavilion1 » Sun Jan 17, 2016 7:28 pm UTC

This post covers the Type System of the xkcd Phone Programming Language

On the Curry-Howard(-Lambek) Correspondence

Instances of types are proofs of that type. I'm just going to let that sink in for those of you who haven't heard of Curry/Howard.

If you know anything about the Curry-Howard Correspondence, you will know that it is a big, somewhat confusing thing that relates the type systems of functional programming with the various systems of formal logic (typically Intuitionistic). To make the XPL sufficiently strange, we will likely need to take advantage of this.`

Though functional languages usually use Intuitionistic logic for their corresponding type system, it isn't, strictly, necessary. We could, in theory, use a much more fun logic (see: Any modal logic). We could even invent our own little niche branch of logic if we so pleased, for example one based on geometry or manifolds. But that would be hard.

A consequence of Curry-Howard is that all functions tend to correspond to laws, axioms, and theorems from formal logic- most interestingly, Pierce's Law is basically just the type of call/cc, and vice versa. We can leverage this in our favour, using obscure laws of formal logic to form strange control flow (call/ccpc, anyone? (call with current continuation plus (other) continuation)).

Logics Available to Us

  • Modal Logic: There are many modal logics. They all tend to be strange and interesting.
    • Alethic Logic: Essentially the base modal logic, which deals with possibility and necessity
    • Epistemic Logic: The logic of knowledge- what someone knows, what they don't know, and how they come to know things.
    • Temporal Logic: The logic of time. Preferably, computation tree logic (branching time) would be used
    • Deontic Logic: The logic of social norms and what is permitted to happen. Has some intuitive problems you can find on the Wiki article (which might make it a pretty good candidate).
    • Doxastic Logic: The logic of what people believe and what can disprove it to them (presumably).
  • Three+-valued: Why not have a logic with truth, falsity, and irrelevance? Or some other combination of three or more possibilities? That's the basis of Three-valued logic, along with arbitrary n-valued logic.
  • Fuzzy Logic: Well what does truth really mean? Doesn't truth come in degrees? Aren't there half truths and quarter truths and two-thirds truths? That's what Fuzzy Logic is all about. A sort of generalization of Three-valued logic.
  • Linear Logic: Linear logic is goddamn confusing. Something to do with limited resources (you can only use so many 15s in a program). Run.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3035
Joined: Sat May 09, 2009 11:55 pm UTC

Re: xkcd Phone: Application Programming Language

Postby Qaanol » Mon Jan 18, 2016 3:51 am UTC

^ will be the exponentiation operator. The xor operator will be ⊗

Whitespace around operators will affect order of evaluation:
-3 ^ 2 is positive 9
-3^2 is negative 9
1+2 * 3+4 is 21
wee free kings

User avatar
Flumble
Yes Man
Posts: 1944
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: xkcd Phone: Application Programming Language

Postby Flumble » Mon Jan 18, 2016 5:47 am UTC

Qaanol wrote:Whitespace around operators will affect order of evaluation:

*effect
This literally begs the question: how wide is a tab?

User avatar
LucasBrown
Posts: 293
Joined: Thu Apr 15, 2010 2:57 am UTC
Location: Poway, CA

Re: xkcd Phone: Application Programming Language

Postby LucasBrown » Tue Jan 19, 2016 3:28 am UTC

There will be no such thing as indentation. Lines beginning with whitespace produce syntax errors.

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3035
Joined: Sat May 09, 2009 11:55 pm UTC

Re: xkcd Phone: Application Programming Language

Postby Qaanol » Tue Jan 19, 2016 6:37 am UTC

Or better yet, reverse indentation. The innermost code is not indented at all, and each containing scope is indented one level more. Anytime you add an even-more-inner scope, you have to indent the entire rest of the file.
wee free kings

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

Re: xkcd Phone: Application Programming Language

Postby hppavilion1 » Tue Jan 19, 2016 7:07 am UTC

Oh god. Something I could parse with PLY as a n00b would be appreciated.

User avatar
Flumble
Yes Man
Posts: 1944
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: xkcd Phone: Application Programming Language

Postby Flumble » Tue Jan 19, 2016 2:29 pm UTC

LucasBrown wrote:There will be no such thing as indentation. Lines beginning with whitespace produce syntax errors.

Oh no, my question concerns the whitespace around operators.
How does it parse, say, a+b<tab>/c/<space><space><space><space>d<space>*<tab>e?

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: xkcd Phone: Application Programming Language

Postby korona » Tue Jan 19, 2016 11:04 pm UTC

At this point the syntax is already context-sensitive so writing a parser for the language becomes incredibly hard.

User avatar
Xanthir
My HERO!!!
Posts: 5214
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: xkcd Phone: Application Programming Language

Postby Xanthir » Wed Jan 20, 2016 3:47 am UTC

Flumble wrote:How does it parse, say, a+b<tab>/c/<space><space><space><space>d<space>*<tab>e?

According to the indentation settings of your IDE/compiler, obviously.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: xkcd Phone: Application Programming Language

Postby phlip » Thu Jan 21, 2016 12:00 pm UTC

Flumble wrote:This literally begs the question: how wide is a tab?

As I suggested once in the Tabs vs Spaces religious war thread - 1 tab = pi spaces.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Qaanol
The Cheshirest Catamount
Posts: 3035
Joined: Sat May 09, 2009 11:55 pm UTC

Re: xkcd Phone: Application Programming Language

Postby Qaanol » Sat Feb 27, 2016 9:32 pm UTC

phlip wrote:- 1 tab = pi spaces.

Ooh, negative whitespace. I like where this is headed.
wee free kings

User avatar
Soupspoon
You have done something you shouldn't. Or are about to.
Posts: 2475
Joined: Thu Jan 28, 2016 7:00 pm UTC
Location: 53-1

Re: xkcd Phone: Application Programming Language

Postby Soupspoon » Sun Feb 28, 2016 10:37 am UTC

Qaanol wrote:
phlip wrote:- 1 tab = pi spaces.

Ooh, negative whitespace. I like where this is headed.

Leftwards? (Need negative "^H"s to go right. And negative ^G would be required to mute the phone.)

User avatar
phlip
Restorer of Worlds
Posts: 7543
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: xkcd Phone: Application Programming Language

Postby phlip » Mon Feb 29, 2016 12:10 pm UTC

Code: Select all

ungetc('\a', stdin);
?

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
Mikemk
Posts: 113
Joined: Tue Feb 11, 2014 7:10 am UTC
Location: Moving furniture'); DROP TABLE OweMyFoot; --

Re: xkcd Phone: Application Programming Language

Postby Mikemk » Tue Mar 01, 2016 3:08 pm UTC

On a more serious note, the following functions are automatically included in all objects unless overridden:
  • Code: Select all

    GetValueOfPi START int e, long float b}

    Nonstatically determines the value of π in base b, scaled so that ((π-e)/(e-0))_10 = ((π-e)/(e-0))_b
  • Code: Select all

    GetValueOfPi START}

    Returns Pau
  • Code: Select all

    CheckIfVelociraptorsPrenset START}

    Returns false if velociraptors exist in the object. Returns true otherwise. Will return a value other than true or false if overridden to always provide one or the other. (SIC)
If the functions are overridden, they must be implemented sanely, or compilation fails.

Also, z is an illegal character unless it's preceded by Q. q is an illegal character unless it's preceded by Z. Both Q and Z must be preceded by xkcd or XKCD.

xkcd and XKCD are legal in the program. Any other variation of the names results in the compiler automatically calling the police. If unable to contact the police, the phone pushes itself into free fall.
Computer specs:
Spoiler:
Intel i5-750 (OC 3.33 GHz)
8GB (OC 1333 MHz) (2GB HDD cache)
NVIDIA GT 740 (OC 1149 MHz) 4GB (OC 841 MHz)
480GB SSD (120 HDD cache)
2x2TB HDD (not RAID)
Windows 10
Linux Mint in VM

hppavilion1
Posts: 21
Joined: Wed Aug 27, 2014 1:00 am UTC

Re: xkcd Phone: Application Programming Language

Postby hppavilion1 » Tue Apr 12, 2016 1:09 am UTC

Instead of objects, concepts.

Functions can return more than once, and put the returned value into a queue.

Return can also be raised to a power, as in:

Code: Select all

return^n x
, resulting in it returning from a caller.

Code: Select all

return^1 x
is just return, but

Code: Select all

return^2 x
returns from its caller and

Code: Select all

return^3 x
returns from its caller's caller. Essentially, it's the functional equivalent of RJMP.

User avatar
Xanthir
My HERO!!!
Posts: 5214
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: xkcd Phone: Application Programming Language

Postby Xanthir » Tue Apr 12, 2016 2:04 pm UTC

Returning multiple times and putting the values into a queue sounds like a standard generator function, like Python or JS has. Each "yield" returns a value, until you finally hit a "return" (or the end of the function).

They're implemented as pausing the function until you request the next value, but that's functionally identical to just running the function and collecting the results (except that the former allows infinite return values). You can pull all the values out of a (finite) generator at once really easily, though - `[...func()]` in JS, or `[x for x in func()]` in Python.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 10 guests