# Cultural Diffusion of Programming Languages

Model was written in NetLogo 5.0.5
•
Viewed 605 times
•
Downloaded 40 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

Info tab cannot be displayed because of an encoding error

## Comments and Questions

Please start the discussion about this model!
(You'll first need to log in.)

Click to Run Model

; A Model of Cultural Diffusion of Programming Languages ; Sergi Valverde and Ricard Solé ; May, 15th (2015) ; The array extension requires Netlogo 5.0 extensions [array] globals [ num-iter max-capacity census ] patches-own [ ; the programming culture of a developer is described by a list holding up to 'max-capacity' languages langj ] to setup set num-iter 0 set max-capacity 3 set census array:from-list n-values ( 1 + MaxLang ) [5] ; set empty lists ask patches [ ; set langj (list (1 + random MaxLang ) (1 + random MaxLang ) ( 1 + random MaxLang )) set langj (list) ] transfer_colormap end to plot-census clear-plot ; foreach n-values array:length census [?] let llista sort-by > array:to-list census foreach llista [ plot log ? 10 ] end to transfer_colormap ask patches [ let langs sort-by > langj let r 0 let g 0 let b 0 let len length langs if len > 0 [ set r (item 0 langs) / (1 + MaxLang) ] if len > 1 [ set g (item 1 langs) / (1 + MaxLang) ] if len > 2 [ set b (item 2 langs) / (1 + MaxLang) ] set pcolor rgb (255.0 * r) (255.0 * g) (255.0 * b) ] end ; Weighted random draw from a list, options: ; 1) Use the NetLogo/Rnd-Extension ; 2) http://stackoverflow.com/questions/22615519/netlogo-weighted-random-draw-from-a-list-how-to-use-rnd-extension to-report weighted-rand-index2 [ values probs ] let i -1 let found false let nc length probs while [(not found) ] [ set i random nc let p item i probs if ( random-float 1.0 < p ) or ( p >= 0.9999999999 ) [ set found true ] ] report i end ; this is executed in patch context to-report least-frequent-known [lan C ] ; langj census if C = 0 [ ; Is this a "Memento" world? report -1 ] if length lan = 0 [ ; An ignorant programmer? report -1 ] if length lan = 1 [ report 0 ] let prob map [ 1.0 - ((array:item census ?) / C) ] lan report weighted-rand-index2 lan prob end ; this is executed in patch context to-report most-frequent-known [ lan C ] ; langj census if C = 0 [ ; Is this a "Memento" world? report -1 ] if length lan = 0 [ ; An ignorant programmer? report -1 ] if length lan = 1 [ report 0 ] let prob map [ ((array:item census ?) / C) ] lan report weighted-rand-index2 lan prob end to adoption let check true ; Rule #1: Innovation if (random-float 1.0 < ProbInnov) [ ; check if this developer has some free memory slots if length langj < max-capacity [ ; discover one random language let l (1 + random MaxLang) ; is this new ? if not member? l langj [ set langj lput l langj ; update census[l] ++; array:set census l (array:item census l + 1) ] ] set check false ] ; Rule #2: Adoption if (random-float 1.0 < ProbAdoption) and check [ ; pick one random neighbor let n one-of neighbors ; source(n) knows at least one language let langv [langj] of n if length langv > 0 [ ; compute normalization constant let C (sum array:to-list census) ; learn the most frequent language let lv item (most-frequent-known langv C) langv ; check whether lv is a new language for the target j if not member? lv langj [ let lenj length langj if lenj >= max-capacity [ ; random replacement let i random lenj let f item i langj set langj remove-item i langj array:set census f (array:item census f - 1) ] set langj lput lv langj array:set census lv (array:item census lv + 1) ] ] set check false ] ; Rule #3: Language Forgetting if (random-float 1.0 < ProbForget) and check [ ; at least knows 2 different languages (one will be forgotten) if length langj > 1 [ ; compute normalization constant let C (sum array:to-list census) ; remove the least frequent language let i (least-frequent-known langj C) let f item i langj ; update census[l] --; array:set census f (array:item census f - 1) ; forget set langj remove-item i langj ] ] end to go ; pick a random developer ; let p one-of patches ; ask p ask patches [ adoption ] transfer_colormap plot-census set num-iter num-iter + 1 end

There are 2 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

A cultural diffusion model of programming languages.pdf | This is the paper were the model was first described: Valverde, S., Solé, R. V. (2015) "A Cultural Diffusion Model for the Rise and Fall of Programming Languages" Human Biology 87(3), 224-234. | over 8 years ago, by Sergi Valverde | Download | |

Cultural Diffusion of Programming Languages.png | preview | Preview for 'Cultural Diffusion of Programming Languages' | over 8 years ago, by Sergi Valverde | Download |

This model does not have any ancestors.

This model does not have any descendants.