Author Topic: An idea regarding single variable programs.  (Read 4511 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Longing for more minimalism and nonsensical restriction in programming, I wonder how far somebody could take making a program with a single variable?

I suppose you could use a large variable like a double and then divide it into smaller memory sections. It would be really fun to look at a code and only see a single variable declaired and lots of shifting bits around to maintain such a low memory state.

Any thoughts? I might try this should I built up enough interest.
Might be an interesting challange to demo coding as we tend to applaud clever restrictions and ingenuity.

Again just making a conversation point here. I'd be interested to hear your thoughts.
Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: An idea regarding single variable programs.
« Reply #1 on: August 05, 2011 »
Sounds like you should look into Brainfuck :) . Very similar concept (though the one "variable" is a pointer into a table of 30000 or so slots depending on implementation). Been thinking about seeing how small an interpreter could be for, say, C64, where there's ROM routines available to print a char to the screen.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: An idea regarding single variable programs.
« Reply #2 on: August 05, 2011 »

I certainly wonder how you do things like nester for loops. With a single variable.  ;)
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: An idea regarding single variable programs.
« Reply #3 on: August 05, 2011 »
Some questions are - Can you access RAM?  Or a screen?  If so you can poke the the variable into memory, or plot it as a colour.  Can you use a stack, with push and pop?
There are 'languages' that only use only a few instructions.  My lecturer in Computer Science at university, Mike P Stannett, came up with a 3  instruction language called MPS which has M,P,S as instructions...(can you see a pattern forming here?)...

Jim
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: An idea regarding single variable programs.
« Reply #4 on: August 05, 2011 »


AH PMS!

I'm sure working with such an instruction set would make it feel as through the language caused PMS.
I'm not sure about restrictions Jim, you make some good points.
I suppose that it would just be a single variable with no way to store the data in memory the variable becomes your RAM.
I guess depending on the OS a double could give you 8 ascii characters (or 16 if you toss out the extended character set). Two floats (depending on the OS), or two ints (depending on os and sign).

Interesting thoughts so far.
Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: An idea regarding single variable programs.
« Reply #5 on: August 05, 2011 »
Duckers/Outracks and I at one point designed an imaginary 8-bit machine with some odd limitations, including a single branching instruction, SAP, which Swaps Accumulator with Program counter. We have yet to actually code the emulator for the thing...

But I think you can get very very far if you have access to any kind of framebuffer/char buffer; it can be used for temp storage as well as output. Stack would also be your best friend here. I don't know; I think I'm just rambling now :)
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: An idea regarding single variable programs.
« Reply #6 on: August 05, 2011 »
Code: [Select]
int *data = (int*)malloc(65536*sizeof(int)); // allocate memory
memset(data,0,65536); // zero the data
data[65535] = 0xDEADF00D; // place an end of data marker
while (*data != 0xDEADF00D) { // continue until we reach that marker
    // do you effect and place it in memory through the pointer
    data++;
}

Would I be allowed to use registers...
Code: [Select]
register counter = 65536;
while (counter) {
 counter--;
}

Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: An idea regarding single variable programs.
« Reply #7 on: August 05, 2011 »
Would declaring a single object with multiple properties be classed as cheating?
You are our 9001st visitor.
Challenge Trophies Won: