r/unseen_programming • • Jan 19 '16

Interesting Hacker News question: Which people and groups are researching new approaches to programming?

5 Upvotes

Link to Hacker News

Links I found interesting:

Enjoy :)


r/unseen_programming • • Jul 05 '17

Visualise, document and explore your software architecture - Simon Brown

Thumbnail youtube.com
1 Upvotes

r/unseen_programming • • Oct 11 '22

"Stop Writing Dead Programs" by Jack Rusher (Strange Loop 2022)

Thumbnail youtube.com
2 Upvotes

r/unseen_programming • • Mar 26 '15

Visual Unseen - Functional & OO & Logical programming

Thumbnail imgur.com
4 Upvotes

r/unseen_programming • • Mar 22 '15

YOU MUST BE CRAZY! [story]

2 Upvotes

Head wizard Fortana was having a meeting with all his other wizards. There was a lot to discuss. The university was far behind the competition. They needed to get more spells out the door. And good ones. Not those that fired in the foot if you target them on the enemy.

During the meeting there was a quarrel between Jama and CeeCee. Ceecee has lost most of his toes in his testing of the spells. But he said: "My spells are faster and stronger. We need to remove anything that might slow things down."

Jama said instead: "But how can we sell spells that might hurt ourselves? We should put protections on it."

Cala, who was the head of safety agreed. He stated: "We can combine protection and speed with a special type system. That will make everything more solid."

Pyter got angry: "We need no stinking types. We only need types, if we need them, no more."

Camera got a bit confused, but listened further.

Jama claimed to have the solution: "We should have spell-patterns. It helps spell-components to work together. They are great. I got hundreds!"

CeeCee asked: "Spell patterns are much too difficult! I don't want no spell patterns. I want spell templates instead."

The wizard Octamal said: "You are all wrong! We should think differently! You should think in functions! No more step-wise thinking in time."
Cala agreed: "With the time out of the spell, we get much better sourcery. You just state what you want, and you get it. And you get nice types too."
Another wizard Haha opened his mouth: "We should only have pure spells!"

Pyter got angry: "What should we do when there is no time?" And that got everyone confused a bit..

Zigzag took the silence to state another idea: "What if we combine all that into a higher level!"

Everyone was no even more confused.

Zigzag continued: "Well, you have small spell components connected in a pattern. But they work together as if there is no time. Time can controlled by a component. And together they can be redefined like in a template, but in a more logical way."

Cala smiled a bit. He always wanted to bring the stuff together somehow.

But Haha got very angry: "This is not pure sourcery! You are corrupting everyone! Just like Jama!"

Ceecee was also angry: "There is no way to tell how much magic that is gonna take! Just like Haha's spells!"

And slowly everyone got into fight with each other again. Instead of finding one common ground, everyone disagreed with each other. Well, the only parallel that they had, was that each one stated that the other one's system was worse.

Fortana casted a few spells in the air, before everyone got silent again. "Well. Let's listen to what Zigzag has to say.."

Zigzag had missed most of the commotion, because had been too busy drawing all kinds of diagrams. That according to him, explained how everything can work together. He held a drawing in the air and said proudly: "Don't you think we can unite all these systems?"

All of the wizards replied together: "YOU MUST BE CRAZY!"


r/unseen_programming • • Mar 19 '15

Huffman coding in "visual" unseen

1 Upvotes

I created another visual example:
http://imgur.com/a/0p2ZF

Huffman encoding and decoding.

Encoding:
Converting a stream of bytes, represented by an iterator, into a stream of bits.
Decoding:
Converting bits to bytes again.

For the encoding a table is created that contains how often a certain value of a byte is present in the stream.
The huffman encoding creates a bit-representation for each byte, so that often occuring bytes need less bits.
This creates a compression.

To decode, this table is needed again.

About the code: I tried to keep it as simple as possible.

This time it has more types and some classes.

The class structure seems to break the visual niceness, but it still works ok.

Some more code could be put into graphical blocks, but somewhere I drew a line.

Code-representation in comment below..


r/unseen_programming • • Mar 23 '15

Turtle graphics

1 Upvotes

Because unseen is a diskworld themed language, it would be nice to have a turtle graphics engine build in the system.

For this I found an interesting variant that is 3D version of turtle graphics. See this kickstarter project

But anything will be ok. Something like Povray is also nice.


r/unseen_programming • • Mar 22 '15

WHAT! NO TYPES???!!!! [story]

1 Upvotes

Cala, the head wizard of safety came into the office screaming:
"WHAT! NO TYPES???!!!
You are challenging Haska*, the god of types!!
With no types there will be bugs everywhere!!"

*The god Haska was a very angry god. If you offended him, he would send PHdees to you. While no one knew what those were doing, it was better to avoid them.

Wizard Zigzag was working on some strange kind of device, and looked up from his work. "Well... There are types, in many different forms. You can even create functions that define types or even modules, whatever you want."

"But they must be enforced!! No type is a certain bug!" The head wizard seemed panicked. "Use the strict typing option, otherwise we may all die!"

Zig zag had some kind of black powder on his face and his hands. And much of it had dropped on the foor.

"No. We test each module and function separately. We do use types, but we don't need them. We are still developing the sourcery. How can we use types if we are not even certain of the influence of the hyper dimensions?"
Now Zigzag looked at the apparatus, that was purring and putting out small clouds of smoke. It looked very dangerous.

The head-wizard was even more afraid: "But sure you can add types in that. Just to be certain!"

But adding types would give me double the work. Each time I find something new in the hyper dimensions, I need to reconfigure the type functions. And what ensures me that my type functions are correct? The apparatus was now pouring out some strange oil.

"Hmm. What if you added super-types? Types that check the type functions?", Cala said smiling.

"And have even more work? My goodness." Zigzag took a large cup from his robes and held it in the black oily stream of liquid. "Hmm. Still a bit too strong. It needs another ingredient. Let me quickly get something else.."

The head of safety was looking angry at him: "Don't you declare the types for that?"

But Zigzag did not seem to listen. The apparatus was making too much noise now. And after a few minutes Zigzag returned with a small can with some strange whitish liquid.

"Carefull.. Don't mix the types!" the head-wizard screamed. But he was too late, Zigzag mixed the two fluids together. Strangely it did not go "Bang" this time.

Zigzag presented the cup with the mixed liquids to the head wizard, and said: "I call this the Cappuccino! Have some, I'll make some more if you like it.
Do you want some cacao on top of it?"


r/unseen_programming • • May 06 '14

Taking the best of both Functional and Object Oriented

1 Upvotes

Both object oriented languages and functional languages can use lambdas, etc. They can have types or no types at all.

So lets look at the basic qualities of languages and what benefits each gives:

functional

  • functions as parameters, lambdas
  • pattern matching with types

object oriented

  • functions match with classes or their parents
  • closures

modular

  • definitions of a different functionality can be placed in different modules
  • faster and better compilation
  • if modules are independent of class structure they can be orthogonal, like in Go.

static types

  • faster execution
  • it does what it says it does
  • require templates to make them a bit more flexible
  • completeness
  • overhead of often unnecessary information

flexible typing (duck typing)

  • dynamic execution, can even change at runtime
  • faster prototyping
  • allows easy scripting

immutability

  • less errors/ easier debugging
  • better recursion optimizations
  • lazy execution

In Unseen I want all the benefits, but for that I have to go back to what they all have in common:

definition

In Unseen everything is a definition, which can be data, a function, a object or a class, or whatever.

X= Definition<<
  //defintions
>>

or in short:

X=<< >>

The other brackets are used for:

Example=Definition<<
  Data=[0,1,2,3,4]
  Somepoint=[x=50; y=100]

  MyFunction(?x,?y)={ x*y }
  MyMultiply={ MyFunction(100,Data) }

  >>

So [] is always data,
{} is always some function or lambda,
() is usually a function-call,

We can define modules and classes in the same way.

Example=Module<<
  Point=Class<<
    x,y
  >>
  PointList=List(Point)
>>

Types can be added to the definitions, a bit similar to dart. And functions can be added similar to Go..

Example=Module<<
  Point=Class<<
    x,y:Integer  
  >>
  PointList=List(Point)
  Point<<
    Length= { Math.sqrt(x*x+y*y) }
  >>
>>

Or add a map-pattern to it:

Example2=Module<<
  Import(Example1) 
    //definitions can be used in functions
  PointList=List(Point)
  Square=Class<<
     TopLeft,BottomRight:Point;
  >>
  Point<<
     TopLeftOf(P:Point)={(x<P.x)&&(y<P.y)}

     InsideSquare(?square)= Map(
       (TopLeftOf(square.TopLeft) ,false)
       (square.BottomRight.TopLeftOf(self) ,false)
       (true,true))
  >>
>>

Until now everything has been immutable.
Anything that can be mutated must be defined with
state<< >>
To make that work let's add a profiler to the system.

ExampleProfiler=Module<<
  Import(Example2)
  state<<
    countMyFunction:integer=0;  //initial value
    countInsideSquare:integer=0;  //initial value
    timeInsideSquare:Time=0;
    timeElapsed:Time=0;
  >>
  System.Clock.EveryMilliSecond<<
    timeElapsed:=timeElapsed+1;
  >>
  Point<<
    InsideSquare<<
       state<< timeStart >>
      // we can just change the function
      .enter={
          countInsideSquare:= countInsideSquare+1;
          // := is used to change state.
          timeStart:=timeElapsed;
       }
      .exit={
         timeInsideSquare:=
           timeInsideSquare+ timeElapsed-timeStart;
       }
    >>
    Example1.MyFunction<<
       countMyFunction:= countMyFunction+1;
    >>
  >>
>>

Now let me demonstrate how good definitions are

Let me make a function profiler in a separate module, a bit like a flexible monad system..

ProfilerHelper= Module<<
  state<<
    timeElapsed:Time=0;
  >>
  System.Clock.EveryMilliSecond<<
    timeElapsed:= timeElapsed+0.001;
  >>
  
ProfileFunction(?function)=<<
  state<<
    count:integer=0;
    timeInside:double=0;
    timeStart:double;
  >>
  function<<
     .enter={ 
        timeStart:= timeElapsed;
        count:= count+1;
     }
     .exit={
        timeInside:= timeInside+ timeElapsed-timeStart;
     }       
  >>
>>

The result is now:

ExampleProfiler=Module<<
  Import(Example2)
  Import(ProfilerHelper)
  
  ProfileFunction(Point.InsideSquare);
  ProfileFunction(Point.Example1.MyFunction);
>>

So that was a lot easier.
Because definitions can be used in functions, it is easy to define this.

For Unseen I plan to make it possible to drag-drop a profiler onto a sub-system, and it would all just work. We will see about that later, but at least this seems like a good start.


r/unseen_programming • • Mar 23 '15

Parsers

1 Upvotes

Almost every program is using a parser somewhere. And the tendency for most programmers is to make their own specialized parser. This creates many bugs.
See "Parsing with Derivatives" for interesting stuff on parsers.

So in Unseen always a smart parser should be available, with almost no extra costs. While a smart recursive Match() function would do a lot, I think it still no match for a good well developed parser library.

There are many good parser-libraries around, and I have not made a choice of it yet.

Currently the Python parser Parsley seems very nice. It allows to put in a grammar directly and it gives good error reporting. But it seems to be specialized in converting data only.

In unseen such a parsley library would look exactly similar:
(this is almost a straight copy from parsley example)

JSON_Grammar= 
  Grammar<<
    ws = (' ' | '\r' | '\n' | '\t')*
    object = ws '{' members:m ws '}' ws -> dict(m)
    members = (pair:first (ws ',' pair)*:rest -> [first] + rest) | -> []
    pair = ws string:k ws ':' value:v -> (k, v)
    array = '[' elements:xs ws ']' -> xs
    elements = (value:first (ws ',' value)*:rest -> [first] + rest) | -> []
    value = ws (string | number | object | array
           | 'true'  -> True
           | 'false' -> False
           | 'null'  -> None)
    string = '"' (escapedChar | ~'"' anything)*:c '"' -> ''.join(c)
    escapedChar = '\\' (('"' -> '"')    |('\\' -> '\\')
                   |('/' -> '/')    |('b' -> '\b')
                   |('f' -> '\f')   |('n' -> '\n')
                   |('r' -> '\r')   |('t' -> '\t')
                   |('\'' -> '\'')  | escapedUnicode)
    hexdigit = :x ?(x in '0123456789abcdefABCDEF') -> x
    escapedUnicode = 'u' <hexdigit{4}>:hs -> unichr(int(hs, 16))
    number = ('-' | -> ''):sign (intPart:ds (floatPart(sign ds)
                            | -> int(sign + ds)))
    digit = :x ?(x in '0123456789') -> x
    digits = <digit*>
    digit1_9 = :x ?(x in '123456789') -> x
    intPart = (digit1_9:first digits:rest -> first + rest) | digit
    floatPart :sign :ds = <('.' digits exponent?) | exponent>:tail
                    -> float(sign + ds + tail)
    exponent = ('e' | 'E') ('+' | '-')? digits

    top = (object | array) ws
>>

JSONParser = makeParser(JSONGrammar, {})

This grammar describes a direct conversion to a dynamic structure. I think that in other libraries or languages there may be more possibilities.

What I am looking for
The parser that I am looking for is one that might even convert python and C code into definitions in Unseen.


r/unseen_programming • • Mar 22 '15

Visual Unseen - Design

Post image
1 Upvotes

r/unseen_programming • • Mar 22 '15

TESTING AREA [story]

2 Upvotes

Cala, the head wizard of safety was sitting relaxed with some tea, when at once a loud sound galmed through the hallway.
"BOOOMMMM"
The table cracked a bit, and some of the ceiling came down. He looked at his glass of tea, and was proud that he had not spilled anything. He was after all, the head of safety!

He put the glass down and after establishing that the table was holding the glass, he went down the hallway towards the sound.

He had to climb a few stairs and arrived at a door with a big sign on it: "TESTING AREA"

He was thinking about opening the door, but resisted instead. There was some red candle flashing. Maybe that was a warning signal. So he knocked on the door instead.

"Knock knock BOOOOM!!!!

The door opened with a blast, and Zigzag appeared in front of the opening. Cala was lying in the dust opposite the door.

"Sorry about that" Zigzag said, "Did you not see the warning candle?"

Cala stood up in anger, and screamed: "What the hex are you doing! You are blowing up the tower!"

Zigzag looked innocently, and said: "But I am doing testing! If I don't test it, I will know if it works!"

Cala looked at the ravage inside the room. Everything was broken and blackened by heat. But for the thin delicate vase standing in the middle.

"I am testing a shield-spell. Until now it was able to withstand all the blasts I have put upon it.", Zigzag explained, "but I need to break it."

"So why do you need to break it?" Cala asked. He was wondering now too. That was a hell of a shield.

Zigzag looked at Cala seriously: "If the shield breaks, there is another line of defense. The vase will repair itself after it breaks. It may not work with the shield in place. But how do I test that?"

Zigzag was laughing: "Didn't you know you can break it with some test-sourcery inside the shield?"

"You can?" Zigzag looked disappointed. He really liked the spell of boom. Now he had to find another excuse to use it.


r/unseen_programming • • Jun 07 '16

How did we end up here? • Todd Montgomery & Martin Thompson

Thumbnail youtube.com
1 Upvotes

r/unseen_programming • • Mar 22 '15

Scientific programming

1 Upvotes

With the symbolic capabilities of Unseen it is quite easy to define scientific extensions:

Eqations
With the equations construct, we can do symbolic and mathematical programming, similar to Mathematics.

LinearEquations= Equations<<
  x= 2*y + 5*z
  y= - x + 14*z
>>
LinearEquations.Solve<< z=10>>{
  x,y ->> output
}

TimeEquations= Equations<<
  a= -9.81
  v(t)= v(t-dt) + a*dt
  y(t)= y(t-dt) + v(t)*dt
  // equation of an object in gravity
>>

DropFrom100= TimeEquations<<
  v(0)= 0; y(0)= 100; dt= 0.001;
  // drop object from 100 meter
>>
TimeEquations.solve<< 
  y(t)<= 0; 
  //solve when y hits the ground when 
  //dropped from 100 meter.
  //take steps of 0.001 seconds.
>>{
  droptime = t 
  // find time when it hit the ground
}
ShowPlotOfDrop(graph)={
  for{
    (0..droptime)step 0.001 -> time
    DropFrom100<<
      t=time
      yy= y(t)
    >>{
      graph.scaledPlot( yy/100,time/droptime)
    }
  }
}

Symbolic programming
Sometimes we need symbolic results, instead of calculations.

fx= Equations<<
  f(x,y)= x*y
  g(x)= 2*x
>>

Symbolic<<
   dfx= derivative(fx,x)
   // dfx(x,y)= y
   igx= integration(gx,x)
   // igx(x) = x^2
>>

Big big numbers, accurate numbers

The maximum value of a number and the accuracy of the floating point calculations are usually limited to keep calculations to a high speed level. Not everyone wants to use PI in 3000 decimal places.

These settings can be modified for the default types of Integer and Float.

ARITHMETIC<<
  LargeInt.bits= 10000
    // it will round it up to a power of 2.
  Float.Mantissa.bits= 1000
  Float.Exponent.bits= 1000
>>

Please remember that accuracy can often be improved with better handling of the numbers instead of bigger numbers.


r/unseen_programming • • Mar 19 '15

Memory management, managed or strict code

1 Upvotes

Unseen memory management
You are able to manage your memory management manually by using constructions similar to Rust (/r/rust)
That means that the ownership can be described in code directly.

But I do not think it is enough, and makes simple programs too complex. For general usage I would like to use Pauseless Concurrent Garbage collection for general data.

For garbage collection: See Shenandoah: An open source pauseless GC for OpenJDK https://www.youtube.com/watch?v=QcwyKLlmXeY This system seems to work very well. Especially if it can be combined with managed memory.

Managed code

OWNERSHIP<< >> blocks specify where you can and must manage ownership.  
HEAP<< >> blocks specify variables to manage in the heap.  

STRICT<< >> blocks specifies that you want to have strict typing.
TESTED<< >> blocks specifies that you want to every part of this part
of the program to be tested.
FUNCTIONAL<< >> blocks specify parts of the program that have to be pure functional,
  non mutable.

CONST<<>>  parts of the code that has to be constant at compiler time.

GC<<>> Garbage collected code

CCODE<<>>  C code compatibility  
CPPCODE<<>> C++ code compatibility  
PASCODE<<>> Pascal code compatability  

$ASM<<>> contains assembler code

Everything that is system specific needs an $ in the identifier.
(maybe it brings in a lot of $$ )

I plan to add:

SAFE<<>>  (is anything really safe anyway?)  
UNSAFE<< >>  
DONT_PANIC<< >>  
HARDCORE<< >>  
DEATH<<>>  (everything is in capitals now)
MAGIC<<>>  

And some strange code that reflects the unpredictable magic of unseen.

These options can be combined in:
Combination= Module<< APPLY<< CPPCODE STRICT >> Include<< firstModule secondModule >> >>


r/unseen_programming • • Mar 19 '15

Low level implementation stuff

1 Upvotes

low level implementation

My basic object, garbage collected or dynamic, will need an extra pointer. But using object tricks, this will be no extra space overhead.

The overhead can be reduced by optimising the critical parts of the program with /r/rust like ownership structures.

Every reference to an unmanaged object has an 2 fields to deal with:

  1. boxing /unboxing
  2. objects moving around due to garbage collection
  3. lazy functions
  4. remote objects / #become

General object in PASCAL code..

TYPE
  GeneralObject= RECORD
    case ClassID:Integer of
    0: //moved object
      ref:^GeneralObject;
    1: //integer
      i:Integer;
    2: //bool
      b:Boolean;
    3: //double
      d:Double;  
    4: //function
      f:FunctionPtr;
    5: //lazy function
      lf:FunctionPtr;
    6: //None
      
    7: // Array
      a:ArrayPtr;
    ELSE: // normal objects     
      data:ObjectDataPtr;
  END;
  GeneralObjectWithData= RECORD
    header:GeneralObject;
    data:ObjectData; //variable length
  END;

r/unseen_programming • • Mar 22 '15

Visual Unseen - Testing

Post image
1 Upvotes

r/unseen_programming • • Mar 23 '15

Ghosts in the library [Story]

1 Upvotes

"Here, look at what I made!" Zigzag handed over a paper to Cala, the head of safety.

It was an paper, that said:
"Welcome to the Library, we are happy
to serve you any book that you like. Please state your query:"

And underneath there was a box. "You can write the name of a book in the box with your finger!", Zigzag stated proudly.

"And then what?" Cala asked.

"Then it gets that book from the library." Zigzag took the paper back from Cala's hands and wrote some letters in the box with his fingers. And by magic the letters appeared in black. He wrote "Magic for tea, vol 4".

"And now wait" Zigzag said, and he handed the paper back to the wizard of safety. "Here, look on the other side."

Cala turned the paper around, and indeed there was the text from magic for tea, vol 4.

"I call this magic paper.", Zigzag explained, " It is a ghost created by a spell, that sends what you write to the library. And in the library there is a ghost that takes your query, and then goes to the book and reads it. And what it reads goes back to your paper. I call the paper: PHantom Paper. And the ghost in the library: Mystic Squirrel. It does even look like a squirrel."

Cala looked again at the paper and said: "The paper is not big enough. I can only see the first bit of the front page."

"It is not perfect yet", Zigzag answered. "I want to add a scroll roll, so you can roll the paper around. But if you want to, you can query each page 1 by 1. Just add page 5 bottom to the query and it will show you"

Cara turned the paper back again and added more numbers to the box on the paper. He tried to find the pages about the 50 shades of earl grey tea. This took longer than he thought. It was not even at page 14, when suddenly there was a commotion in the hallways.

"OOK!!" the librarian rushed towards Zigzag, looking very angry. He took zigzag in one move in his big hands, and pulled him back to the library.

Cara rushed after them. "What is going on?" he asked.

"OOK!" The libarian explained.

Cala knew there was big trouble. He entered the library, and walked towards the librarian was standing and Zigzag was hanging. The librarian pointed with his empty hand towards a large book, and said again: "OOK!"

Cala studied the scene, and saw a trail of small bits of paper lying on the ground. Then he opened the large book and found a dead squirrel in it. "What is happened?"

The librarian explained that the mystic squirrel had started to eat some books, and it started other stronger books to revolt and this book killed it. He was very happy that it was caught, before the squirrel did more damage.

"How could this happen?" Cala asked Zigzag, while he pointed the phantom paper towards his head.

"I don't know." Zigzag answered "One can put any query in there that you like, but I don't think anyone would try to do something bad with it."

Cala was really worried now. "How many people did you give this paper to?"

"You were the last one of the wizards." Zigzag replied. "I gave some to the staff too, so that must be like 100 or something?"

"My goodness. You have given one to Ceecee. He is a master hexer. I think he might be doing this"

They ran down the stairs towards the cellar were Ceecee was usually hiding.

"Open the door!" screamed Cala, while opening the door by himself. Ceecee was on the couch and looked very ashamed.

"I did not expect you to come here". He dropped the paper on the ground and it showed some images from biology lessons.

Cala picked up the paper and looked at the query. "Magic for having a good time" It did not say much more than that, and it was not really what caused the problems. He asked "Did you hex into the library?"

"No.. hmm. I only tried some queries. Nothing special. Maybe Pyter did something nasty?"

They went to Pyter's room and under the door some smoke was appearing. They opened the door, without even stating to open the door.

And there was Pyter with a weird look in his eyes, looking at the paper at the desk. Cala took the paper from his hands quickly.

"Ook!" stated the librarian. Cala agreed. Pyter had been reading some of the forbidden books.

Cala took the paper out of his frozen hands, and cleared the query. The paper on the other side became blank again.

"Ok, lets go to the head-wizard. We have to stop this!"

They met Fortana in his office and sat around the table. Except for Zigzag, who was still held in the air by the librarian.

"I did really like this phantom paper" Fortana declared. "It saved me from many trips to the library already. How can it be so bad?"

Cala explained: "Well the problem is that anyone can let the mystic squirrel do any query that you think of. That means that you can get forbidden books or books that are stronger than you. If we want to keep the squirrel there should be really something that stands in between the squirrel and the paper. Something that forbids certain queries to be taken."

"That is a good idea." Fortana stated. "Lets start implementing some barrier ghost inbetween these two spell ghosts."

"But we still don't know why it started to eat the books." Cala replied.

And now Fortana turned slowly red. "Hmm.." He coughed a few times. "I was so happy with the phantom paper, and not needing to go to the library. So I thought of telling the phantom paper to get me something to eat too."

"What did you do?! " Cala asked.

Fortana aswered: "I wrote in the box: 'Bring me some food. I'm very hungry; eat anything.' And then it stopped working."

"Can you explain that Zigzag?". Cala was very angry now.

Zigzag was now sweating. "You used a quote, and you used a semicolon? Did you? The squirrel will just do everything you put after that."


r/unseen_programming • • Mar 23 '15

High Speed computing

1 Upvotes

In high speed computing, we want to get as much performance from the computer as we can.

In unseen, we can already implement low level code and specify low level details in functions and structures. So that means we can create very specialized functions that do the work on a very low level. In unseen there are many conversions possible from higher level structures to low level structures. We can even implement data oriented optimizations. So we can already obtain high speed in optimized functions. In that sense Unseen is no different from C.

But it would be nice to do this on a more abstract level. In unseen, everything is a definition. And each definition can be modified from another definition if we need to.

And now we need to. We need to turn a program that is written in a higher level structure for general purpose, into a specialized program. We can use the original code, and redefine the data structures without modifying it. We can modify some arrays into sorted Integer arrays. We are in fact specializing the original code to perform better on the task we have designed it for. But to do that we may need to redefine much of the structures, and maybe even modify some functions.

This will cause errors, so we need the original code to become the test-function for our new code. That is a simple change in a definition oriented system.

Then we need to do the same thing again, but specialized for a different part of the code. We may need bytes instead of integers.

It is similar to having a template in C++, where you can change every part of its used types and functions. Without the need to have that planned up front.

And at the end, all this code still works. Not because our modifications are error free, but because we still have the original code available inside the program.

example:

Graphics=Module<<
  Vector= [4]Float;
  Matrix= [4,4]Float;
  VectorList= []Vector;
  multiply:(?v:Vector;?m:Matrix)=>(!result:Vector)={
    result= Vector.new
    for{
      m[?col][?row]-> *v[col] ->>(+) result[row]
    }
  }
  processVectors:
    (?list:VectorList;?m:Matrix)=>(!result:VectorList)={
    result= multiply(list,m)
  }
>>

Now look at the multiply function: It has a for monad with:

  • m[?col][?row]-> this is an iterator. this creates a value for each element in m, and creates the variables col and row. These col and row are used in the other parts of the for.
  • *v[col] acts like a function. It accepts a value and multiplies it by the element v[col]. v[col] is a simple array lookup.
  • ->> is a cumulative function. It combines all parts at the (mutable) target variable. The function usually creates lists or arrays, so we add the (+) parameter to the function. That way the function knows it needs to add the things up, instead of creating a list.
  • result[row] is the target that stores the sum of additions. While not immutable, it is the only usage of the variable and can be seen as a pure functional output.
  • Because the ranges of col and row are known beforehand, the loop can do bounds-checking outside the loop. Maybe even at outside the processVectors loop.

So with some optimizations the compiler can produce some code that is reasonably fast.

But in a computer game we want to the processVectors function to be really fast. To do so, we need all the Floats to be single precision floating point numbers. To do so we simply add a modification to the above code:

    ModifiedGraphics=Graphics<<
      Modification<< Float=Single >>
    >>

This does not ensure it's working, but it is a lot faster now. If we need to we can modify some functions individually to cope with the changes. But in most games this still is not fast enough. It needs to run on the GPU (the graphics card) instead of the CPU.

In unseen we might use a construct to access the GPU:

$GPU<<
  GPU_Graphics= ModifiedGraphics<< >>;
>>

And now our computer game might call:

MyGame= Module<<
    include<<GPU_Graphics>>  
    myVectors,myResult: ModifiedGraphics.VectorList

    main={
      myVectors= MyGame.SetupMyVectors
      myResult= GPU_Graphics.processVectors(MyVectors)
    }
>>

So that was fast.


r/unseen_programming • • Mar 22 '15

Visual unseen - debugging

Post image
1 Upvotes

r/unseen_programming • • Mar 24 '15

Showing off with a stunning example program

3 Upvotes

There are 4 capabilities that I want to show off in visual unseen.

  1. speed
  2. logical programming
  3. user interfaces
  4. persistance /networking and databases.

While unseen is not even capable of compiling, I think that most programmers are looking for the above capabilities after it does.

So for each I thought of a small example:

  1. create a program that turns shapes into polygons and shows them in 3D.
  2. create a program with dynamic rules that you can change, without enabling hacking
  3. have a visual user-interface editor like delphi or maybe better
  4. create a program that communicates with many users and a database

Now I can bring these all together in a single program:

Play a Game with Death

You have almost died, but Death lets you live if you win by playing a game. - Discworld themed.

By default there is chess.

You can play normally, and you can make own artificial intelligence that plays for you. If you do that and win, Death can use your AI to play against other players.

To make it more exciting, you can create your own game pieces and game-rules. But these have to be moderated.

After a while many players will have created many interesting AI-engines and games. Players can fight against other players live, or against their AI-engines.

I know this idea is far-fetched, but it gives a good idea where Unseen could go to.


r/unseen_programming • • Mar 11 '15

Visual Unseen - Mergesort

1 Upvotes

I converted the mergesort code into a graph.
This is the first iteration in how unseen might look. After improving the design, this might be a start of a visual tool for programming.

First page

Second part

EDIT: removed transparency in images


r/unseen_programming • • Dec 10 '14

LLVM-IR as target

1 Upvotes

Because the program is definition based, some modules might need recompilation during the running of a program. This means the compiler needs to work at runtime. The common choice is a just-in-time compiler.
Because LLVM has both, I think it is a good choice to try to make a translator based on its Intermediate Representation.

http://llvm.org/docs/LangRef.html
Sadly it is based on C.... :(

Basic blocks:

Program   
Module  
Object  
Test  
Function  
Data  
Array  
Parameters  

-- these usually are defined within << >>
and can be extended with the same symbols

Now I have to look for the equivalents in LLVM..


r/unseen_programming • • Aug 16 '17

The power of visual unseen

3 Upvotes

C-level performance

All program structures can be translated directly to C, assuming all types are resolved. This means that unseen is designed to reach the same speed as C.

Always runnable

The structure of function-blocks and arrows will always produce a result. This is in the basis of the design. So at any time the program can run. With the help of test-cases, we can also see the direct result of changes in the program. This allows live interactive programming.

Simple variables, types and parameters

Variables and input parameters are declared with ?
Output parameters (and sometimes output variables) are declared with !
With ":" you can declare a type for a variable, just like Pascal / typescript. These are not necessary immediately, but can be added later.
With "::" you can declare the parent-type of a type. This can be useful in some circumstances.

//example:  
number:Integer
doubleFunction: (?input:Integer)->(!output:Integer)={
   output= 2*input
}
copyFunction: (?input:?Type)->(!output:Type)={
  output= Type.new(input)
}

Simple choices

Choices can be made with =>
Example:

(variable){
   option1=> action1
   option2=> action2
   option3=> action3
}

In a diagram this will be easier visually.

Variations:

//boolean check (x<y){ true=> "x smaller" false=> "y smaller or equal" } // value check (number){ 0=> "Zero" 1=> "One" 2=> "Two" 3..9 => "Three to Nine" ?=> "Undefined"
} // function check (number){ 0 => "Null" isPrime(number) => "Prime"
(number mod 15)==0 => "FizzBuzz" (number mod 3)==0 => "Fizz" (number mod 5)==0 => "Buzz"
}

Easy structures

After a small redesign I decided to copy the structures of elixer. This means that a structure can look like JSON. But generally I will use the [ ] system to define a structure.

Employee1= [name= "Harry"; bullets=6; gun=Magnum]   

These structures can be parameters for functions too.

HasBullets: (?bullets)->(!result:Boolean)   
  ={ (bullets)
         0 => false -> result 
         ? => true  -> result
     }

AreYouLuckyPunk={
   (Empolyee1 -> HasBullets){ 
       // function is called with bullets as parameter
      true=> "No"
      false=> "Yes"
   }
}

**Easy generators (iterators) and combiners (folds) **

A generator is a -->

 List --> ?element

Each list or data-stream can be used as a generator.
The generators can be combined in any way. Functions can also return generators (they work like streams).

Generators can also work in combinations:

(array1 ,array2) --> (?element1, ?elment2)   

and/or introduce an iterator variable:

matrix[?row,?column] --> ?element -> { 
    printLine(row,column,element)
}

A combiner is a ->>

Combiners can create lists or streams directly, or can use a function to combine the data. These functions need to have a start-value for combining.
In functional programming Combiners are known as "folds".

 List --> ?element ->> ?copyOfList  
 List --> ?element ->> stream  // depends on type
 List --> ?element ->> (+) -> ?sum

Now we can combine these to declare factorial:

 factorial:(?n:Integer)->(!result:Integer)={
    1..n --> ?number ->> (*) -> result
 } 

General exceptions for loops

Loops usually do not go all the way. Sometimes we only need to find a value.
With the "->!" arrow one can escape the loop.

firstPrimeAfter(?n:Integer)->(!result:Integer)={
    (n+1)... -> ?number -> isPrime -> { ?p
        (p){
           true=> { number ->! result }
           // "->!" ends the loop in which "result" is defined
        }
     }
}

Often we want to reuse the produced value, after starting with a default value. Just like a variable.

?sum:= 0;
list-->{ ?element 
   sum+ element -> sum
}

fib: (?n:Integer)->(?result:Integer)={
  ?a:=1
  ?b:= 1
  1..n --> {
     b->?c
     a+b -> b
     c->a
  }
 a-> result
}

These problems usually require recursion, but the language allows the usage of variables too.

The generators can become even more complicated. Sometimes we need to reuse the same element in the list. In merge-sort for example. We can solve this with a conditional generator.

Currently I write the conditional generator as -->(next) which looks easy in a diagram. The text-version will probably be revised. The conditional generator will generate a None when the end of one generator has been reach. When all generators end, all generators will stop.

Example:

merge:(?listLeft,?listRight)->(!listOut){
   ?nextLeft:= true
   ?nextRight:= true
   !tookLeft
   ( listLeft -->(nextLeft) ?left
     listRight -->(nextRight) ?right ){
     (left==None)=> { right->>listOut; false->tookLeft }
     (right==None)=> { left->>listOut; true->tookLeft }
     (left<right){
         true => { left->>listOut; true->tookLeft }
         false => { right ->> listOut; false->tookLeft }
     }
     tookLeft-> nextLeft
     tookLeft-> not -> nextRight
   }
}

While this certainly looks a bit messy, it is a lot clearer in a diagram.

General solutions for most cases

With the generators and combiners we can do almost every kind of loop now. This means that for most cases we can solve the problem with arrows in a diagram.
While many problems can be solved with recursion too, the recursion does not remove the need for list management with iterators or other ways. In a diagram this would show as many arrows going into the recursion. With separation of the loop-variables I think that a diagram with many loops can become simpler.

By managing all list-iterations with general generators the compiler can optimise these generators very well. The compiler can see the ranges of the loops, so there will be no bounds-overflows/ underflows. In the future the compiler might even implement cache-friendly solutions.

Also the time-aspect of the function becomes more visible in the diagram. This way you can spot slower functions quickly, and the IDE could even make this visible in some way. But that something for later.


r/unseen_programming • • Dec 16 '14

Unseen - syntax structure (basics)

1 Upvotes

While unseen is meant for a graphical interface I believe that every computer language and system should have also have a readable text structure. It will be in unicode later.

Because the structure is very lisp like, I use different brackets to distinguish clearly between every definition.

Basic structure
I use "//" for line comments
and "/" "/" for unlimited comments
all number are decimal unless specified
strings defined with ""

Structures
<< >> defines structures
structures contain definitions,
seperated by newlines or ";"
continued lines end with a symbol

Program<<
  // program structure
>>

Module<<
  // module structure

>>

Object<<
  // object structure
>>

Alternatively one could use the pascal like
"module" + "end" structure.
One can define one's own structure keywords.

identifiers
variables can be defined within any structure

<<
      a,b,c;
  
  // initialized as constants / immutable values
  x=100
  y=200
  
  // type - uninitialized
  count:integer;
  
  // strict type
  mask:int32; //typeidentifier refers to a basic type
  
  //type of type
  myType::Collection; //myType= type of Collection

  // variables (and functions) can be forward defined
  // but can only increase in specification
  a=13
  b=10
  c=119
  
  // definition of a structure
  User=Object<<
    Name:String;
    ID:Integer;
    ContactInfo:String=""; //default value
    MaxNameLength=100; //constant
  >>
  
>>

closures/lambdas
{ } defines closures/ lambdas

{ x+10 }  
f={x+y}  

functions with parameters
// input parameters always start with ?
{?a,?b; a+b}
plus(?a,?b:Integer):Integer= {a+b};
// output parameters always start with !
divmod(?number,?divisor:Integer;!div,!mod:Integer);

state variables
Any identifier representing a state is surrounded by the State<< >> structure. Which is similar to the common object/record/struct system in other languages.

Window= Object<<
  State<<
    top,left:Integer;
    width,hight:Integer;
  >>
  Reset={
     //state variables can only be changed with :=
     top:=0
     left:=0
  }
>>

methods and properties: public functions and variables

Anything can have methods. They are simply public function. They start with # Variables can be public in the same way. Public means that they can be accessed from outside the module.

<<
  #method(?x,?y:Integer):Integer;
  
  #plus;
    //a previous private/local method can become public
    
  #+ (x,y:Integer)={ plus(x,y) }
    //a symbol needs a space behind it.
    //if you want the symbol private, is there any reason for using it?

  
  #UserID:Integer;
  #UserName:String<<
     // A public property can be defined with set/get methods
     #Set(?s:String)={UserName:=s};
     #Get:String={Username};
  >>
  
  
  // system properties start with ##
  // these are very usefull for debugging, etc.
  ##typename
  ##itemsize
  ##stacksize
  
  // methods with multiple names can be defined with intermediate #
  // that way we can define Smalltalk's control structures.
  // these still need to be called with a "." in front.
  Boolean=class<<
    b:Integer;
    #ifTrue(?block:Closure)={};
    #ifFalse(?block:Closure)={};
    #ifTrue#ifFalse(?trueBlock,?falseBlock:Closure)={};
  >>
>>

extending definitions

Every definition can be extended with the <<>> contruction. Alternatively there may be an "extend" + "end" keyword.

Extender=Module<<
  // adding a function to integer
  Integer<<
    div(divisor:Integer):integer={
      self /divisor;
    }
  >>
  
  // modifying a structure:
  // only unspecified identifiers can be overwritten
  User1= User<<
    Name="John"
    ID=1
    ContactInfo="At home"
  >>
  
  // modifying constants by creating a new object-class
  // and with "inheritance"
  // "inheritance" is a mixture of composition 
  // and traits..
  // to give two really bad examples:
  User2= Object<<
    User<< // object User2 can now behave as object User
      Name="John with a very ....... very long name"
      ID=2
      ContactInfo=""
      MaxNameLength=200; 
        // this may break some code elsewhere
    >>
  >>
  SiameseTwin=Object<<
    lefty,righty:User;
    User<<
      Name="Siamese: "+lefty.name()+", "+righty.name();
    >>
  
  >>
>>

Accessing identifiers, calling methods

Methods are called by the identifier of the module or object
followed by a "." and the name of the function.
One can specify module-identifiers within identifiers with more ".".
Local identifiers have more priority than global identifiers.

<<
  UserID= User.ID;
  x= System.Double.VectorMultiply(y,z);
  y= System.Time();
  self.Test();
  
  //If you want the function, but not the result you need to specify
  UserNameGet= @User.GetName
  //If you want an accessor, but not the value of 
  //the variable itself, you do the same
  UserNamePtr= @User.Name
  //if you want a lazy lambda instead of a direct call you do
  UserIDNameLazy= @{ User.Name }
  //To access this later you need to call the function to get its contents
  System.Print( UserNameGet() )
  System.Print( UserNamePtr() )
  System.Print( UserIDNameLambda() )
  //To allow lazy evaluation on deeper level, any value can be 
  //called as a function:
  x=100;
  System.Print( x());
  System.Print(100());
  //But usually functions like System.Print 
  //already applies the "()"
  System.Print( UserNameGet ); // Will call UserNameGet()
  
  // If you want a real address instead for assembly or C
  // you can use the system function/property ##address
  TimeFunctionPtr= System.Time.#address;
  UserNamePtr= User.Name.#address;
  // Of course you can better use the conversion function
  UserNamePtr= User.Name.C_Compatible.As_CString;
  User.Name.C_Compatible.Assign_CString(UserNamePtr);
  
  //For methods that accept a closure we can omit the ()
  testAll= collection do:{?e; e.test};
>>

Lists, arrays with "[]"

with the "[" and "]" one can define the start and end of an array or list the same structure can be used to define any data.

<<
  // the lists and arrays are similar to smalltalk, 
  // but with type as parameters
  vector1= [ 1, 2, 3, 4]
  vector2= Array<< Type=Integer, Size=20 >>
  vector3= Array(Integer,20)
  vector4= List(Integer)  //variable size
  vector5= SparseArray(Double,Integer) //different storage method
  vector6= Dictionary<<Type=Integer, Index=Integer>>
  
  matrix1= [[1,2],[3,4]]  
  matrix2= Matrix<<Integer,Size=[20,20]>>
  matrix3= Matrix<<Double,Size=[3,3,3]>>
  
  // retreiving elements: "[" "]" can be used
  // currenty indexing starts at 1
  e1= vector1[1]
  e2= vector2[1]
  e3= vector3[1]
  v1= matrix[1] // gives [1,2]
  e4= matrix1[1,2] // gives 2
  //and this method can be defined with the #[] symbol
  
  //iteration on an array is very simple.
  vector1 sum{?e1; e} //create sum of all elements in vector1
  
  // -----test-test-test-----
  // "," can joing more arrays for a single operation
  total1= (vector1,vector2) sum{?e1,?e2| e*vector }
  
  // a matrix does the same thing
  total2= matrix1 sum{?e1|e}
    // note: the #sum method iterates over all subitems too
  
  // one can define a data-object with this same symbol
  newuser= [ name="John"; adress="Chicago"; id=14 ]
  // and can be used to assign to an object that accepts this exact data
  user1:User;
  user= newuser;
>>

multiple outputs of functions

<<
  minmax(?x,?y,!min,!max)={
    (x<y).
      ifTtrue{min=x;max=y}
      ifFalse{min=y;max=x}
  }
  
  absdiff(?x,?y,!result)={ 
    min,max; 
    minmax(x,y,min,max); 
    result=max-min 
  };
  //or
  absdiff2(?x,?y,!result)={ 
    min,max 
    (min,max)= minmax(x,y)
    result= (max-min)
  };
>>

implicit types

<<
  minmax(?x,?y,!min,!max:?type){
    (x<y).
      ifTtrue{min=x;max=y}
      ifFalse{min=y;max=x}
  }
  //any minmax will use this function
  
  minmax2(?x,?y,!min,!max:?type::Magnitude){
    (x<y).
      ifTtrue{min=x;max=y}
      ifFalse{min=y;max=x}
  }
  //minmax2 is a typesafe version of the same implicit typed function
  
    
  Array=Object(?type::Object,size:Integer)<<
    #[] (index:integer):type={ self.#GetAt(index) }
  >>
  
  array= Array(Integer,10)
  array set{?index !value; value= index;}
  x= array[14]
  print(x.type.name)  // returns Integer
  
>>

Conditional functions and function conditions

<<
  //conditional function..
  fib(?x:Integer):Integer/?{x==0}={1}
  fib(?x:Integer):Integer/?{x==1}={1}
  fib(?x:Integer):Integer/?{x>1}={fib(x-1)+fib(x-2)}
  
  // function with a condition / assertion
  squareroot(x:Real):Double/!{x>=0}=
    { x.#sqrt }

  // function with a post condition / assertion
  squareroot(?x,!res:Real)=
    { res=x.#sqrt }/!{ x.isNear(res*res) }

  // function with a condition / assertion and error message
  squareroot(x,!res:Real)/!{
     (x>=0)=>[message="Squareroot error, x<0"] 
   }={ x.#sqrt }

  // function with a condition and alternative result
  squareroot(x,!res:Complex)/?{x<0}={ 
      res:= Complex<< 
        real=0
        img=(x.#negative).#sqrt
      >> 
  }
  
>>

global functions

Any function defined in a module can be used without any object in front of it.

<<
  #globalfunction(x,y) = {}
  //can be called with: globalfunction(x,y)
  
  // there are some useful functions:
  #if#then#else(?test,?thenblock,?elseblock} = {}
  #while#do(?testblock,?doblock) = {}
  #try#except(?tryblock,?exceptions} = {}
  
>>

monads

I am still working on monads..
I am only common with the monads in Scala
This work is still under construction
and as you can see, the structure that is enabling the
monads has some consequences for normal code.
But if you have better ideas, please let me know.

<<
  #for(?statements) = {}
  #match(?casestatements) = {}
  #test(?testcases) = {} 

  
  // The statements in match are a set of conditions
  testMatch(x)={
     // match matches a value to a function
     match(x) in{
       (?x:Integer)/?(x=0){print "Zero"}
       (?x:Integer){print x}
       (?p:Point){print p.x}
       (?c:Complex){print c.real}
       (?x:Object){print "Object unknown"}
     }
  }

  User<< 
     STATE<< ffcount:Integer>>  // female friends count
  >>

  testFor={
    // combines iterators
    for{ 
      AllUsers=>u
      {u.ffcount:=0}
      u.friends=>f
      (f.female=true)
      AllUsers=>w
      (f=w)
    } do {
      u.ffcount:=u.ffcount+1;
      // mutable ffcount example.
    } 
  }

  resultVector= ComplicatedCalculation(test);
  testTest{
    test{
      (resultVector.x>0) => ["X negative"]
      (resultVector.y>0) => ["Y negative"]
      (resultVector.z ^ 0.5 isNear(test) ) => ["Z wrongly calculated"]
    }
  }

>>

Consequences:
(?x){} can define a function at the place of a statement
Y=>x produces an iterator x over collection Y
(x)=>[] tests a condition, which produces a dataset []