Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Common Lisp Object System (CLOS) Syntax

  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Common Lisp Object System (CLOS) Syntax

    Lets discuss common lisp object system syntax here
    Last edited by peter; 2014-01-17 at 08:00 PM.
    AutomateCAD

  2. #2
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    I too prefer code that is more 'readable', even at the cost of some code efficiency.

    Quote Originally Posted by peter View Post
    "It's just that these days they're considered bad practice"

    I like the reddick naming convention, it is out of favor.

    I like objDatabase compared to db.

    I do not like reading abbreviations but rather read full descriptive variable names.

    I do not always agree with ms on best practice. IMHO...
    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):

    Code:
    Object objDatabase;
    
    Database db;
    As a generalization, I tend to name my variables for their Type, and /or Property name where applicable.
    "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

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    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

  4. #4
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,714
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    Quote Originally Posted by peter View Post
    I want the (vlax-put obj "color" 1) syntax so I can pass a property to the function and its new value.
    I know of no way to pass a VL Objects via ResultBuffer... Only ObjectId.
    "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

  5. #5
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    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

  6. #6
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    Quote Originally Posted by peter View Post
    propertyput(objEntity, "ColorIndex", 1)
    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.

  7. #7
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    Quote Originally Posted by BlackBox View Post
    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):

    Code:
    Object objDatabase;
    
    Database db;
    As a generalization, I tend to name my variables for their Type, and /or Property name where applicable.
    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

  8. #8
    Certifiable AUGI Addict
    Join Date
    2015-11
    Location
    Jo'burg SA
    Posts
    4,512
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    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.

  9. #9
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    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

  10. #10
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Common Lisp Object System (CLOS) Syntax

    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.

    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
    It is a place to start.
    AutomateCAD

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 17
    Last Post: 2014-02-17, 07:18 PM
  2. 2013: Common Coordinate System - Large Site Model
    By Limbatus in forum Revit Architecture - General
    Replies: 3
    Last Post: 2013-08-01, 08:53 PM
  3. Lisp to add an MText object that contains an object property
    By sheila.bjerreskov717262 in forum AutoLISP
    Replies: 7
    Last Post: 2013-07-22, 05:58 PM
  4. Replies: 10
    Last Post: 2006-10-25, 09:33 PM
  5. New to File System Object
    By T_Livingston in forum VBA/COM Interop
    Replies: 5
    Last Post: 2006-05-24, 01:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •