Funk2 Documentation: How to Program in Funk2

Funk2 Documentation: How to Program in Funk2



Overview


    
Funk2 Home...
Developer Support and Mailing Lists
Supported systems
Example of defining and using a frame type
Basic programming examples


Developer Support and Mailing Lists


    

Because Funk2 is currently a very active research project, these documentation pages will not be able to explain the cutting edge features of the language and theory of causal reflection or reflective programming. For the time being, please feel free to email the author, Bo Morgan <bo@mit.edu>, if you have questions or bugs to report. There are publications about the intended uses for Funk2 here: Funk2 Home. If you have any questions, you are welcome to join our developer's mailing list, which is an open list that is meant for developers around the world to share their questions and experiences with the language and theory. You can join our public developer's mailing list here: funk2-dev Google Groups mailing list.



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.



Frame Definition Examples


    

Here is one straightforward way to create a new type of frame:


    in--> [deframe dog [] [color weight legs]]
out-> 
[]


We can create a new dog frame like this:


    in--> [new dog]
out-> 
[dog :type dog :legs [] :weight [] :color []]


We can put a new dog frame in a global variable like this:


    in--> [globalize the-dog [new dog]]
out-> 
[]


We can set the dog's color to black like this:


    in--> [set the-dog color `black]
out-> 
[]


We can see our globalized dog frame like this:


    in--> the-dog
out-> 
[dog :type dog :legs [] :weight [] :color black]


We can get the dog's color like this:


    in--> [get the-dog color]
out-> 
black


We can ask for brief documentation for any object like this:


    read> [doc the-dog]
[dog

  [dog legs []]
    - returns nothing.

  [dog weight []]
    - returns nothing.

  [dog color []]
    - returns a symbol (black).]
out-> 
[]


We can see our new frame type like this:


    in--> [lookup_type `dog]
out-> 
[primobject_type
  
:get legs    [funk :name legs :args [this] :is_funktional [] :documentation []]
  
:get weight  [funk :name weight :args [this] :is_funktional [] :documentation []]
  
:get color   [funk :name color :args [this] :is_funktional [] :documentation []]
  
:set legs    [funk :name legs :args [this value] :is_funktional [] :documentation []]
  
:set weight  [funk :name weight :args [this value] :is_funktional [] :documentation []]
  
:set color   [funk :name color :args [this value] :is_funktional [] :documentation []]
  
:variable parents []
  
:variable type    primobject_type
  
:execute new     [funk :name new :args [] :is_funktional [] :documentation []]
  
:execute is_type [funk :name is_type :args [exp] :is_funktional [] :documentation []]]


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.']]
defunk
say-hi [x]
out-> 
[]
    in--> [say-hi 'Marvin']
Why, hello there Marvin. It is really great to see you.
out-> 
[]




Basic Programming Examples


    

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


    in--> [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 '!']]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.']]
defunk
say-hi [x]
out-> 
[]
    in--> [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]]]
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']] []]
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]]
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]]
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
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 *]
                                        
[thread
                                          
:program_counter    *
                                          
:stack              *
                                          
:iter               *
                                          
:env                *
                                          
:args               *
                                          
:return             *
                                          
:value              *
                                          
:trace              *
                                          
:critics            *
                                          
:cause_reg          *
                                          
:keep_undead        *
                                          
:parent_thread      *
                                          
:parent_env         *
                                          
:execute_mutex      *
                                          
:last_executed_time *]]
                       
:pool_index     []
                       
:desc           0]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x41401960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           1]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x41e02960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           2]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x42803960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           3]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x43204960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           4]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x43c05960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           5]]
                     
[processor
                       
:mutation_mutex [mutex]
                       
:scheduler      [scheduler :processors *]
                       
:pthread        #x44606960
                       
: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 *]]
                       
:pool_index     []
                       
:desc           6]]
                     
[processor :mutation_mutex [mutex] :scheduler [scheduler :processors *] :pthread #x45007960 :threads [] :pool_index [] :desc 7]])]



λ

Blue%20Ribbon%20Online%20Free%20Speech%20Campaign