Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Jan Burse Newsgroups: comp.lang.java.programmer Subject: Re: Immutable Datastructures with good Sharing Date: Sat, 05 Nov 2011 19:30:44 +0100 Organization: albasani.net Lines: 56 Message-ID: References: <4839047.311.1320512815263.JavaMail.geo-discussion-forums@pref15> <24CdnZZfrM8C5SjTnZ2dnUVZ_qmdnZ2d@posted.palinacquisition> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.albasani.net +JRAT6WbaMBOS9bEks2i3IED+cGPyFWWgCPNdwn4Ca7XkjxxywXSGySSr3Kd81y0Q7cBiJm7ySyu9rs+X8CmPg== NNTP-Posting-Date: Sat, 5 Nov 2011 18:30:49 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="vdzZJy17gcBWNdsNBahvmbX0/s2iXPhXKHVtZYz3B7TQyAhyaG+COkZRKqojfqTvq7UhOxgnc+W+N8oZwyVV7zrSCACjDyvJTN5LJeYXyCX3lAiI08Fdwh3PXBOABZ2r"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20110928 Firefox/7.0.1 SeaMonkey/2.4.1 In-Reply-To: Cancel-Lock: sha1:kAwssT1uuDMuOLQiLGOKFOLIIvw= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:9582 Stefan Ram schrieb: > In the functional lanugage it is exactly the other way > round: It has a result specified, but no effect specified. I admit that the question might need some out of the box thinking, especially when somebody makes a strict divide between Java (destructive, etc..) and functional programming (non-destructive, etc..). But I am looking for: Some stack class, where: (Easy) pop() creates a new immutable stack push() creates a new immutable stack With good sharing. Some queue class, where: (Hard?) enqueue() creates a new immutable queue dequeue() creates a new immutable queue With good sharing. All of that in !Java!. The stack is quite easy, a good indicative that something is immutable are the keywords final before field variables: public class Stack { final Object element; final Stack next; Stack(e, n) { element = e; next = n; } public Stack push(Object e) { return new Stack(e,this); } public Object top() { return element; } public Stack pop() { return next; } } But how about the Queue? Best Regards P.S.: In LISP one just uses the CONS for push, the CAR for top, and the CDR for pop.