FrenchGermanGreekHindiItalianJapaneseKoreanPortugueseRussianSpanish

Funk2: Causal Reflective Programming

Funk2: reflective programming language



Overview


    
Supported systems
The goal
How does it work?
Examples of causal reflective programming
Basic programming examples
Programming with primfunk funktions
Programming with ptype objects
Programming with primobject objects
Current plan
Society of Mind final project ideas
Downloads
Publications
Media presentations
Developers


Supported systems


    

Funk2 currently compiles on 32-bit and 64-bit Linux operating systems. 64-bit pointers are recommended because of the amount of memory needed for the reflective capabilities; a 32-bit machine is currently only able to index a few gigabytes of memory.



The goal


    

The goal of the programming language Funk2 is to enable reflective algorithmic tracing for large heterogenous control systems. A few point emphasized in the Funk2 programming language are:

  oLayered Critical Causal Reflection
  oEfficient and Robust Control
  oLearning by Credit Assignment
  oDivergent Solution Paths
  oIntricate Thread Control
  oGoal-oriented Learning


How does it work?

    

Examples of the most basic computational features include: (1) memory creation, (2) memory read, and (3) memory write. Tracing all causal relationships between these basic features allows tracing the context of all other programmer-defined semantic abstractions. All of these computational features create an intricate trace network of dependencies, automatically traceable and shared by many parallel threads of execution. Funk2 allows causal tracing to occur modularly to dynamically chosen parts of large commonsense-scale artificial intelligence projects. The resulting causal dependency trace networks can be processed by critical causal reflection threads.



Examples of causal reflective programming


    

Here is how to retrieve the creation Cause for any piece of memory ([], the value of the symbol nil, is the only thing that does not reference a piece of memory):

Note that in the Cause object there are multiple named slots holding information in the frame of the cause. The frames of a Cause are thread, env, name, and args. By default only 7 levels of recursion are printed to the screen. The symbol used for ending a recursion is the astrisk, *.In order to access the slots of an object, you can use funktions that are named to access and mutate objects. For example, the following example shows how to retrieve only the name and args slots of a cause object.


    in--> [let [[cause [cause-of 12]]] [cons [cause-name cause] [cause-args cause]]]
read> [let [[cause [cause-of 12]]] [cons [cause-name cause] [cause-args cause]]]
out-> 
[primfunk:read #xb7f03420]


Here is an example of how to remember the state of an object at specific historical points in time:


    in--> [globalize a [array-new 10]]
read> [globalize a [array-new 10]]
out-> 
[]

in--> a
read> 
a
out-> 
([] [] [] [] [] [] [] [] [] [])

in--> [tracing_on-set a t]
read> 
[tracing_on-set a t]
out-> 
[]

in--> [system_date]
read> 
[system_date]
out-> 
(date 1970 0 13983 6 29 7 526235)

in--> [dotimes [i 5] [array-elt-set a i [+ i 10]]]
read> 
[dotimes [i 5] [array-elt-set a i [+ i 10]]]
out-> 
[]

in--> a
read> 
a
out-> 
(10 11 12 13 14 [] [] [] [] [])

in--> [remember a (date 1970 0 13983 6 28 44 908595)]
read> 
[remember a (date 1970 0 13983 6 28 44 908595)]
out-> 
([] [] [] [] [] [] [] [] [] [])

in--> a
read> 
a
out-> 
(10 11 12 13 14 [] [] [] [] [])


Here is another example of how to remember the state of an object at specific historical points in time:


    in--> [globalize a [array-new 10]]
read> [globalize a [array-new 10]]
out-> 
[]

in--> [tracing_on-set a t]
read> 
[tracing_on-set a t]
out-> 
[]

in--> [globalize dates [array-new 10]]
read> 
[globalize dates [array-new 10]]
out-> 
[]

in--> [dotimes [i 10] [array-elt-set dates i [system_date]] [array-elt-set a i i]]
read> 
[dotimes [i 10] [array-elt-set dates i [system_date]] [array-elt-set a i i]]
out-> 
[]

in--> a
read> 
a
out-> 
(0 1 2 3 4 5 6 7 8 9)

in--> dates
read> 
dates
out-> 
((date 1970 0 13983 6 12 19 283811)
       
(date 1970 0 13983 6 12 19 561113)
       
(date 1970 0 13983 6 12 19 828195)
       
(date 1970 0 13983 6 12 20 94674)
       
(date 1970 0 13983 6 12 20 361727)
       
(date 1970 0 13983 6 12 20 629388)
       
(date 1970 0 13983 6 12 20 896560)
       
(date 1970 0 13983 6 12 21 163860)
       
(date 1970 0 13983 6 12 21 431032)
       
(date 1970 0 13983 6 12 21 699425))

in--> [let [[history nil]] [dotimes [i 10] [set history [cons [remember a [array-elt dates i]] history]]] history]
read> 
[let [[history []]] [dotimes [i 10] [set history [cons [remember a [array-elt dates i]] history]]] history]
out-> 
[(0 1 2 3 4 5 6 7 8 [])
       
(0 1 2 3 4 5 6 7 [] [])
       
(0 1 2 3 4 5 6 [] [] [])
       
(0 1 2 3 4 5 [] [] [] [])
       
(0 1 2 3 4 [] [] [] [] [])
       
(0 1 2 3 [] [] [] [] [] [])
       
(0 1 2 [] [] [] [] [] [] [])
       
(0 1 [] [] [] [] [] [] [] [])
       
(0 [] [] [] [] [] [] [] [] [])
       
([] [] [] [] [] [] [] [] [] [])]



Basic Programming Examples


    

Here is one straightforward way to write a "Hello world!" program in the Funk2 language:


    in--> [print 'Hello world!']
read> [print 'Hello world!']
'Hello world!'
out-> 
'Hello world!'


Here is another more advanced way to holla your planet:


    in--> [let [[planet 'Earth']] [format stdout 'Hello ' planet '!']]
read> [let [[planet 'Earth']] [format stdout 'Hello ' planet '!']]Hello Earth!
out-> 
[]


Here is how to define and subsequently call a funktion:


    in--> [defunk say-hi [x] [format stdout 'Why, hello there ' x '. It is really great to see you.']]
read> [defunk say-hi [x] [format stdout 'Why, hello there ' x '.  It is really great to see you.']]
defunk
say-hi [x]
out-> 
[]
    in--> [say-hi 'Marvin']
read> [say-hi 'Marvin']
Why, hello there Marvin. It is really great to see you.
out-> 
[]


Here is how to loop over a list of values:


    in--> [mapc [funk [x] [print x]] [list 1 2 3 #xFF 'dog' `[2 3]]]
read> [mapc [funk [x] [print x]] [list 1 2 3 #xff 'dog' `[2 3]]]
1
2
3
#xff
'dog'
[2 3]
out-> 
[]


Here is how to call our funktion above in a parallel thread:


    in--> [prog [thread &say-hi [list 'Gerry']] nil]
read> [prog [thread &say-hi [list 'Gerry']] []]
Why, hello there
out-> Gerry. It is really great to see you.
[]


Here is how to serially filter every element in a list:


    in--> [mapcar [funk [x] [+ x 10]] [list 1 2 3 4 5]]
read> [mapcar [funk [x] [+ x 10]] [list 1 2 3 4 5]]
out-> 
[11 12 13 14 15]


Here is how to concurrently filter every element in a list:


    in--> [parcar [funk [x] [+ x 10]] [list 1 2 3 4 5]]
read> [parcar [funk [x] [+ x 10]] [list 1 2 3 4 5]]
out-> 
[11 12 13 14 15]


The scheduler:global_scheduler variable in the global environment can be used as a reference to the global funk2 scheduler for the local machine. Processor information available from "/dev/proc" during funk2 initial bootstrap compile is available for all machines currently logged into the grid. Grid support is in development, this only shows this information for the local machine. Once support for multiple machines is available, this variable will change into a funktion that takes a machine-id as an argument and returns that machine's scheduler object.


    in--> scheduler:global_scheduler
read> scheduler:global_scheduler
out-> 
[scheduler
        
:processors ([processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x40a00960
                       
:threads        [[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]
                           &n