Skip to content

Instantly share code, notes, and snippets.

@Sgeo
Created January 16, 2013 16:05
Show Gist options
  • Save Sgeo/4548336 to your computer and use it in GitHub Desktop.
Save Sgeo/4548336 to your computer and use it in GitHub Desktop.
DynamicVariable subclass: #DynamicGeneratorVar
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Sgeo-DynamicGenerator'!
!DynamicGeneratorVar commentStamp: 'SethJGold 1/14/2013 06:41' prior: 0!
DynamicGeneratorVar holds the current DynamicGenerator in use. Should not be used directly by client code.!
Generator subclass: #DynamicGenerator
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Sgeo-DynamicGenerator'!
!DynamicGenerator commentStamp: 'SethJGold 1/14/2013 06:45' prior: 0!
Similar to a Generator, but the class allows for yield:, which calls yield on the DynamicGenerator currently in scope. This allows for functions that use the current generator which don't need to be explicitly passed a Generator, a.la Racket generators.!
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
DynamicGenerator class
instanceVariableNames: ''!
!DynamicGenerator class methodsFor: 'as yet unclassified' stamp: 'SethJGold 1/14/2013 06:49'!
currentGenerator
^ DynamicGeneratorVar value.! !
!DynamicGenerator class methodsFor: 'as yet unclassified' stamp: 'SethJGold 1/14/2013 06:47'!
on: aBlock
^ super on: [:gen | DynamicGeneratorVar value: gen during: aBlock. ]. ! !
!DynamicGenerator class methodsFor: 'as yet unclassified' stamp: 'SethJGold 1/14/2013 06:50'!
yield: anObject
^ self currentGenerator yield: anObject.! !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment