As was mentioned very briefly on IRC[1], it might be nice if defstruct
objects (a.k.a. struct-basis, a.k.a. PersistentStructMap$Def) were
callable.
Currently you can:

user=> (defstruct point :x :y)
#=(var user/point)
user=> (struct point 42 11)
{:x 42, :y 11}

You can also use struct-map instead of struct, but I think the above
case is far more common.  So why not make it the default if you call
the struct-basis?  The attached patch allows:

user=> (point 42 11)
{:x 42, :y 11}

This is less wordy and has a nice declarative ring to it.

--Chouser

1. http://clojure-log.n01se.net/date/2008-10-22.html#15:20

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

commit 7184734148c4961c4696ad968f53bb53d589e595
Author: Chouser <[EMAIL PROTECTED]>
Date:   Tue Nov 4 23:59:13 2008 -0500

    PersistentStructMap$Def extends AFn

diff --git a/src/jvm/clojure/lang/PersistentStructMap.java b/src/jvm/clojure/lang/PersistentStructMap.java
index 055448c..5fd868a 100644
--- a/src/jvm/clojure/lang/PersistentStructMap.java
+++ b/src/jvm/clojure/lang/PersistentStructMap.java
@@ -18,7 +18,7 @@ import java.io.Serializable;
 
 public class PersistentStructMap extends APersistentMap{
 
-public static class Def implements Serializable{
+public static class Def extends AFn implements Serializable{
 	final ISeq keys;
 	final IPersistentMap keyslots;
 
@@ -26,6 +26,153 @@ public static class Def implements Serializable{
 		this.keys = keys;
 		this.keyslots = keyslots;
 	}
+
+	public Object invoke(Object arg1) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7)
+			throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13)
+			throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14)
+			throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15,arg16} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16, Object arg17) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16, Object arg17, Object arg18) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,
+                                                                     arg18} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16, Object arg17, Object arg18, Object arg19) throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,
+                                                                     arg18,arg19} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20)
+			throws Exception{
+		return construct(this, ArraySeq.create( new Object[]{arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,
+                                                                     arg10,arg11,arg12,arg13,arg14,arg15,arg16,arg17,
+                                                                     arg18,arg19,arg20} ));
+	}
+
+	public Object invoke(Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6, Object arg7,
+                             Object arg8, Object arg9, Object arg10, Object arg11, Object arg12, Object arg13, Object arg14,
+                             Object arg15, Object arg16, Object arg17, Object arg18, Object arg19, Object arg20,
+                             Object... args)
+			throws Exception{
+		Object[] vals = new Object[args.length + 20];
+		vals[0] = arg1;
+		vals[1] = arg2;
+		vals[2] = arg3;
+		vals[3] = arg4;
+		vals[4] = arg5;
+		vals[5] = arg6;
+		vals[6] = arg7;
+		vals[7] = arg8;
+		vals[8] = arg9;
+		vals[9] = arg10;
+		vals[10] = arg11;
+		vals[11] = arg12;
+		vals[12] = arg13;
+		vals[13] = arg14;
+		vals[14] = arg15;
+		vals[15] = arg16;
+		vals[16] = arg17;
+		vals[17] = arg18;
+		vals[18] = arg19;
+		vals[19] = arg20;
+		System.arraycopy(args, 0, vals, 20, args.length);
+		return construct(this, ArraySeq.create( vals ));
+	}
 }
 
 final Def def;

Reply via email to