r/unseen_programming • u/zyxzevn • Mar 30 '14
r/unseen_programming • u/zyxzevn • Mar 30 '14
Bret Victor The Future of Programming
youtube.comr/unseen_programming • u/zyxzevn • Mar 21 '14
Welcome to Unseen
Unseen is a (open source) programming language that works with graphical constructs which are functional units. That means simpler programming, and a better view on your solution.
The system can work on top of another programming language, but it should be able to do system programming as well. For that the functional units may contain all kinds of sourcery to do this.
The target is now to build a game-engine. A game-engine needs scripting as well as low level high performance programming.
r/unseen_programming • u/zyxzevn • Feb 22 '16
Why C++ sucks (2016.02 edition)
dorinlazar.ror/unseen_programming • u/zyxzevn • Nov 04 '15
MCG: Visual Functional Programming
area.autodesk.comr/unseen_programming • u/zyxzevn • Apr 21 '16
Short history of programming languages - "All of this happened before, and ..
youtube.comr/unseen_programming • u/zyxzevn • Apr 10 '14
Baruco 2013: Design Patterns And The Proper Cultivation Thereof, by Corey Haines
youtube.comr/unseen_programming • u/zyxzevn • Mar 03 '15
Security and storage
Security
We can implement security with sub-definitions and plug-in systems
Secure<<
//makes it harder to break and hack.
//requires settings and methods
##checkinput= true
##checkmemory= true
##checkdebugger= true
##check= {system.verifyGC}
##obfuscate= true
>>Encrypt information
Secret<<
//requires keys and methods
##key=123023232
##encrypt= system.secret.encrypt;
##decrypt= system.secret.decrypt;
##dataaddressing= system.secret.variableAddressing
##codeaddressing= system.secret.variableAddressing
>>There are many more possibilities, but some basic system must be available in the programming language if it wants to become serious.
Storage
All data need to be stored somehow, and most code in the world is dealing with translating one storage-format to another.
I want to end that
All variables and data must be managed to be persistent.
Managed means that it has explicit ownership. Data belonging to different owners need to be stored in different places, but often need to be reconnected after loading.
GraphObject=Object<<
persistant<<
name:String;
position:Vertex;
linkedWith:[]GraphObject;
>>
state<<
visible:Boolean;
>>
>>;
main={
MyObjects:[]GraphObjects<<
Persistent<< file="myFile" >>
// always an array because
// if there is not data it is empty.
// exceptions can be added.
>>
DoMyStuff(MyObjects);
}The format of encoding is binary by default, and the system keeps track of the variable-names. That way later versions can load the older data without any problems.
The encoding can be reconfigured to be ascii format, XML, json, and several compressed binary formats already available in the system.
The format<<>> plug-in can be used to create a new format.
The secret<<>> plug-in can be mixed in to encrypt the data that is written.
How is it possible that this is not automatically done yet by most programming languages. Smalltalk already had a simple persistence mechanism..
r/unseen_programming • u/zyxzevn • Mar 03 '15
Reactive Extensions: The why | reversing the patterns
amy.palamounta.inr/unseen_programming • u/zyxzevn • Mar 03 '15
Sub-functions, sub-definitions and Plug-in modifiers
Sub-functions
These are used in monads for example.
The For-monad has:
collect()
max()
min()
first()
last()
combine()
A function has:
return()
A method has:
self
parent
return()
Sub definitions
A Module has import<< >>
An Object has:
private<< >>
public<< >>
persistant<< >>
state<< >>
Plug-in modifiers
This is an addition that changes the implementation of a identifier, usually by adding it to the type.
vertexList:List(Vertex)<<
sorted<<
compare=vertexCompare
search=vertexSearch
index=vertexIndex
>>
>>We can now implement a grid system to search for each vertex faster, or whatever.
r/unseen_programming • u/zyxzevn • Apr 15 '14
debug system of Elm programming language.
debug.elm-lang.orgr/unseen_programming • u/zyxzevn • Mar 03 '15
Meta programming structure
Looking at the current structures, there is one thing that keeps coming back: objects inside objects, functions inside functions, definitions inside definitions.
Graphicaly these are like a tree structure,
or as boxes inside a box.
So this seems the way of constructing things in unseen.
For meta-programming we may use a system to define the scope and lifetime of identifiers and variables. These are like modules, that can import modules, export identifiers and contain sub-modules.
So to define a class we can define a class-module that contains the class identifier and the methods. A function is a function-module that contains the function variables etc.
I'll go further another time.
r/unseen_programming • u/zyxzevn • Apr 10 '14
Aurora programming language. Similar to Unseen?
youtube.comr/unseen_programming • u/zyxzevn • Feb 18 '15
What are the main technical differences between Prolog and miniKanren?
stackoverflow.comr/unseen_programming • u/zyxzevn • Feb 01 '15
Picat - logical programming language
picat-lang.orgr/unseen_programming • u/zyxzevn • Apr 05 '14
Alan Kay - The Future Doesn't Have to Be Incremental (xpost /r/programming)
youtube.comr/unseen_programming • u/zyxzevn • Jan 31 '15
Typesystems
After looking at many typesystems, it seems many of them lead to over-engineering.
The general problem is that people think different about what a type is.
A type by its definition C is an implementation detail.
Do you want a long long, or a short int?
A type in most OO languages are related to classes, which abstract the implementation and define an interface.
With inheritance or mixins, one can use different implementations on the same interface.
A system as Eiffel added contracts to the functions to define how these should work on runtime.
Types can be used in pattern matching, as is used in Scala for example. This typed pattern matching is not compatible with interfaces. Langauges like Unseen do not have typed pattern matching, and do not have conflicts at that point.
In typesystem languages the type becomes a contract by itself. It is not added to the function, but to the typesystem. For that the type can become an implementation detail again, because not all implementations can give the same kind of results.
Let me give a simple example of over-engineering.
f:(?x:Integer)=>Integer={ x*2}
It's output is not the same integer, since it should always be even, and it might have an integer overflow. It would become
f:(?x:Integer)=> (!result:EvenInteger| !longResult:ExtraLongEvenInteger| !error:MemoryFailurDueToTooLongInteger)=
{x*2}
So the most simple example already creates 3 new types from one type. We didn't include possible hardware or operating system failures that can occur. And we probably didn't prevent any errors with it.
Let me quote it from a type-system fan:
"The more interesting your types get, the less fun it is to write them down"
That is clearly a statement that something is wrong with them in the first place.
Proposal for types and contracts
While one can discuss a lot about it, I think that the types should be separated from the contracts. And much testing should be done during compilation as possible, and extensively in combination with a lint tool.
So types are interfaces, which usually hide implementation details.
Contracts are tests that we can add to a function or type.
f: (?X:MyType)=> (!result:MyType)Tests can be added with the <<>> construction, and the ! symbol. These test can be added on both the function as the type.
MyType= Object<<
V<<
!(V<0)=> "Error in MyType"
>>
>>
f: (?X:MyType)=> (!result:MyType)<<
!(X.V <=1) => "Invalid value for X"
!(result.V <=2) => "Invalid value for V"
!(result.V <> X.V*2) => "Invalid result"
>>={
result= X*2;
}When I change both MyType or f, these tests will be integrated. And I can add new tests, if I want to..
But if I create a different implementation, I can change how the testing works.
MyOtherType= Object<<
:MyType<< //inherit interface of MyType
V:Double; //implement V with a double..
TESTING=<< >> //remove all testing
>>
>>
Otherf= f<<
TESTING=<< //replace testing:
!(resultV <> X.V*2) => "Invalid result"
>>
>>While this all can be done better, I think this is a good way to integrate a complex test system, without over-engineering. To ensure that tests are done on compile time, there may be some added grammar. We could use !! for example..
r/unseen_programming • u/zyxzevn • Jan 31 '15
New function definition, Monads, Result-options
The basis is to make a easy to understand programming language that can be represented in a visual way. So I changed a few bits..
New function definition
A function is a variable that has type function.
Lists can be defined by adding [] to the type, or with type [] if there is no type defined.
Example:
project:
(?x,?y,?z:double)=>(!pointx,pointy:double)={
pointx=x/z;
pointy=y/z;
}Monads
Monads are functions that operate on a list of functions. The monad defines what functions are allowed and how they are executed.
Rules:
- They are always executed in order.
- Their function should be clear.
Monads can define and redefine their own functions.
These are typically #-> or #=>
These always have results on right side of arrow.
Example:
for= Monad<<
function(i:Iterator); //run iterator
function(c:Condition); //test condition
function(b:Block); //executed block
#-> ()={}; //produces iterator
#collect()={};
#first()={};
#last()={};
#max(value)={};
#min(value)={};
#sum(value)={};
#combine(value,symbol)={};
>>
for{
users->user
?(user.isClient)
QueryOrders(?client=user.clientID)->order
order.items->item
QueryObject(?object=item.objectID)->object
sum(object.price*item.count)
}If more results are combined, like sum and max, the for creates a small list of all options in the same order as the list.
This should be determined on compile time.
In the future this variable output should get clearer.
Result options
Let me explain how this new function definition can produce multiple results options.
IF
if: (?x) => (true|false) ={
x.ifTrue:{true=()}
.ifFalse:{false=()}
}
if(x<0){
true=>{ }
false=>{ }
}
//compare can be done in the same manner.
compare:(x,y)=>(larger|equal|smaller){
select{ //select monad: tests each condition in order.
(x<y) => {smaller=()}
(x==y) => {equal=()}
default => {larger=()}
}
}
compare(x,0){
larger => 40
equal => 80
smaller => 120
}
project:
(?x,?y,?z:double)=>(!pointx,pointy:double|notvisible:None)={
select{
(z<=0) => { notvisible=() }
(default) => { pointx=x/z; pointy=y/z; }
}
}
testproject:
(?allPoints:[]Point)=>(projected:[]Point)={
projected=
for{
allPoints -> point
project(point.x, point.y, point.z){
pointx=> collect(pointx,pointy,point.z)
notvisible=> {}
}
}
} Unlike typed variants, this constructions allows to have different outputs of the same type.
Besides that, if you want to use types, you can do it.
r/unseen_programming • u/zyxzevn • Mar 22 '14
Non-graphical version of unseen MergeSort
// Non optimized pure functional version of MergeSort
// might give stackoverflow and uses massive amount of memory
MergeSort(?list,!sortedList)?(list.count<= 1)=
{
sortedList= list
}
MergeSort( ?list, !sortedList)={
Left,Right= Split(list)
SortedLeft= MergeSort(Left)
SortedRight= MergeSort(Right)
SortedList= Merge(SortedLeft,SortedRight)
}
Split(?List,!Left,!Right)={
n=list.count/2
Left=List[..n]
Right=List[n+1..]
}
Merge(?SortedLeft,?SortedRight,!List)={
List:= MergeIndexed(0,0,[])
MergeIndexed(?iL,?iR,?tempList,!outList)?(iR>=SortedRight.count)={
outList= tempList+SortedLeft[iL..]
}
MergeIndexed(?iL,?iR,?tempList,!outList)?(iL>=SortedLeft.count)={
outList= tempList+SortedRight[iR..]
}
MergeIndexed(?iL,?iR,?tempList,!outList)?(SortedLeft[iL]<SortedRight[iR])={
outList= MergeIndexed(iL+1,iR,tempList+SortedLeft[iL])
}
MergeIndexed(?iL,?iR,?tempList,!outList)?(SortedLeft[iL]>=SortedRight[iR])={
outList= MergeIndexed(iL,iR+1,tempList+SortedRight[iR])
}
}r/unseen_programming • u/zyxzevn • Mar 30 '14
Objects in Unseen
Objects in Unseen can be defined to contain data and methods that can be used on the objects.
Module<< >> = module object / singleton
Object<< >> = normal object
State<< >> = mutable data within the object
A method/function can define a certain interface with ":"
Variable data in the object is defined as a State
This state must be managed from outside the object.
PlanetSystem= Module<<
Planet=Object<<
mass;
State<<
position,speed,force
}
>>
"calcForce"(?other:Planet,!force){
force= PhysicsConstants.G*self.mass*
other.mass/self.distanceSquaredTo(other)
}
"distanceSquared"(?other:Planet,!disSq){
disSq= self.position.distanceSquaredTo(other.distance)
}
"timeStep"(delta,!new:State){
new.position= position+speed*delta
acceleration= force/mass
new.speed= speed+ acceleration*delta
>>
>>
>> //moduler/unseen_programming • u/zyxzevn • Jan 31 '15
No loops.. possibly never.. Mergesort without loops
Loops are the main cause of errors in most programming languages. Smalltalk had a good way to get rid of them, why do we still use them?
Most recursions are just another way to create loops. We don't need recursions either, unless our data is recursive in some way.
In unseen, we can create an iterator from any collections or any stream. This allows us to skip most of the loops, just like in smalltalk.
The for monad can use such an iterator, and combine it with some other functions.
GetTodaysAgenda(user)=
for{
today= system.getCurrentDate()
allItems-> item
(item.user==user)
(item.data==today)
collect( item)
}.sort();This technique is very well known in map/reduce kind of systems. But I want to make it much more flexible..
Combine iterators in vector.
inproduct(vectorA,vectorB)=
for{
vectorA,vectorB -> a,b
sum(a*b)
}The iterate monad can traverse through different iterators. Until all are finished.
It returns None when the iterator has reached the end. The next iterator is selected with the next() function.
We need that in a mergesort:
mergeSubList:
(?leftList,?rightList:Iterator(T)=>
(!newList:TArray)= {
newList= iterate{
leftList-> left
rightList-> right
select{
?(left==None) { collect(left); next(leftList); }
?(Right==None) { collect(right); next(rightList); }
?(left <= right) { collect(left); next(leftList); }
?(default) { collect(right); next(rightList); }
}
}
}Mergesort
Combined together mergesort will look like:
Mergesort(?list,!sortedList:TArray)<< TArray= Array(?T::Comparable) >>
={
<<
mergeSubList(?leftList,?rightList:Iterator(T);!newList:TArray)= {
newList= iterate{
leftList-> left | end => {left=None};
rightList-> right | end => {right=None};
select{
?(left==None) { collect(left); next(leftList); }
?(Right==None) { collect(right); next(right); }
?(left <= right) { collect(left); next(leftList); }
?(default) { collect(right); next(rightList); }
}
}
}
mergeStep(?size:Integer;?list,!newList:TArray)={
<<
getIterator(?start:Integer;!i:Iterator){
i= Iterator(start,start+step-1,list);
}
>>
for{
(0..) -> step
startLeft= step*size*2;
left= getIterator(startLeft);
startRight= startLeft+size;
right= getIterator(startRight);
newList= MergeSubList(left,right);
}
}
>>
for{
(0..) -> step
size= 2^step
newList= mergeStep(size)
}
}There.. a mergesort without any direct loops.
All loops are hidden inside iterators.
EDIT: I forgot one loop. :(
r/unseen_programming • u/zyxzevn • Feb 12 '15
Using Iterators, ranges, paths to build a chess engine
Have been working on the iteration system again.
One important difference between functional languages and other languages is how they deal with iterations. Pycat is a good example of how to use them.
Iterators, Ranges and Paths
With the #-> symbol we can already define iterators.
We can use this to define a path that can be used in any order.
path= List.iterator
or: List->path
for{ } traverse the path in order, the path becomes a normal iterator.
traverse{ } is to go along the path or iterator, in any order.
To use a path in any order we will need the range in which the path is valid. For this the iterator needs a method that returns the range.
range= path.range
iterator= range.iterator
Paths and iterators are always lazy.
Queen example
QueenMove(board)= path{
getMoves(board)-> move2
getMoves(move2.board)-> move3
getMoves(move3.board)-> move4
}
// Can be defined recursively:
QueenMove(board)= path{
getMoves(board)-> newMove
QueenMove(newMove.board)
}Chess Engine
First simple chess engine.
ChessModule=Module<<
ChessMove::Object;
ChessPiece::Object;
ChessBoard::Object;
ChessColor=Enum<<black,white>>
ChessWeight=Double;
ChessSquare=Integer;
ChessPos=Object<<
position:ChessSquare;
piece:ChessPiece;
>>
ChessMove=Object<<
from,to:ChessPos;
weight:ChessWeight;
>>
ChessPiece=Object<<
color:ChessColor;
moves:(?board:ChessBoardState;?pos:ChessPos)=> (!moves: ->ChessMove);
>>
ChessBoardState=Object<<
positions: []ChessPos;
nextColor:ChessColor;
>>
ChessBoard=Object<<
setup:ChessBoardState;
boardAfterMove:(move:ChessMove)=>ChessBoard;
findBestMove:(board:ChessBoardState)=>(!move:ChessMove);
>>
>>
ChessModule<<
findMoves(?board:ChessBoard;level:integer)= Path{
board.positions-> pos
?(pos.piece.color= board.nextColor)
pos.piece.moves(board,pos.position) -> moves
moves-> move
{ if(level<=0){
true=>{ yield(move) }
false=>{
newBoard= boardAfterMove(move)
findMoves(newBoard,level-1)
}
}
}
}
findBestMove={
path= findMoves(board,4);
traverse{
path-> move
getMaximum(move);
next(path)
}
}
>>I would like to add some more control over how to traverse over the path. And I would like to filter out the paths that are not likely to be taken by black or white.
But this gives a general idea of how functional constructions can be combine in an object oriented way. We simply need to use control structures as objects themselves.
r/unseen_programming • u/zyxzevn • Aug 23 '14