From: ············@gmail.com
Subject: Conversion to keyword
Date: 
Message-ID: <1170295102.742512.262560@a75g2000cwd.googlegroups.com>
Hello:

   Is there any way to convert from a name to a keyword?
like this (code is still under development, not finished)

(defmacro defclass-simple (class parent-class definition)
   `(defclass ,class ,parent-class
      ,(dolist (item definition)
          (let ((name (car item)))
             (append item `(:accessor name :initarg ????)))

  Because the accessor and initarg in most situation I think it would
be the same as the slot-name of the class, I would like to make the
defclass simpler.

Thanks

From: Ken Tilton
Subject: Re: Conversion to keyword
Date: 
Message-ID: <jVcwh.33$yS7.15@newsfe08.lga>
············@gmail.com wrote:
> Hello:
> 
>    Is there any way to convert from a name to a keyword?
> like this (code is still under development, not finished)
> 
> (defmacro defclass-simple (class parent-class definition)
>    `(defclass ,class ,parent-class
>       ,(dolist (item definition)
>           (let ((name (car item)))
>              (append item `(:accessor name :initarg ????)))
> 
>   Because the accessor and initarg in most situation I think it would
> be the same as the slot-name of the class, I would like to make the
> defclass simpler.

Agreed. Here is mine, if it helps (usual apology for formatting):

(defmacro defmd (class superclasses &rest mdspec)
  `(defmodel ,class (,@superclasses model)
     ,@(let (definitargs class-options slots)
         (loop with skip
             for (spec next) on mdspec
             if skip
             do (setf skip nil)
             else do (etypecase spec
                       (cons
                        (cond
                         ((keywordp (car spec))
                          (assert (find (car spec) '(:documentation
:metaclass)))
                          (push spec class-options))
                         ((find (cadr spec) '(:initarg :type :ps
:persistable :cell :initform :allocation :reader :writer :accessor
:documentation))
                          (push (apply 'defmd-canonicalize-slot spec)
slots))
                         (t ;; shortform (slotname initform &rest
slotdef-key-values)
                          (push (apply 'defmd-canonicalize-slot
                                  (list* (car spec) :initform (cadr
spec) (cddr spec))) slots))))
                       (keyword
                        (setf definitargs (append definitargs (list spec
next)))
                        (setf skip t))
                       (symbol (push (list spec :initform nil
                                       :initarg (intern (symbol-name
spec) :keyword)
                                       :accessor spec) slots)))
             finally
               (return (list* (nreverse slots)
                         (delete nil
                           (list* `(:default-initargs ,@definitargs)
                             (nreverse class-options)))))))))

I wish I had created that <gasp> ten years ago.

kenzo

-- 
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
                                  -- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
                                  -- Elwood's Mom
From: ············@gmail.com
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170299978.711887.270930@s48g2000cws.googlegroups.com>
Thanks Ken too, but yours are really sophisticated that I think I need
some time to understand it.

And then with lots of the slots init-form 0, that I made my code looks
like this:

(defun initform-0 (&rest rest)
   (loop for item in rest collect
      `(,item :initform 0)))

and

(let ((argument (initform-0 'x 'y 'w 'h 'rowgap 'colgap
                   'distb 'font 'ychar 'x-magr 'y-magr)))
  `(defclass-simple DCSLableAndBlock ()
     ((style :initform "00")
      (text  :initform "")
      ,@argument)))

for the class definition.
From: Ken Tilton
Subject: Re: Conversion to keyword
Date: 
Message-ID: <g5gwh.49$Kv2.36@newsfe12.lga>
············@gmail.com wrote:
> Thanks Ken too, but yours are really sophisticated that I think I need
> some time to understand it.

Oh, heaven-frickin-forbid you should take some time to understand 
anything. You are the MTV generation, an idea has five seconds to 
penetrate your skull or it is out! Oh, OK, I could have given you the 
(implied) syntax (of course defmodel becomes defclass):

(defmd one () two)
(defmodel one (model)
  ((two :initform nil :initarg :two :accessor two))
  (:default-initargs))

(defmd one () (two 3)):
(defmodel one (model)
   ((two :initarg :two :initform 3 :accessor two))
   (:default-initargs))

(defmd one () (two :three)):
(defmodel one (model)
  ((two :initarg :two :initform :three :accessor two)
  (:default-initargs))

(defmd one () (two :accessor too)):
(defmodel one (model) ((two :initarg :two :accessor too)) 
(:default-initargs))

(defmd one () :two 42):
(defmodel one (model)
     nil
     (:default-initargs :two 42))


That said, it is totally excellent if you ignore me and invent your own: 
you'll learn a ton that way.

kzo


-- 
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
                                   -- Elwood P. Dowd

In this world, you must be oh so smart or oh so pleasant.
                                   -- Elwood's Mom
From: ············@gmail.com
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170322551.727756.224710@v45g2000cwv.googlegroups.com>
Ken, it's definitely yours is better, but I will use it only after
thoroughly understanding it.
I might need more days to read the codes because I am not that smart I
must admit.

Still thanks for the samples.
From: ········@gmail.com
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170440718.144929.20100@l53g2000cwa.googlegroups.com>
On Feb 1, 1:35 am, ·············@gmail.com" <············@gmail.com>
wrote:
> Ken, it's definitely yours is better, but I will use it only after
> thoroughly understanding it.
> I might need more days to read the codes because I am not that smart I
> must admit.
>
> Still thanks for the samples.

this thread also has an example of two such macros written in two
different styles

     http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/
5ec446075ab25507/c681912422d05173?
lnk=gst&q=defkenny&rnum=1#c681912422d05173

hth

Nick
From: ········@gmail.com
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170440948.928253.42350@q2g2000cwa.googlegroups.com>
On Feb 2, 10:25 am, ········@gmail.com wrote:
> On Feb 1, 1:35 am, ·············@gmail.com" <············@gmail.com>
> wrote:
>
> > Ken, it's definitely yours is better, but I will use it only after
> > thoroughly understanding it.
> > I might need more days to read the codes because I am not that smart I
> > must admit.
>
> > Still thanks for the samples.
>
> this thread also has an example of two such macros written in two
> different styles
>
>      http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/
> 5ec446075ab25507/c681912422d05173?
> lnk=gst&q=defkenny&rnum=1#c681912422d05173
>

er... the link seems to be all cut up in that last post, try

   http://tinyurl.com/2gfqab

Nick



> hth
>
> Nick
From: Lars Rune Nøstdal
Subject: Re: Conversion to keyword
Date: 
Message-ID: <pan.2007.02.01.02.04.57.59203@gmail.com>
On Wed, 31 Jan 2007 17:58:22 -0800, ············@gmail.com wrote:

> Hello:
> 
>    Is there any way to convert from a name to a keyword?
> like this (code is still under development, not finished)
> 
> (defmacro defclass-simple (class parent-class definition)
>    `(defclass ,class ,parent-class
>       ,(dolist (item definition)
>           (let ((name (car item)))
>              (append item `(:accessor name :initarg ????)))
> 
>   Because the accessor and initarg in most situation I think it would
> be the same as the slot-name of the class, I would like to make the
> defclass simpler.
> 
> Thanks

cl-user> (macrolet ((test (name)
                      `(list ',name ,(intern (symbol-name name) :keyword))))
           (test hello))
(hello :hello)

..or something like that, I think.

-- 
Lars Rune Nøstdal
http://nostdal.org/
From: ············@gmail.com
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170297836.584979.197430@s48g2000cws.googlegroups.com>
Thanks...the current version is as follows

(defmacro defclass-simple (class parent-class definition)
  `(defclass ,class ,parent-class
      (loop for item in definition collect
         (let ((name (car item)))
             (append item `(:accessor ,name :initarg ,(intern (symbol-
name name) :keyword)))))))
From: Thomas A. Russ
Subject: Re: Conversion to keyword
Date: 
Message-ID: <ymilkjgbi5s.fsf@sevak.isi.edu>
·············@gmail.com" <············@gmail.com> writes:

> Thanks...the current version is as follows
> 
> (defmacro defclass-simple (class parent-class definition)
>   `(defclass ,class ,parent-class
>       (loop for item in definition collect
>          (let ((name (car item)))
>              (append item `(:accessor ,name :initarg ,(intern (symbol-
> name name) :keyword)))))))

You need a ,@ in front of the (loop ...) form.



-- 
Thomas A. Russ,  USC/Information Sciences Institute
From: Pillsy
Subject: Re: Conversion to keyword
Date: 
Message-ID: <1170348006.530647.216050@h3g2000cwc.googlegroups.com>
On Jan 31, 8:58 pm, ·············@gmail.com" <············@gmail.com>
wrote:
> Hello:

>    Is there any way to convert from a name to a keyword?
> like this (code is still under development, not finished)

> (defmacro defclass-simple (class parent-class definition)
>    `(defclass ,class ,parent-class
>       ,(dolist (item definition)
>           (let ((name (car item)))
>              (append item `(:accessor name :initarg ????)))

>   Because the accessor and initarg in most situation I think it would
> be the same as the slot-name of the class, I would like to make the
> defclass simpler.

I have the following little function for doing such things:

(defun keywordify (symbol)
   (intern (symbol-name symbol) :keyword))

so you could just do

`(:accessor name :initarg ,(keywordify name))

HTH,
Pillsy
From: Rob Warnock
Subject: Re: Conversion to keyword
Date: 
Message-ID: <8M-dnRuM7LSCl17YnZ2dnUVZ_qSrnZ2d@speakeasy.net>
Pillsy <·········@gmail.com> wrote:
+---------------
| I have the following little function for doing such things:
| 
| (defun keywordify (symbol)
|   (intern (symbol-name symbol) :keyword))
+---------------

Might run a tiny bit faster if you only lookup the package once:

  (defun keywordify (symbol)
    (intern (symbol-name symbol)
	    (load-time-value (find-package :keyword))))


-Rob

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Pascal Bourguignon
Subject: Re: Conversion to keyword
Date: 
Message-ID: <87tzy4viyj.fsf@thalassa.informatimago.com>
····@rpw3.org (Rob Warnock) writes:

> Pillsy <·········@gmail.com> wrote:
> +---------------
> | I have the following little function for doing such things:
> | 
> | (defun keywordify (symbol)
> |   (intern (symbol-name symbol) :keyword))
> +---------------
>
> Might run a tiny bit faster if you only lookup the package once:
>
>   (defun keywordify (symbol)
>     (intern (symbol-name symbol)
> 	    (load-time-value (find-package :keyword))))

No.  It might _compile_ a tiny bit faster.

KEYWORDIFY will be called at macroexpansion time, which is at
compilation time (when you have a compiler).



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush