Notebooks such as Jupyter give programming languages a level of interactivity approaching that of spreadsheets.
I present here an idea for a programming language specifically designed for an interactive environment similar to a notebook.
It aims to combining the power of a programming language with the usability of a spreadsheet.
Instead of free-form code, the user creates fields / columns, but these can be combined into tables and object classes.
By decoratively cycling through field elements, loops and other programming constructs can be created.
I give examples from classical computer science, machine learning and mathematical finance, specifically:
Nth Prime Number, 8 Queens, Poker Hand, Travelling Salesman, Linear Regression, VaR Attribution
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
Idea for ineractive programming language
1. Idea for Interactive Programming Language
Lincoln Hannah - July 2018
Notebooks such as Jupyter give programming languages a level of interactivity approaching that of spreadsheets.
I present here an idea for a programming language specifically designed for an interactive environment similar to a notebook.
It aims to combining the power of a programming language with the usability of a spreadsheet.
Instead of free-form code, the user creates fields / columns, but these can be combined into tables and object classes.
By declaratively cycling through field elements, loops and other programing constructs can be created.
I give examples from classical computer science, machine learning and mathematical finance, specifically:
Nth Prime Number, 8 Queens, Poker Hand, Travelling Salesman, Linear Regression, VaR Attribution
Input
Output
Name Formula Comments
X 5:9:2 5 7 9 Array 5 to 9 by 2
Xby2 2*X 10 14 18 increment by 1 if increment omitted
Y 4: { Y^2 < 30 } 4 5 {} indicates a do while condition
like a do while loop
Z 1:1000 1 2 3 4 5 996 997 998 999 1000
MyCol Data ABC Hello 123
Function Fn( Arg1, Arg2 ) Arg1 + 2 * Arg2 In-line function definition
Function fibonacci( n=10 ) MultiLine
1:n 1 2 3 4 5 11 12 13 14 15
fib fib.prev + fib.prev(2) 1 1 2 3 5 89 144 233 377 610
Return fib.last 610
fibonacci( 4:7 ) 3 5 8 13
My_Dict Dictionary
key 4:6 4 5 6
value Data four five six
X 5 7 9 5 7 7 9 5 7 9 Fields in adjacent rows (X and Y)
Y 4 4 4 5 5 4 4 5 5 5 whithout a specified join, does a cross-join.
Xby2 10 14 18 10 14 14 18 10 14 18 produces every combination of X and Y so
My_Dict( Y ) four four four five five four four five five five Can be used like nested loops
MyCol ABC ABC ABC ABC ABC 123 123 123 123 123
XbyY X*Y 20 28 36 25 35 28 36 25 35 45
Fn( X, Y ) 13 15 17 15 17 15 17 15 17 19
Multiple blank lines indicates end of
multi-line function
Values - First 5 Values - Last 5
Data keyword allows vaulues to be
entered directly
Default argument values (n=10)
allow example function output to be
shown within function definition.
Useful for debugging.
2. Outer_Join( X, Y ) 4 5 7 9
X 5 7 9
Y 4 5
Concat( X, Y ) 5 7 9 4 5
X_filled Str(X) 5 7 9 Manual1 haha
Y 4 2
CountX count( X ) 3
MaxX max( X ) 9
X 5 7 9
SumY sum( Y ) 9 9 9
SumXbyY sum( XbyY ) 45 76 81
FirstMatch( X ) <= 6 <=8 CatchAll
X_bucket_1st up_to_6 up_to_8 Some_Other
X 5 7 9
Y_bucket_1st up_to_6 up_to_8 Some_Other
AllMatch( X ) <= 8 <=10
X_bucket_All up_to_8 up_to_10
X 5 7 5 7 9
X_bucket_All up_to_8 up_to_8 up_to_10up_to_10up_to_10
AllMatch( X ) <= 8 <= 8 >8
Above.AND.AllMatch( Y ) ==4 ==5 CatchAll
lable A B C
X 5 7 5 7 9 9
Y 4 4 4 4 4 5
lable A A B B C C
I New MyClass( Arg1=1 ) 1
I.Arg2 1
I.Const 1.2
I.Out1 8.2
Id Generated automatically. Arg2 not
speified so gets default value from
class definition.
3. W New MyClass( Arg1=X, Arg2=Y) 1 2 3 2 4 12 18 7 14 21
X 1 2 3 1 2 2 3 1 2 3
Y 1 1 1 2 2 6 6 7 7 7
W.Out1 6.2 8.2 10.2 9.2 11.2 23.2 25.2 24.2 26.2 28.2
W.Out2 0.2 1.4 2.6 -0.8 0.4 -3.6 -2.4 -5.8 -4.6 -3.4
M1 New Matrix( nRows=3, nCols=2 ) 1
M2 New Matrix( nRows=1, nCols=2 ) 1 Alternate notatation
M1.Row 1 2 1 2 1 2
M1.Col 1 1 2 2 3 3
M1.Value Data 10 11 12 13 14 15
M2.Col 1 1
M2.Row 1 2
M2.Value Data 3 3
M3 M1.Product( M2 )
M3.Row 1 2 3
M3.Col 1 1 1
M3.Value 63 75 87
Class MyClass
ID ID-Generator 1
Arg1 Decimal 1
Arg2 Decimal 1
Const Static Decimal 1.2
Out1 Const + 2 * Arg1 + 3 * Arg2 6.2
Out2 Const * Arg1 - Arg2 0.2
Data keyword allows values to be
entered in data area
Static Data indicates cannot be
overridden when instantiated. Data
without Static are default values
only. Fields will be input (white)
Every class has an id. (like the
primary Key of a table) ID shown if
no field selected, as per Z and W
above.
Arguments set to columns / vectors
so a column of Ojbects created with
generated IDs - 1 to 21.
4. NameSpace MathLibrary
Class Matrix
ID ID-Generator 1
nRows Data 2
nCols Data 2
Row 1 : nRows 1 2
Col 1 : nCols 1 2
Row 1 2 1 2
Col 1 1 2 2
Value Data 0 0 0 0
Row==Col 1 2
Trace Value 0 0
Add Method returns Matrix
M2 Argument Matrix 1
Return New Matrix( nRows= This.nRows, nCols= This.nCols) 1
Error_If nRows != M2.nRows Error( "number of Rows must match to add Matricies" )
Error_If nCols != M2.nCols Error( "number of Columns must match to add Matricies" )
Row == M2.Row == Return.Row
Col == M2.Col ==Return.Col
Return.Value Value + M2.Value
Transpose Method returns Matrix
Return New Matrix( nRows = This.nCols, nCols=This.nRows) 1
Return.Row == This.Col
Return.Col == This.Row
Return.Value This.Value
Product Method returns Matrix
Right Argument Matrix
Return New Matrix( nRows= This.nRows, nCols= Right.nCols)
Error_If nCols != Right.nRows Error( "number of Columns of left matrix must match number of Rows of Right matrix." )
This.Col == Right.Row
Return.Value sum( This.Value * Right.Value )
Fields created within method only
visible within method (Privative
Errors produced if user tries to add
matricies of unmatched dimensions
Left, Right, Add automatically joined
on Row and Column Due to matching
Default values set in class definition
can be overwritten.
5. Class Primes
Is_Prime Method returns Boolean
x Argument Integer 32
i 2 : { i > sqrt( x ) } 1 2 3 4 5
Mod_x x mod i == 0 TRUE TRUE FALSE TRUE FALSE
x 1 >1
Return TRUE OR( Mod_x )
Nth_Prime Method returns Integer
n Argument Integer 5
i 1: {Count_Primes == n} 1 2 3 4 5 6 7
Count_Primes Is_Prime( i ) + Count_Primes.prev(First=0) 1 2 3 3 4 4 5
Return Last( i ) 7
NameSpace Poker
Class Card
ID ID-Generator 1
Suit Possible_Values Data 4 Hearts Diamonds Clubs Spades
Number Possible_Values Data 13 Two Three Four Five Six Ten Jack Queen King Ace
Class Hand
ID ID-Generator 1
C New( 5 ) Card 1 2 3 4 5
C.Suit Data Hearts Diamonds Clubs Spades Spades
C.Number Data Five Five Five Five Six
Four_of_a_Kind count( distict( C.Suit ) ) >= 4 TRUE
Three_of_a_Kind count( distict( C.Suit ) ) >= 3 TRUE
Pair count( distict( C.Suit ) ) >= 2 TRUE
Full_House Count( Distict( C.Suit ) ) >= 2 TRUE
Non static Data - set defaults to test
formulas