View define-pattern-example-of-use.rkt
(define-pattern (inner a) (list a (... ...))) ; This line defines a new pattern
(define inner-lists (list (list 1 2) (list 3 4))) ; Same as (define inner-lists '((1 2) (3 4)))
(match inner-lists
[(inner (list _ x _ ...)) (printf "x = ~a\n" x)]) ; Matches inner lists, returns (2 4)
View pattern-extension-macro-simple.rkt
(define-syntax-rule (define-pattern (name args ...) substitution)
(define-match-expander name
(syntax-rules ()
[(_ args ...) substitution])))
View pattern-extension-simple.rkt
(define-match-expander inner
(syntax-rules ()
[(inner x) (list x (... ...))]))
View generator-example.py
def squared(coll):
for x in coll:
yield x ** 2 # "yield makes this a generator
for x in squared(range(10)):
print(x)
View generators-to-the-rescue.py
from neo4j.v1 import GraphDatabase
import csv
def query(cypher):
with GraphDatabase.driver("bolt://localhost:7687") as driver:
with driver.session() as session:
with session.begin_transaction() as tx:
for record in tx.run(cypher):
yield record # <- Generator here!
View deep-nesting-example.py
from neo4j.v1 import GraphDatabase
import csv
cypher = "MATCH yadda-yadda-yadda"
header = ["x", "y"]
with open(file, "w") as output:
writer = csv.writer(output)
writer.writerow(headers)
with GraphDatabase.driver("bolt://localhost:7687") as driver:
View example-of-new-pattern.rkt
#lang racket
(define-match-expander aba
(syntax-rules ()
[(aba a b) (list a b a)]))
(define some-list (list 4 3 4))
(match some-list
[(aba x y) (printf "x = ~a, y = ~a\n" x y)])
View destructuring-with-match-define.rkt
#lang racket
(define some-list (list "b" "a" "c"))
(match-define (list xs ... x) some-list)
(printf "First elements are ~a\n" xs)
(printf "Last element is ~a\n" x)
View matcher-example.rkt
#lang racket
(define some-list (list "b" "a" "c"))
(match some-list
[(list "a" x y) (printf "~a, ~a\n" x y)]
[(list "b" x y) (printf "~a, ~a\n" x y)])
View igraph-degree-distribution.R
library("igraph")
library("poweRlaw")
library("ggplot2")
# Just loading my data
edge_list <- read.csv("edge-list-ocupacoes.csv")
G <- graph.data.frame(edge_list)
# List of degrees
G.degrees <- degree(G)