Re: Dictionary:embedInStream requires inval to be a Dictionary, why?

rohrhuber-g/[email protected] Sat, 11 Jan 2020 15:39:20 +0000
Newsgroups gmane.comp.audio.supercollider.devel
Message-ID <[email protected]>

> On 11. Jan 2020, at 11:00, [email protected] wrote:
> 
> 
> Is there a good reason for the following discrepancy?
> 
> p = Prand([(a: 1), (a: 2)], inf).asStream;
> 
> p.next;  // ok
> p.next(());  // ok
> p.next(0);  // Message 'putAll' not understood.
> 
> The current logic assumes that there is never any reason for a pattern
> to return an event, other than to insert the returned the event's
> values into the event being passed in. While Dictionary:embedInStream
> allows inval to be nil, it strictly requires that any other inval
> absolutely must be a dictionary, no exception allowed.
> 
> But I did have a case just now where I needed to pass a number into a
> stream, but the stream needs to return events that are being used as
> object prototypes.
> 
> Currently, this use case is forbidden, and I can't see a good reason
> why. I worked around it by passing the numeric value conditionally,
> but... I dunno, it seems a bit rude of Dictionary:embedInStream to
> behave this way.
> 
> ^if(event.isNil) { this } { event.copy.putAll(this) }.yield
> 
> Should this not be as follows?
> 
> ^if(event.respondsTo(\putAll)) { event.copy.putAll(this) } { this }.yield


I think it would be better to separate the interface here and find a verb that corresponds to  “this.copy.putAll(event)”.

Something like:

embedInStream { arg event;
		var func = this.at(\embedInStream);
		if(func.notNil) { ^func.value(this, event) };
		^event.overwriteWith(this).yield
	}
	
Dictionary:

overwriteWith { arg dict;
	^this.copy.putAll(dict)
}


Object:

overwriteWith { arg dict;
	^dict
}












_______________________________________________
sc-dev mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-dev/
search: http://www.listarc.bham.ac.uk/lists/sc-dev/search/