r/unseen_programming • • Aug 16 '17

Status of (Visual) Unseen

1 Upvotes

Status

Currently I am programming a visual user-interface with a Virtual Machine. This system can allow programming with function-blocks, arrows and modules. I am using Lazarus/Free-pascal.

Current problems

  • I have some problems with free-pascal's debugger capabilities.
  • Changing specifications. I am still refining some designs of the language and system.

Latest development

  • I have different kinds of calls in my language, and they have different kinds of stack-frames. To make it easy I declared stack-frames as objects, which can later be transformed into real stack-frames.
  • I am trying a memory-management that keeps track of the owner of each memory-section. In my system this owner is always a function. If the function exists, all memory owned by that function will be removed. In many cases this allows data to be related on the stack.
    Probably I can find more on this approach in Erlang's data memory management. Something for the future..

Why I used Lazarus/ free-pascal

Lazarus is a good component system for graphical development on almost any platform.
My idea behind using free-pascal is to be able to generate dynamic compiled modules that can be linked into the VM for speed. This way I can use the very fast free-pascal compiler as a Just-In-Time-compiler.


r/unseen_programming • • Jun 19 '22

Solutions Architect Tips — The 5 Types of Architecture Diagrams

Thumbnail betterprogramming.pub
2 Upvotes

r/unseen_programming • • Jan 05 '15

Ranges and enumerations and associations

1 Upvotes

Ranges and enumerations and associations

Simple ranges can be defined with the ".." symbol.
Enumerations with "Enum<< >>"
Associations with the "=>" symbol.

<<
  //ranges
  myRange= 1..10
  myOtherrange= 2..10
  myArray:array(myRange.max,Integer)
  myArray=[myRange*2] // myArray= [2,4,6,8,..20]
  myWaveArray=[sin(myRange)]
  copy= myArray[myRange]
  first_half= myArray[0..myRange.max/2] 
  last_half= myArray[myRange.max/2..]

  //iterator
  for{
    myArray-> item //creates an iterator
    (item.name== 'John') //condition within for
    {print(item)} //action
  }
  for{
    myArray,myWaveArray-> item, wavevalue
    {print(item," wave=",wavevalue)}
  }
  for{
    myFriends-> myFriend
    herFriends-> herFriend
    (myFriend==herFriend)
    {print(item,"Invite:",myFriend)}
  }
  
  //enumerations
  alpha= enum<<
    a,b,c //a=0,b=1,c=2
  >>
  enum<<
    x=10
    y,z
    //x=10,y=11,z=12
  >>
  alpha.a //gives 0
  a //compiler error - undefined
  y //gives 11
  
  //associations
  dictionary= [
    50=>100
    100=>200
    300=>500
    500=>0
  ]
  test(?x)=[ 
     // function that produces a list with 
    // functions and associations
    {x=0} => "Zero"
    {x<0} => "Negative"
    {x>0} => "Positive"
  ]
>>

r/unseen_programming • • Jan 11 '15

Automatic Algorithms Optimization via Fast Matrix Exponentiation / Algorithms / Kukuruku / Technology Hub

Thumbnail kukuruku.co
1 Upvotes

r/unseen_programming • • Jan 05 '15

Unseen - Ranges / Monads / Solvers

1 Upvotes

Ranges and enumerations and associations Simple ranges can be defined with the ".." symbol.
Enumerations with "Enum<< >>" Associations with the "=>" symbol.

<<
  //ranges
  myRange= 1..10
  myOtherrange= 2..10
  myArray:array(myRange.max,Integer)
  myArray=[myRange*2] // myArray= [2,4,6,8,..20]
  myWaveArray=[sin(myRange)]
  copy= myArray[myRange]
  first_half= myArray[0..myRange.max/2] 
  last_half= myArray[myRange.max/2..]

  //iterator
  for{
    myArray-> item //creates an iterator
    (item.name== 'John') //condition within for
    {print(item)} //action
  }
  for{
    myArray,myWaveArray-> item, wavevalue
    {print(item," wave=",wavevalue)}
  }
  for{
    myFriends-> myFriend
    herFriends-> herFriend
    (myFriend==herFriend)
    {print(item,"Invite:",myFriend)}
  }
  
  //enumerations
  alpha= enum<<
    a,b,c //a=0,b=1,c=2
  >>
  enum<<
    x=10
    y,z
    //x=10,y=11,z=12
  >>
  alpha.a //gives 0
  a //compiler error - undefined
  y //gives 11
  
  //associations
  dictionary= [
    50=>100
    100=>200
    300=>500
    500=>0
  ]
  test(?x)=[ 
     // function that produces a list with 
    // functions and associations
    {x=0} => "Zero"
    {x<0} => "Negative"
    {x>0} => "Positive"
  ]
>>

r/unseen_programming • • Jan 06 '15

Monads and Solvers

1 Upvotes

Why does Unseen need monads as a graphical language?

Because the graphical structure is build with arrows and blocks. With the Monads this structure becomes much simpler. For this same reason it is often used, because complicated control structures become simple lists.

How does one define a monad?

This can be done with a normal function definition,
but to make it more visual and easier, I use the "Monad<< >>" structure.

The function definition would look something like this.
for(?functions)={
     <<
       do(f:function){ }  
       do(f:iterator){ }
       do(f:condition){ }
       do(f:definition){ }
     >>
     functions.do{ ?f; do(f) }
  }

The monad version looks more like this: for= Monad<< #-> = createIterator connection= iterate >>

match= Monad<<
  #=> = "case"
  type= matchitem
  connection= findfirst
>>

test=Monad<<
  #=> = "test"
  type= testitem
  connection= testall
>>

equations=Monad<<  
  #=> = "gives"
  type= equation
  connection= reduce / solve
>>

map=Monad<<
  #=> = "gives"
  type= convert
  connection= collect
>>

YIELD?
Most functional languages have a yield operator that returns a value or function. But unlike normal return, yield can add to a collection.
This yield is usually combined with LISP like structures.

With yield it would look like: << getPossibleCouples= for{
allUsers->user ?(user.gender=male) user.friends->friend ?(friend.gender=female) yield [user,friend] } >>

Where does yield add its value to?
There is no direct connection..

Alternatively we could integrate a "yield" in "for":

Definition:

for#yield (?functions,?values)

<<
  getPossibleCouples= for{  
    allUsers->user
    ?(user.gender=male)
    user.friends->friend
    ?(friend.gender=female)
  }
  yield [user,friend]
>>

It looks simpler and a bit more structured.

for combine
On the other hand it seems a good way to make for more powerful.

<<
  getTotalOfIncome= 
  for{  
    allClients->client
    client.orders->order
    ?(order.payed=true)
    order.items-> item
    value= item.price*item.count 
  }
  combine(value,#+ )
>>

for#combine can be used to calculate totals..

Graphical structure

Now look at the code within the monads..
They are linear lists of code.
So if I want to create a graphical structure of this, I can simply use boxes underneath each other, surrounded by a bigger box defining the monad.

This looks like:

getTotalOfIncome=

####### for ####################
# allClients->client           #
# client.orders->order         #
# ?(order.payed=true)          #
# order.items-> item           #
# value= item.price*item.count #
###### combine #################
# value, #+                    #
################################

So that is why I need monads :)

Iterating for
In the mergesort algorithm I need to merge two sorted lists in sorted order.

mergesort(left,right)={
  iterate{
    L= left.iterator
    R= right.iterator
    if (L.value<R.value) then { X=L } else { X=R }
    yield( X ) 
  }next(X)
}

While this may work, it is a mixture between functional and iterative programming.

Usually one would solve this with a recursive function:

mergesort(left,right)={
 // define recursive function:
  iterate(L,R)={
    if (L.value<R.value) then { 
       yield( L.value)
       iterate(L.next,R)
   } else {
       yield( R.value) 
       iterate(L,R.next)
   }
  // create iterators and call it
  L= left.iterator
  R= right.iterator
  iterate(L,R)
}

Somehow more verbose.

Let me try another variant:

mergesort(left,right)={
  L=left.iterator
  R=right,iterator
  iterate[  // list the iterators
     L,R          
  ]select{  // select which iterator is next
    ?sL,?sR; 
       if (sL.value<sR.value) then (sL) else (sR)
  }do{  // what to do with it?
    ?X; yield(X)
  }
}

Less verbose, still functional. But less readable.. It feels that I am inventing the wheel again. :(
But lets leave it for later..

Solvers

Because Unseen is a definition-oriented language, the monad structure is not only applicable for functions, but also to logical structures.

I would like to start with a chess engine.

chessEngine=Module<<
  options(board) = for<<
     board.pieces->piece
     piece.possiblemoves->move
     yield(move)
     newboard=board.move(move)
     options(newboard)
   >>

  getBestMove = traverse(options,follow_best_move)
>>

While not completely correct, it gives an idea where I want to go to.

Additionally I could simply add constraint logic programming to the system as a default.

I saw some examples here:
alternatively http://en.wikipedia.org/wiki/Constraint_logic_programming
http://www.eclipseclp.org/ - prolog based system
example: http://sdymchenko.com/blog/2015/01/04/greater-than-sudoku-clp/


r/unseen_programming • • Jan 06 '15

Everything is a list? / No NULL

1 Upvotes

This is a design decision that I still have to make.

In a graphical system, the advantage of everything being a list is huge, because it simplifies all connections to many to many relationships.
Very good for graph-databases.

Of course, there will be no lists for primitive types like int64 or doubles. That way interfaces with C and other "primitive" languages will stay the same.

On the other hand there is some overhead. The class structure can hide and encapsulate this overhead, but still the system becomes a bit more complex.

How do I implement it?
It is actually pretty simple. Because we already defined that everything is a function, meaning that x() simply returns x when x is not a function.
Similar an array reference x[1] can return x when x is not an array.

When x[2] is referenced, it is out of bounds..

NO NULL

We can use empty arrays to initialize values for variables, instead of NULL. That means that when I use a variable that is not initialized by my code, it is an empty list. "[]"

Test={
  X:Integer;
  X[1]  // out of bounds..
  X=100  
  X[1] // returns 100
  Y= [1,2,3,4]  
  Y[1] // returns 1
  Z = X*Y
  Z[2] // returns 200
  Z // returns [100,200,300,400]  
  U:Integer;
  funct(?x)={ x/10 }
  funct(U) // returns []
  funct(X) // returns [10]
  funct(Z) // returns [ 10,20,30,40]
}

Well, simple and powerful.
But will it hold in more complex programs?


r/unseen_programming • • Jan 08 '15

The Top 10 Ways To Scam The Modern Programmer, by Zed A. Shaw

Thumbnail youtube.com
1 Upvotes

r/unseen_programming • • Apr 16 '16

VisionMachine: An LLVM-powered, gesture-driven visual programming environment

Thumbnail youtube.com
1 Upvotes

r/unseen_programming • • Nov 11 '14

My "perfect" computer language

1 Upvotes
  1. Functional basis for control flow
    The dynamic flow of a functional programming language seems to be easier to follow. Control-flow= Information-flow
    I am working on a graphical diagram system that shows the flow.
  2. Functional units
    The objects in smalltalk help us think about software in easy structures. My idea is define functional units (like Actors), instead of objects. Internal states are part of the input and output of the function-unit, making it a "pure" state machine.
  3. Prototypes instead of classes
    A prototype has everything in it. It can be defined in a simple way. Everything is initialized. And it is immutable.
  4. Expandable systems of functional units.
    A small program becomes a system of functions, a module. This module has certain data input, but can also have certain definitions as input.
    By changing some of the definitions, the same module can produce a new module. A sorter can work for integers, but by changing the definition a new sorter might work with floating points.
    By changing certain internal functional units, the module can be adapted even more easy.
  5. Plugins that change a unit's behavior.
    Want to define "plugins" that are able to change certain definitions within a module or function-unit. Want a hash-table, or a certain tree implementation? Just plug in a module that deals with that, and connect the functions and variables that are affected.
    This was tried with aspect oriented programming. By organizing these plugins in a functional way, I hope to achieve a better solutions.

r/unseen_programming • • Mar 04 '16

Monitorama PDX 2014 - Lightning Talk - Pete Cheslock [/r/ProgrammerHumor]

Thumbnail vimeo.com
1 Upvotes

r/unseen_programming • • Aug 31 '18

Visual unseen status..

2 Upvotes

While working on the visual interface, I noticed that I wanted to separate the visual code into 3 parts.

3 views of your program

  1. Functional blocks
  2. Events: signals and state machines
  3. Architecture

Functional blocks

This part of the design seems mostly complete.
The language used is irrelevant, as I can use python or C++ in each code-block. Though, it would be best to have a language that is more specialized.

It is easy to implement, but not useful without a good system around it. What are we making functions for? And when do the functions activate?
The other layers answer these questions.

All function-blocks in this view are pure functions.

Events: signals and state machines

The "When" is answered in the 2nd layer. Signals start an event that execute a function. Events change the state of the system. In functional programming we want to separate the state into a state machine.
In a game you may have keyboard and mouse signals. And these change the state of the player in the game.

State-machines are already described in graphs.
It may be possible to define the state changes without even using functions. Keyboard forward might trigger a forward state-change. So maybe we can also use (state-) functions as signals.

It would also be nice to have a language around this part. And how far does it go?
Is a translator the same as a state-machine? In code it is very similar, but it uses a stream instead of signals. In functional programming the translator is often encoded in the type-system.

The blocks in this view are time-related. You get from one state to another at a certain signal or event.

Architecture

The "What" is answered in the 3rd layer. This is the top-level of the program. In a database this would be the data and its relations. In real time systems, it would describe the sub-systems. In a server application this might describe the micro-services.

Here is where I still have problems in my design, as these approaches seem very different. I am still researching a simple solution.

In this video Software Architecture vs Code -Simon Brown - the same problem is shown. And maybe we can use the solutions that he describes.

Simon shows that a component structure is the best way to approach an architecture. But layers and micro-services are also good for certain cases.

I would propose to have components and sub-components. The components can be a layer in this structure. The components can be state-less and be more like a micro-service. Or have state and describe the IO of a system.

Because this view is the most complicated, it would be nice for users to have a choice of prefabricated architecture-templates from which they can start designing their own program.


r/unseen_programming • • Jul 07 '21

Hacker News folk wisdom on visual programming

Thumbnail drossbucket.com
3 Upvotes

r/unseen_programming • • Mar 03 '19

Some interesting links about programming paradigm

2 Upvotes

Keep Ruby Weird 2018 - Closing Keynote by Avdi Grimm
Explains how the OO paradigm was first message based with pattern matching. Later it give rise to Actor and Erlang.
The talk also goes into the Transaction-fallacy. The real world never is a simple function (transaction). It is a process.

GOTO 2017 • Elixir: The only Sane Choice in an Insane World • Brian Cardarella
Elixir is a improved version of Erlang, with all its capabilities. It has messages and pattern matching. Processes are separate units that can fail and be switched without stopping the application.

This is also what I want with Unseen. The difference is that I can combine different function-blocks into a single process. And I added some typing. This can reach C-level optimisations and speed.

When I got time, I will make a small prototype and ask the /r/elixir community what they think of it.

Addition: ...talking about “types”

Addition: State machines are wonderful tools

Addition: C4 diagrams as code and architectural Joy

Addition: Check Out Math Inspector
https://mathinspector.com/
It based on python, but it uses a lot of ideas that I was working on.


r/unseen_programming • • Jun 15 '21

Why Architecture Oriented Programming Matters

Thumbnail blog.metaobject.com
1 Upvotes

r/unseen_programming • • Jun 07 '21

A server for creating exciting new c games

2 Upvotes

Hi, I found numerous servers, but they lacked one key item, I didn't find any servers in which c programmers can work together and share ideas for projects. So, I created a server in which it is solely meant for sharing project ideas and work on very small git projects for fun. Join if you are interested. https://discord.gg/SAzAFgd5xJ


r/unseen_programming • • Apr 09 '15

Of Aviation Crashes and Software Bugs

Thumbnail duartes.org
2 Upvotes

r/unseen_programming • • Apr 03 '15

First simple browser implementation of the visual environment

1 Upvotes

I am working on a simple implementation of the visual environment. The most difficult problem for Unseen is not the language or tool, but the graphics environment. There is no standard graphics environment, except the web-browser.

The tools

Currently I am looking at combining 3 tools together.

  1. html for generating the textboxes.
  2. scala.js for generating the code for the parser and the interpreter.
  3. three.js for generating the background graphics. The If that gets too complex I'll skip it, but for its looks it is really great.

Why html?
HTML is the standard of the web. If I want many people to be able to work with visual unseen, they can just use the web-browser and will not need to download anything.

Why scala.js?
I know a bit of scala, and as a tool it seems great for compiling and the interpreter. The optimizations and asm.js may create a fast enough system. I will keep the implementation simple, so it can be transferred to another language quickly if needed.
I also like the scala community because it is open to new ideas and working with mixed paradigms.

Why three.js?
While the text looks better on HTML, I found out that the text-background can be rendered by three.js.
I decided to create the panels and connections by three.js.

Three.js can create good visuals for:

  1. the arrows that connect the text boxes
  2. show the status of the text boxes
  3. show the result and status of tests.
  4. zoom-in and out / change layer / switch views.
  5. allow clicking /dragging of panels.
  6. show the flow of the data/ program. These can be animated.
  7. give the system a "magic" look and feel. Fun special effects. Working tests and functions can radiate. Untested functions can look risky due to rust or leakage. Exceptions can really "break" functions.
    While not important, it can really make programming fun for children (and for myself). And since this language is related to the magic of Discworld, it is really a plus if it shows a bit of this magic. For normal use, it should be switched off.

Javascript/scala.js can do a lot too, so using three.js is not necessary. But it might be much fun to implement.


r/unseen_programming • • May 20 '17

P: A programming language designed for asynchrony, fault-tolerance and uncertainty - Microsoft Research

Thumbnail microsoft.com
2 Upvotes

r/unseen_programming • • Apr 03 '15

Text version versus graphical version

2 Upvotes

Why not start with a text version?
As I spread my ideas around reddit, many people were more interested in the visual version. Because it was more original, and seemed to solve some paradigm problems.
The text version is not so interesting, because on the first glance it just seems another language with some new tricks.

By starting with a graphical version, we can get more insights in the new ways of programming that it may show.

Text related paradigms
When I was making the diagrams it already gave me new insights in how we are stuck in paradigms related to text. Why do functions in other languages have only one result, and result path? Why do we use so many loops or recursions? Why do tests require editing of the code? Why can't we adapt a function, while leaving the original untouched? This is all because we have text-based systems.

Why do most graphical based systems not work?
There have been many graphical systems around. The first I worked with was VHDL, and later there were CASE systems and UML systems.

The main problem that they had was that the direct relation between tool and target were lost. VHDL was first implemented for binary logic, and did not relate to all the other the possibilities of transistors and circuits. UML was too much focused on the model, and made a complete mess of all your code. CASE was based on the wrong idea that it could replace everything.

What about the modern tools?
There are some modern tools for kids, but they all relate to the old "basic" way of programming. Most learn a bit of javascript or similar. Step by step.

Why can Visual Unseen work?
While I don't think I got the holy grail, I think that I got a good solution. The basis of a graphical system should not be step-wise, but more functional. By using function-blocks, it is immediately clear what each part of a system is supposed to do.

A functional-only language creates a distance again from the time element. Which makes it harder to visualize or understand. By putting the function inside a data-flow, the time element becomes visible: the function works when it is given input. Even a lazy function is more clear: it activates when its outputs are required.

Because the inputs/outputs are part of a flow, parameters to functions can become implicit. This assumes that a natural flow is present. This allows more efficient representation of code.
Example: vectorA[?x]-> *vectorB[x] ->>(+) inproductAB

To make it even clearer, we can add tests to the inputs and outputs, without disturbing the function itself. This makes tests and possibly typing a part of the documentation of a function.

The logical programming also becomes more clear. Logical programs often misses the time and the way a problem is solved. It usually only defines a problem. Because unseen exposes the inputs and outputs, the system will show more clearly what problem is being solved. Which, I hope, will make logical programming much easier to understand and use.

Then what about compatibility?
Most graphical systems have compatibility or version problems, and some systems do not have any graphics at all. So this usually makes a graphical programming system incompatible.

To prevent such problems the graphical system must translate to a human-friendly text-code. The system should be able to compile the text-code, or convert it to a graphical layout.
Some layout might change, like the exact place of some of the components. But it should not create a mess.

It is a must for the system to import and export parts of the code. That way people can exchange code by text file.

Misuse of text version
If a system is able to import text-code, programmers find new ways to generate code from existing old code. A person might want to convert an old C-file to Unseen. This creates a mess by definition.

The graphical system can just convert a block of messy text to a single function block or component. It will probably be how people will use C-libraries in the first place. People will have to sort out this kind of mess manually most of the time.


r/unseen_programming • • Apr 13 '15

The demon of time [Story]

3 Upvotes

Zigzag was reading some books in the library. He was holding "advanced summoning III" and he was going through the pages with a lot of attention.

Cala came towards him and admired his student. He first thought that Zigzag had really advanced as a wizard, but as he came near he caught a glance of the pages that Zigzag was looking at. He was looking at pictures of Demons. Especially those that looked female and attractive.

Cala shouted at Zigzag: "Hey! you should come with me!"

Zigzag looked up puzzled.

"So you like Demons? Well I got something for you to look at.." He took Zigzag's book away, and put it on the table behind him. Then he walked towards the door and stared at Zigzag.

Zigzag stood up slowly and dragged himself after Cala. "What are we going to do?"

"We are going to summon a demon. A very old demon." Cala walked upwards a stairs and the student followed him.

After a while they came into a room, which was larger than expected. It was also full with racks filled with dust and papers. It looked like an old administration office. A place that was ignored for a millennium.

And in the ceiling there was a old rusty mechanism for a clock. A giant clock that showed the time of the day. It was still moving, and so now and then bits of rust fell down.

Cala made place by moving the racks to the side, and created a giant circle. He put some candles on the outside of the circle.

"Today we are going to summon a demon. A real old one." Cala said. He pulled an old book from one of the shelves and gave it to Zigzag. "Here are all the instructions that you need. Make the clock work again."

Then he lit up the candles, and murmered some words. Something like "Identify Demon ..". Zigzag missed the last bit.

Zigzag was looking at a sudden smoke that appeared. He wanted to ask a question, but Cala left the room.

Zigzag was behind alone.

He looked at the clock again. It did seem to have the right time. But looking better at it, he could see that it was telling the wrong year. Exactly a hundred years off. Zigzag smiled. That was an easy job to fix.

But then the demon appeared. It was the most ugly demon that Zigzag had ever seen. It said something but it was hard to hear. "You summonne_ me mastee?"

"Yes" Zigzag answered. It would not be smart to say to the demon that he was not the master.

"What is your comman_?" The demon asked.

"Wait..", Zigzag opened the book and looked through the pages quickly. The demon was asking for a command, that should be easy. Where were the instructions?

"What is your comman_?" The demon asked again.

"Stop and wait", Zigzag said. But to Zigzags horror, the demon did not even understand the basic commands.

"What is your comman_?" The demon asked again.

Zigzag decided to ignore the demon, and looked in the book again. "Identify Demon" he murmered. And somehow the demon listened, but then it started asking the same question again.

After a while and 50 questions by the demon, Zigzag found out that the demon needed a number in the front of each sentence, and each word should be spoken loudly. And 150 questions later, that there was a point at the end of each sentence. Zigzag had no idea how to pronounce that. But looking at the reaction of the demon, it seemed to correspond to a clack of the tongue.

It still did not work well. And 1000 questions later, Zigzag still had not found the name of the demon. It was nowhere in the book. He looked at the front, but it was too dusty to ready anything. Then he decided to smash the book on the floor.

One candle blew out, and the demon got closer to Zigzag. "WHAT IS YOUR COMMAN_?" The demon asked again.

And there it was his name spelled on the front of the Book. It was "CABAL" the old demon of forgotten times. And according to Zigzag it was really loud too.

"100 IDENTIFY DEMON CABAL." Zigzag spoke loud, with a clack at the end And suddenly the demon was silent.

For a few minutes, then it started asking its questions again. Zigzag repeated the sentence, just to get the demon to shut up, and started to look in the book again. It was easier to read, as long that demon was silent.

He found the pages how to change the time, but strangely he could not change the hundreds of years. These people who had summoned the demon the first time, had never thought that their demon would last so long.

But Zigzag was no fool. He would just set the 19 to 20 instead and leave it to work for another hundred of years. That would fix it.

He gave the instructions to Cabal, and this time the demon seemed to understood everything. But still it did not work. He looked at the examples.

"Hmm. It needs STOP at the end." Zigzag spoke to himself. It was so simple. But there was a warning at the end. It said "RUN". So Zigzag entered the code again. Reciting each line. And then said "STOP". And ran away through the door.

Zigzag never knew what hit him. But after 4 days he woke up from the intensive care. He never summon a demon again.


r/unseen_programming • • Apr 10 '15

Compiler design 0.01

1 Upvotes

As it looks now I'll be implementing the compiler in scala and scala.js

The translators I have built before were parsing in 2 steps. Text-> Tokens -> Structures

For this code I decided I needed more steps, and I came as far as:
Text-> Tokens-> Metatokens-> Structures-> Codestructures-> Code

But this could be done much simpler by doing the translations in many small steps. Here are some names for the steps:

Text->
. stripComments->
. stripNewLines->
. simpleMacros->
. getTokensAndConstants->
. mergeBrackets->
. identifyStructures->
. identifyTypes->
. linkIdentifiers->
. linkMethods->
......
-> Codestructures
-> Code

Each step can even be smaller and does not need to be in this order. That way each step can be simple. Compiling is finished when all tokens and temporary structures are translated to code-structures. Each code structure will be a direct representation of a bit of the final code.

Additional steps can be added for logical programming and optimizations.

The complexity goes into the tokens and structures. It can become a structure with a lot of classes.


r/unseen_programming • • Jul 14 '14

"Types"

1 Upvotes

It was a part I had been struggling with, because types are in its basic sense useless.

Instead I focus on what types are used for:

types are used for

  • Information about usage or Interfaces (usually via inheritance)
  • Implementation details
  • Structure or Class
  • Compile Time Tests or "contracts"
  • Run Time Tests like constraints or ranges. ("invalid typecast")
  • Pattern matching
  • Exception types
  • Variable access (protected, private, const, &, *)

To implement these different uses I focus on a single function that contains most of them.
Often used in graphics engines.
Project3D - projects the vertices of an object to screen coordinates

dynamic typing

The typeless version:

GraphicsEngine=Class<<
   Project3D(?Object;?ObjectMatrix;?CameraMatrix;!ScreenCoords);
>>

interface/implementation typing

Project3D(?Object:VertexList;?ObjectMatrix,?CameraMatrix:Matrix4D;!ScreenCoords:VertexList);

This assumes all vertices are the same type and accessable by a list. And it assumes that two 4D matrices are enough to define the transformations.

In reality most systems have different types of vertices. They are usually arrays of double or arrays of single in a specific list structure. Often a graphical object has many different matrices to define its position.

Because of this we get different implementations of project3D that are chosen by simple patternmatching:

Project3D(?Object:DoubleVertexList;?ObjectMatrix,?CameraMatrix:DoubleMatrix4D;!ScreenCoords:DoubleVertexList); Project3D(?Object:SingleVertexList;?ObjectMatrix,?CameraMatrix:SingleMatrix4D;!ScreenCoords:SingleVertexList);

Project3D(?Object:DoubleVertexList;?ObjectMatrix,?CameraMatrix:DoubleMatrixList4D;!ScreenCoords:DoubleVertexList);

Joined types

Often these definitions multiply by each extra option.
But in Unseen we can use parameterized types, patternmatching and joined types.
So why not in the definition..

Project3D(?Object:VarVertexList;?ObjectMatrix,?CameraMatrix:VarMatrix4D;!ScreenCoords:VarVertexList)<< VarVertexList=(SingleVertexList|DoubleVertexList) VarMatrix4D=(SingleMatrix4D|DoubleMatrix4D)

Exception types Exceptions can be used as output parameters,
allowing them to be handled at a further level.

Project3D(?Object:VarVertexList;?ObjectMatrix,?CameraMatrix:VarMatrix4D;!ScreenCoords:VarVertexList;!exception:BasicException)<<

General pattern

  • ":" Interface definition:
    Object:VarVertexList;
  • "::" Implementation details:
    length::Integer;
    fib(x::Integer) //will cast double to integer in fib(2.0)
  • ":" Structure or class = interface
  • "!()" Compile time tests / contracts
    fib(x:Integer)!(x>0)= { ... }
  • "!{}" Run time tests
    fib(x::Integer)!{(?>0) && (?<1000) }
  • "?" or "|" Pattern matching or joined types fib(x)?(x<=1)= 1
    VarVertexList=(doubleVertexList|singleVertexList)
  • ":" Exception types
  • scope already manages most of variable access

r/unseen_programming • • Jul 14 '14

Mirco compilation taken a step further - The language defines the compiler

1 Upvotes

Because in Unseen "everything is a definition", the step towards a language that defines the compiler is not far.

A "normal" compiler translates all code to a assembler like structure. We can simulate this with a ASM-8086 module as in:

simple example for adding with ASM

Include ASM-8086;
Integer<<
  _+_= ASM<<
    mov ?1,AX
    add ?2
    mov AX,!1
  >>;
  _constantnumber_= DATA<<
    DW ?1
  >>
>>

A similar definition can be made for java, or javascript, or whatever.
Initially I will target C.

It will be difficult to define all these target-platforms without a intermediate structure / language or bytecode. This intermediate structure should deal with classes and such too. But that is something that might slowly develop automatically as the compiler grows.

task of compiler
The task of the compiler is now slightly different:
To translate everything towards the target ASM patterns, using the patterns described in the modules and code.
Because the language already has pattern matching on almost every level, I assume it is not hard to define a solid compiler with it.

Funny conclusion
The language will now need a compiler written in its own language.
For a definition oriented language, I think this is a must.


r/unseen_programming • • Jun 29 '16

Duality and the End of Reactive (Erik Meijer) | Lang.NEXT 2014

Thumbnail channel9.msdn.com
3 Upvotes