Object disoriented

From Esolang
Jump to navigation Jump to search

Object disoriented is an object-oriented programming language. This means that objects are the only kind of data it manipulates. It also belongs to the class of functional programming languages, especially "dysfunctional programming languages" alongside 0x29A.

Each object has two member data objects, a and b. In line with the best data encapsulation principles, other objects cannot read these member objects. As such, the only way to read these objects is to interface with the object's single member function. This prevents incorrect use of these member objects.

Since each object's interface is a single function that takes an object as an argument and returns another object, all object are interchangeable, and thus virtual. This encourages polymorphism and inheritance.

Statements

c**
Copy object * to object *. This is not a pointer/referrence/shallow copy, it is a full, deep copy (ie a new instance).
f**
Use function of object * on object *, discard result.
*
This reads in an object, but then discards it (similar to a C++ statement). The f** statement is actually a special case of this. It can also be used to read in an input bit and discard it. Otherwise, this is pretty much a NOP.
o*
Output. Will add one bit to the output buffer. When the 8th bit is sent, an 8-bit char is printed. Send z for a 0, and n fpz rz zz for a 1. (other objects also have a value of 1) The bit order is most significant bit first, least significant bit last.
r*
Return *. This is also (necessarily) the end of the function, since there is no flow control anyway. If there was any assignment to s, the assignment happens here (without affecting the return value).

Readable and writable objects (l-values)

a
Member data a.
b
Member data b.
s
Self. This one is special: Reads from it return the current value, but writes will only happen after the end of the currently running function.
t
Function local variable.
p
Function parameter. This is not merely a copy of the parameter - if changes happen to this object, they also happen downstream! (so this is a so-called "call by reference".)

Readable objects (r-values)

z
Zero/dummy object. If executed as a function, the function does nothing and returns z. Thus, it is functionally equivalent to nrz zz or nrs ss.
f**
Return value of function of object * used on object *.
n(f)**
New object with code (f) and member objects * and *. For instance, n rp zz creates an object that simply returns its argument. n ra az will make a copy of the current object a into the child's object a, and thus will return a when called (this sort of construct can be used to store data, or form large data structures).
l"id".
Returns a new instance of class "id".
i
Input. Reads an 8-bit char into a buffer, and then reads the first bit. Subsequent references read following bits, until the buffer is empty and a new byte is polled. Returns z if the bit is 0, or n fpz rz zz (an object that activates it's parameter's function) if the bit is 1. The bits are read starting with the most significant bit.

Definitions

d"id".(f)**
Define class with name "id"., function (f), and member data * and * (often z and z). Technically, this isn't necessary, since the instances could be replaced with a n(f)**, so it's actually sort of a macro.
dmain.(f)**
Define a class which is the program's entry point. It is first called with z as parameter, although that can change if the function calls itself, of course.
ecomment.
This is a comment.

Examples

Cat program

e  This is CAT   .

e  This class is an infinite loop that inputs a bit and outputs it on each iteration  .
dcatloop.
  oi
  fsz
  rz
zz

e  This class is the program's entry point; it simply runs the catloop class's function  .
dmain.
  flcatloop.z
  rz
zz

Hello, world!

e  This hello world program implements a 88 bits stack   .
e  The stack represents the 11 char ascii data .

e  This function pushes a 0 onto a stack  .
dp0.
  cn
    cas
    rz
  pz
  p
zz

e  This function pushes a 1 onto a stack  .
dp1.
  cn
    cas
    r n fpz rz zz
  pz
  p
zz

e  This function creates a hello world stack  .
dmakehelloworld.
  flp0.a flp1.a flp1.a flp0.a flp1.a flp0.a flp0.a flp0.a     e   h   .
  flp0.a flp1.a flp1.a flp0.a flp0.a flp1.a flp0.a flp1.a     e   e   .
  flp0.a flp1.a flp1.a flp0.a flp1.a flp1.a flp0.a flp0.a     e   l   .
  flp0.a flp1.a flp1.a flp0.a flp1.a flp1.a flp0.a flp0.a     e   l   .
  flp0.a flp1.a flp1.a flp0.a flp1.a flp1.a flp1.a flp1.a     e   o   .
  flp0.a flp0.a flp1.a flp0.a flp0.a flp0.a flp0.a flp0.a     e space .
  flp0.a flp1.a flp1.a flp1.a flp0.a flp1.a flp1.a flp1.a     e   w   .
  flp0.a flp1.a flp1.a flp0.a flp1.a flp1.a flp1.a flp1.a     e   o   .
  flp0.a flp1.a flp1.a flp0.a flp1.a flp1.a flp0.a flp0.a     e   l   .
  flp0.a flp1.a flp1.a flp1.a flp0.a flp0.a flp1.a flp0.a     e   r   .
  flp0.a flp1.a flp1.a flp0.a flp0.a flp1.a flp0.a flp0.a     e   d   .
  ra
zz

e  This function takes a function and returns a function that repeats it 8 times  .
dmakeloop8.
  rn
    fap fap fap
    fap fap fap
    fap fap
    rz
  pz
zz

e  This function takes a function and returns a function that repeats it 11 times  .
dmakeloop11.
  rn
    fap fap fap fap
    fap fap fap fap
    fap fap fap
    rz
  pz
zz

e  This function pops a bit off the input (passed by reference) and outputs it  .
dprintstackbit.
  cfpza
  oa
  rz
zz

e  This function coordinates all the previous functions together (and is the entry point)  .
dmain.
  c flmakehelloworld.z a
  c flmakeloop11. flmakeloop8. lprintstackbit. b
  fba
  rz
zz

Delayed cat

e This program will store all the data input until
it reads a char >128 into a string, then output it.

dmain.cia cnfazobrzpap cncatcbactbrb snfpzrzzzt fatcftzt
cnfazobrzpip cnfazobrzpip cnfazobrzpip cnfazobrzpip
cnfazobrzpip cnfazobrzpip cnfazobrzpip ftprzzz

Minifuck interpreter

e Commands:               @: nop;
a: array[n]^=1;           b: n++;   
c: n--;                   d: print_bit(array[n]);
e: array[n]=get_bit();    f: while(array[n]){       
g: }, end of program
.

dmain.
 cfn
   iiiii
   c ncatcbactbrb ncatcbactbrb ii i t
   c fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnfazrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz
     z
     n
       cn cfap a rfn
         c fnrfaz pz t
         c fnrfaz tz a
         c fffnrnrncncatcbactbrbbptfatrftzappzzz a z n fpz rz zz a
         c ncatcbactbrb a fnfazrfaz tz t
         c ncatcbactbrb t fnfazrfaz pz b
         rb
       zz a pz p
       rz
     zz
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz
     n
       cn cfap a rfn
         c fnrfaz pz t
         c fnrfaz tz a
         c fnfazrfaz tz t
         c fnfazrfaz pz b
         c ncatcbactbrb ab b
         c ncatcbactbrb tb b
         rb
       zz a pz p
       rz
     zz
     n
       cn cfap a rfn
         c fnfazrfaz pz t
         c fnrfaz tz a
         c fnfazrfaz tz t
         c fnrfaz pz b
         c ncatcbactbrb ab b
         c ncatcbactbrb bt b
         rb
       zz a pz p
       rz
     zz
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnfazrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz
     n
       cn cfap a rfn
         c fnrfaz pz t
         c fnrfaz tz a
         oa
         rp
       zz a pz p
       rz
     zz
     n
       cn cfap a rfn
         c fnrfaz pz t
         c ncatcbactbrb i fnfazrfaz tz t
         c ncatcbactbrb t fnfazrfaz pz b
         rb
       zz a pz p
       rz
     zz
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz 
     n
       cn
         cfap a
         rfn
           c fnrfaz pz t
           c fnrfaz tz a
           c fffnrnrncncatcbactbrbbptfatrftzappzzz a b z a
           rfap
           zb
         a
         pb
       p
       rb
     zs
     z
   a
   fap
   c fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnfazrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz ss
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz ss
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnfazrfaz fnfazrfaz tz z
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz ss
   fffnrnrncncatcbactbrbbptfatrftzappzzz fnrfaz tz snrpzz b
   rfbp
 zz a
 fa ncatcbactbrb zz
 rz
zz

Comments

Since there's no looping statement, recursion must be used. For this reason, it is recommended to implement at least some simple recursion optimisations, since otherwise long loops would generate more data on each iteration, eventually overflowing the implementation's stack.

The language can be proven turing complete by remapping Unlambda programs as follows:

Unlambda Object disoriented
` f
i n rp zz
k n rn ra pz zz
s n rn rn rffapfbp ap pz zz

See also

Object disoriented Turing-completeness proof