Lets discuss common lisp object system syntax here
![]() |
|
![]() |
|
![]() |
|
![]() |
Lets discuss common lisp object system syntax here
Last edited by peter; 2014-01-17 at 08:00 PM.
AutomateCAD
I too prefer code that is more 'readable', even at the cost of some code efficiency.
To my mind, objDatabase is actually less descript, if the Type being referenced is Database, and not Object (we're coding in object-oriented languages, never mind Dynamic Type):
As a generalization, I tend to name my variables for their Type, and /or Property name where applicable.Code:Object objDatabase; Database db;
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
Never mind the minutia...
I am trying to find the correct syntax for passing an expression to a function. Like the predicate, action, func expressions.
I want to create the ability to pass an expression to a .net function and have it be a wrapper that evaluates it.
So much of the code is redundant, with maybe one or two lines different...
I want to pass the two lines as an argument.
I here in net 5.0 they are returning the compile at runtime evaluate expression like from vb6.
Currently most syntax in .net corresponds to the (vla-put-color obj 1) in lisp. I want the (vlax-put obj "color" 1) syntax so I can pass a property to the function and its new value.
And not just the gettype.getproperties(), but also the specific properties for the specific object I am passing.
On the previous topic...
As I understand it... the database and everything else in object oriented programming for that matter is an object.
I like obj, col, dbl, str, lst, etc... I tried coming up with different prefixes depending on the type of object, but because we have too many cooks in the kitchen, with syntax and functions all over the place
I reverted back to the obj prefix. It is just the way I like to read it.
P=
I have the
AutomateCAD
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
I understand that you cannot use com vla-objects in .net...
What I was getting at was a way to specify the property name as a variable.
objEntity.ColorIndex = 1
Is the usual way in .net to set a variable
propertyput(objEntity, "ColorIndex", 1)
Is what I want to be able to do.
That way I can pass the property name and value to the .net function from lisp and manipulate the .net object.
Peter
AutomateCAD
That's called message-passing, and it's actually the way most OOP is done in Lisp. E.g. Common Lisp's CLOS (Common Lisp Object System) is designed exactly like this: http://www.cs.northwestern.edu/acade...dings/clos.php And it's also how Vital Lisp originally implemented the tie-in onto ActiveX (vlax-put, vlax-get & vlax-invoke).
You're absolutely on the correct track. I was thinking along the same lines. It should even be possible to use reflection so you don't need to program in every method/property through something like a switch statement.
I have been thinking about this discussion.
My thoughts are I avoid abbreviations.
So
DataBase dataBase;
or
Database objDataBase;
would be my preference.
Scott Mcfarlanes class names at AU this year (c# code best practices) used the
Database database;
style
I would like to work with the contributors of these threads to find some middle ground in our variable naming styles that we could all use.
I find abbreviations cryptic and difficult to understand unless I write them.
The idea here is to help everyone understand, especially newcomers...
Thoughts?
AutomateCAD
I definitely agree that in most cases abbreviations could make for less readable code. It's just that so many of us are "used to" some form of abbreviation - especially those of use who've come from the time when your variables had a maximum name-length (or like in AutoLisp using extra RAM for longer names). Of course that's no excuse for using cryptic names.
I try to work on the principle where I name a function and/or variable such that they wouldn't need any comment to make it clear as to what's happening in the code. Though I do find myself sometimes falling back to old habits. Where I'm not too sure though is if the name needs to include the type-info, for me it makes less sense in a statistic typed language (like C#, not using var) than in a dynamic typed language (like Lisp). But even then I'd say that rather loose the type from the name if that might make the understanding better. E.g. Say you want to store a list of layer names (perhaps selected by the user through a dialog), IMO calling that lstLayers is less readable than simply calling it Layers.
Another thing which I hope I can someday un-learn is to use descriptive names instead of generalizations. E.g. how many times have I seen (and used myself) a variable name like LST to hold a list of values? Even a better (though not descriptive enough) name would have been Values. Best would be to name it according to what those values would be used for, e.g. a list of layer names should then rather be called Layers.
I use lstSublist or lstPoint in my lisp programming.
I do not use abbreviations any more and I agree with:
" I name a function and/or variable such that they wouldn't need any comment to make it clear as to what's happening in the code"
lstOfStrings
The other thing I have been promoting is a verb last function or sub naming convention like SplashScreenShow compared to ShowSplashScreen.
Or AttributesGet compared to GetAttributes. Which to my view is backwards and makes it difficult to organize code alphabetically.
You end up with all the get functions together instead of all of the attributes functions together...
WHat is you feeling on
Dim objDatabase as Database
or
Dim dataBase as Database
?
Peter
AutomateCAD
On the topic CLOS and trying to create the ability to change properties with a general function that accepts the object, propertyname and newvalue
Here are two general functions to get and put .net properties from lisp using .net.
This is copied from a thread I participated in on the LISP list a few months ago.
It is a place to start.Code:Imports System Imports System.Reflection Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Public Class LISPClass ' syntax (PropertyPut (entlast) "width" 10.0) <LispFunction("PropertyPut")> _ Public Function PropertyPut(ByVal rbfLISPArguments As ResultBuffer) On Error GoTo OnError Dim arrLISPArguments As TypedValue() = rbfLISPArguments.AsArray If arrLISPArguments.Length = 3 Then Dim oidSelection As ObjectId = arrLISPArguments(0).Value Dim strPropertyName As String = arrLISPArguments(1).Value Dim objValue As Object = arrLISPArguments(2).Value Dim objDocument As Document = Application.DocumentManager.MdiActiveDocument Using objTransaction As Transaction = objDocument.Database.TransactionManager.StartTransaction() Dim objSelection As Entity = CType(oidSelection.GetObject(OpenMode.ForWrite), Entity) Dim lstProperties As IList(Of PropertyInfo) = New List(Of PropertyInfo)(objSelection.GetType().GetProperties()) Dim intIndex As Integer = PropertyInfoAvailable(lstProperties, strPropertyName) If Not intIndex = Nothing Then Dim infProperty As PropertyInfo = lstProperties.Item(intIndex) If infProperty.CanRead = True And infProperty.CanWrite = True Then infProperty.SetValue(objSelection, objValue, Nothing) objTransaction.Commit() objTransaction.Dispose() Return New TypedValue(LispDataType.T_atom, -1) End If End If objTransaction.Dispose() End Using End If OnError: Return New TypedValue(LispDataType.Nil, -1) End Function ' syntax (PropertyGet (entlast) "width") <LispFunction("PropertyGet")> _ Public Function PropertyGet(ByVal rbfLISPArguments As ResultBuffer) On Error GoTo OnError Dim arrLISPArguments As TypedValue() = rbfLISPArguments.AsArray If arrLISPArguments.Length = 2 Then Dim oidSelection As ObjectId = arrLISPArguments(0).Value Dim strPropertyName As String = arrLISPArguments(1).Value Dim objDocument As Document = Application.DocumentManager.MdiActiveDocument Using objTransaction As Transaction = objDocument.Database.TransactionManager.StartTransaction() Dim objSelection As Entity = CType(oidSelection.GetObject(OpenMode.ForRead), Entity) Dim lstProperties As IList(Of PropertyInfo) = New List(Of PropertyInfo)(objSelection.GetType().GetProperties()) Dim intIndex As Integer = PropertyInfoAvailable(lstProperties, strPropertyName) If Not intIndex = Nothing Then Dim infProperty As PropertyInfo = lstProperties.Item(intIndex) If infProperty.CanRead = True And infProperty.CanWrite = True Then Dim objValue As Object = infProperty.GetValue(objSelection, Nothing, Nothing, Nothing, Nothing) objTransaction.Commit() objTransaction.Dispose() Return objValue End If End If objTransaction.Dispose() End Using End If OnError: Return New TypedValue(LispDataType.Nil, -1) End Function Public Shared Function PropertyInfoAvailable(ByVal lstProperties As IList(Of PropertyInfo), ByVal strProperty As String) On Error GoTo OnError For Each infProperty As PropertyInfo In lstProperties If infProperty.Name.ToString.ToUpper = strProperty.ToUpper Then Return lstProperties.IndexOf(infProperty) End If Next OnError: Return Nothing End Function
AutomateCAD