Instantly share code, notes, and snippets.

@hlindberg /ducks.pp
Last active Aug 29, 2015

Embed
What would you like to do?
ducks in a row - puppet
define duck($name) {
notice "duck $name"
include c
}
class c {
notice 'in c'
duck { 'duck0': name => 'mc scrooge' }
}
class a {
notice 'in a'
duck {'duck1': name => 'donald' }
include b
duck {'duck2': name => 'daisy' }
}
class b {
notice 'in b'
duck {'duck3': name => 'huey' }
duck {'duck4': name => 'dewey' }
duck {'duck5': name => 'louie' }
}
include a
@hlindberg

This comment has been minimized.

Show comment
Hide comment
@hlindberg

hlindberg Apr 4, 2014

What does this print out?

Owner

hlindberg commented Apr 4, 2014

What does this print out?

@hlindberg

This comment has been minimized.

Show comment
Hide comment
@hlindberg

hlindberg Apr 4, 2014

Answer:

Notice: Scope(Class[A]): in a
Notice: Scope(Class[B]): in b
Notice: Scope(Duck[duck1]): duck donald
Notice: Scope(Class[C]): in c
Notice: Scope(Duck[duck3]): duck huey
Notice: Scope(Duck[duck4]): duck dewey
Notice: Scope(Duck[duck5]): duck louie
Notice: Scope(Duck[duck2]): duck daisy
Notice: Scope(Duck[duck0]): duck mc scrooge
Owner

hlindberg commented Apr 4, 2014

Answer:

Notice: Scope(Class[A]): in a
Notice: Scope(Class[B]): in b
Notice: Scope(Duck[duck1]): duck donald
Notice: Scope(Class[C]): in c
Notice: Scope(Duck[duck3]): duck huey
Notice: Scope(Duck[duck4]): duck dewey
Notice: Scope(Duck[duck5]): duck louie
Notice: Scope(Duck[duck2]): duck daisy
Notice: Scope(Duck[duck0]): duck mc scrooge
@hlindberg

This comment has been minimized.

Show comment
Hide comment
@hlindberg

hlindberg Apr 4, 2014

why is mc scrooge at the end?

Owner

hlindberg commented Apr 4, 2014

why is mc scrooge at the end?

@zaphod42

This comment has been minimized.

Show comment
Hide comment
@zaphod42

zaphod42 Apr 4, 2014

mc scrooge is at the end because it is pushed onto the end of the FIFO queue to process defines. Because a and b are classes the creation of their duck resources is evaluated as soon as it evaluates the include statements inside the classes. However, mc scrooge isn't enqueued until the first duck is evaluated, which is after the a and b classes. This means that it goes to the end of the queue and so will show up last.

zaphod42 commented Apr 4, 2014

mc scrooge is at the end because it is pushed onto the end of the FIFO queue to process defines. Because a and b are classes the creation of their duck resources is evaluated as soon as it evaluates the include statements inside the classes. However, mc scrooge isn't enqueued until the first duck is evaluated, which is after the a and b classes. This means that it goes to the end of the queue and so will show up last.

@zaphod42

This comment has been minimized.

Show comment
Hide comment
@zaphod42

zaphod42 Apr 4, 2014

"the creation of their duck resources is evaluated as soon as it evaluates the include statements". To clarify, it is the creation of the resources that is done immediately, but not the evaluation of their bodies.

zaphod42 commented Apr 4, 2014

"the creation of their duck resources is evaluated as soon as it evaluates the include statements". To clarify, it is the creation of the resources that is done immediately, but not the evaluation of their bodies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment