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 |
|