From: Sungwoo Lim
Subject: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011005012100%sungwoo@cad.strath.ac.uk>
Hello,

How can I change the variable name incrementally?
For example,

when I get the value N as 1,2,3,...
I want to get a variable name as st1,st2,st3,...
The N is a number of strokes, so it will be changed every time
when I sketch.

I tried to change the last character of the variable only,
but first I have to change the variable name as a string (e.g. "stn"..)
then, I have to change the string as a name of variable again?
Is this correct?

(defun inc-var-name (n)
  (something to get stn)) <- ?
   ^^^^^^^^^^^^^^^^^^^^
then, I can do this:

(defun stroke-set (stn)
  (setq stn (make-stroke-info)))

How can I get the incremental variable name?
Thanks for advance.

Sungwoo

From: Jonathan BAILLEUL
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <3AFA5D69.CC92588E@labri.u-bordeaux.fr>
Sungwoo Lim a �crit :
> 
> Hello,
> 
> How can I change the variable name incrementally?
> For example,
> 
> when I get the value N as 1,2,3,...
> I want to get a variable name as st1,st2,st3,...
> The N is a number of strokes, so it will be changed every time
> when I sketch.
> 
> I tried to change the last character of the variable only,
> but first I have to change the variable name as a string (e.g. "stn"..)
> then, I have to change the string as a name of variable again?
> Is this correct?
> 
> (defun inc-var-name (n)
>   (something to get stn)) <- ?
>    ^^^^^^^^^^^^^^^^^^^^
> then, I can do this:
> 
> (defun stroke-set (stn)
>   (setq stn (make-stroke-info)))
> 
> How can I get the incremental variable name?
> Thanks for advance.
> 
> Sungwoo

What are you expecting exactly? Renaming a variable after its
declaration? 
This sounds strange, but not impossible (certainly related to symbol
properties, but I don't remember).

If you want to declare several variables at a time whose name have an
incremental part, you definitely should use a macro to calculate the
names during its expansion. I can get some code for illustrating this,
but I'm sure someone else in this group will do it before I can retrieve
my example.


-- 
----------------------------
Bailleul Jonathan
DEA Informatique
LaBRI, Universite Bordeaux I
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011044515104%sungwoo@cad.strath.ac.uk>
In article <·················@labri.u-bordeaux.fr>, Jonathan BAILLEUL
<········@labri.u-bordeaux.fr> wrote:

> What are you expecting exactly? Renaming a variable after its
> declaration? 
> This sounds strange, but not impossible (certainly related to symbol
> properties, but I don't remember).
> 
> If you want to declare several variables at a time whose name have an
> incremental part, you definitely should use a macro to calculate the
> names during its expansion. I can get some code for illustrating this,
> but I'm sure someone else in this group will do it before I can retrieve
> my example.

What I want to do is this...
When I draw one stroke, I want to make one structure for it with a name
'st1'. Then when I draw next stroke, I want to make same structure with
a name 'st2'.

Thanks, I will take a look the reference of 'symbol property' part.
Also, plz give me the sample code as well.

Sungwoo
From: Jochen Schmidt
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <9ddtcn$i2b6s$1@ID-22205.news.dfncis.de>
Sungwoo Lim wrote:

> In article <·················@labri.u-bordeaux.fr>, Jonathan BAILLEUL
> <········@labri.u-bordeaux.fr> wrote:
> 
>> What are you expecting exactly? Renaming a variable after its
>> declaration?
>> This sounds strange, but not impossible (certainly related to symbol
>> properties, but I don't remember).
>> 
>> If you want to declare several variables at a time whose name have an
>> incremental part, you definitely should use a macro to calculate the
>> names during its expansion. I can get some code for illustrating this,
>> but I'm sure someone else in this group will do it before I can retrieve
>> my example.
> 
> What I want to do is this...
> When I draw one stroke, I want to make one structure for it with a name
> 'st1'. Then when I draw next stroke, I want to make same structure with
> a name 'st2'.
> 
> Thanks, I will take a look the reference of 'symbol property' part.
> Also, plz give me the sample code as well.

Why not using a Hashtable?

Regards,
Jochen
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011401435788%sungwoo@cad.strath.ac.uk>
In article <··············@ID-22205.news.dfncis.de>, Jochen Schmidt
<···@dataheaven.de> wrote:

> Why not using a Hashtable?
> 
> Regards,
> Jochen

No specific reason...
I am not quite sure which one is better...
In fact, I have more than 90 datas with mixed types for one stroke.
The reference tell me that hashtable gives very fast search for entries.
Is that mean that using a structure will be expensive?
Thanks,

Sungwoo
From: Janis Dzerins
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <87y9s5pici.fsf@asaka.latnet.lv>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> In article <·················@labri.u-bordeaux.fr>, Jonathan BAILLEUL
> <········@labri.u-bordeaux.fr> wrote:
> 
> > What are you expecting exactly? Renaming a variable after its
> > declaration? 
> > This sounds strange, but not impossible (certainly related to symbol
> > properties, but I don't remember).
> > 
> > If you want to declare several variables at a time whose name have an
> > incremental part, you definitely should use a macro to calculate the
> > names during its expansion. I can get some code for illustrating this,
> > but I'm sure someone else in this group will do it before I can retrieve
> > my example.
> 
> What I want to do is this...
> When I draw one stroke, I want to make one structure for it with a name
> 'st1'. Then when I draw next stroke, I want to make same structure with
> a name 'st2'.

Your approach looks very wrong to me. Why do you want to assign every
structure to its own [generated] variable instead of putting (pushing)
them all in one list or array?

> Thanks, I will take a look the reference of 'symbol property' part.
> Also, plz give me the sample code as well.

Here's sample code :)

(let ((strokes ()))
  (loop ;; or something else where you get your strokes
    (push (make-stroke ...) strokes)))


-- 
Janis Dzerins

  If million people say a stupid thing it's still a stupid thing.
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011324361337%sungwoo@cad.strath.ac.uk>
In article <··············@asaka.latnet.lv>, Janis Dzerins
<·····@latnet.lv> wrote:

> Your approach looks very wrong to me. Why do you want to assign every
> structure to its own [generated] variable instead of putting (pushing)
> them all in one list or array?
> 
> > Thanks, I will take a look the reference of 'symbol property' part.
> > Also, plz give me the sample code as well.
> 
> Here's sample code :)
> 
> (let ((strokes ()))
>   (loop ;; or something else where you get your strokes
>     (push (make-stroke ...) strokes)))

Yes, you are right. I should put those stroke structure into a list
using PUSH. However, it is useful for only one object (shape) which
includes multi-strokes. If I sketch a new object (B), then I have to
store that structure with other name.

For example,

Object (S) - Object (A) - stroke
           |            |
           |            - stroke
           |            |
           |            - stroke
           |            |
           |            - stroke
           |             ...
           - Object (B) - stroke
                        |
                        - stroke
                        |
                        - stroke
                        ...

These objects A and B could be child-element of other object
hierarchically. So I still need a separated variable...

> (let ((strokes ()))
>   (loop ;; or something else where you get your strokes
>     (push (make-stroke ...) strokes)))

Yes, this is good example for me, but still I need a method to
incrementally change the name of 'strokes'.

Thanks for your help. =)

Sungwoo
From: Marco Antoniotti
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <y6czocl483n.fsf@octagon.mrl.nyu.edu>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> In article <··············@asaka.latnet.lv>, Janis Dzerins
> <·····@latnet.lv> wrote:
> 
> > Your approach looks very wrong to me. Why do you want to assign every
> > structure to its own [generated] variable instead of putting (pushing)
> > them all in one list or array?
> > 
> > > Thanks, I will take a look the reference of 'symbol property' part.
> > > Also, plz give me the sample code as well.
> > 
> > Here's sample code :)
> > 
> > (let ((strokes ()))
> >   (loop ;; or something else where you get your strokes
> >     (push (make-stroke ...) strokes)))
> 
> Yes, you are right. I should put those stroke structure into a list
> using PUSH. However, it is useful for only one object (shape) which
> includes multi-strokes. If I sketch a new object (B), then I have to
> store that structure with other name.
> 
> For example,
> 
> Object (S) - Object (A) - stroke
>            |            |
>            |            - stroke
>            |            |
>            |            - stroke
>            |            |
>            |            - stroke
>            |             ...
>            - Object (B) - stroke
>                         |
>                         - stroke
>                         |
>                         - stroke
>                         ...
> 
> These objects A and B could be child-element of other object
> hierarchically. So I still need a separated variable...
> 
> > (let ((strokes ()))
> >   (loop ;; or something else where you get your strokes
> >     (push (make-stroke ...) strokes)))
> 
> Yes, this is good example for me, but still I need a method to
> incrementally change the name of 'strokes'.

No you do not.  You are CREATING objects which can have an associated
list of STROKES.  You can "name" each object, but you do not need
"variables".

Look

	(defclass object ()
           ((sub-objects :accessor sub-objects)
            (parent-object :accessor parent-object)
            (strokes :accessor strokes :initform () :type list)
            ))

When you create an object you eventually do

	(make-instance 'object)

When you start accumulating strokes you can do

	(let ((the-object (get-the-object-you-created-one-way-or-the-other)))
          (loop ;; or something else where you get your strokes
                (push (make-stroke ...) (strokes the-object))))

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group	tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA			http://bioinformatics.cat.nyu.edu
	       "Hello New York! We'll do what we can!"
			Bill Murray in `Ghostbusters'.
From: Janis Dzerins
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <87u22tp75b.fsf@asaka.latnet.lv>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> In article <··············@asaka.latnet.lv>, Janis Dzerins
> <·····@latnet.lv> wrote:
> 
> > Your approach looks very wrong to me. Why do you want to assign every
> > structure to its own [generated] variable instead of putting (pushing)
> > them all in one list or array?
> > 
> > > Thanks, I will take a look the reference of 'symbol property' part.
> > > Also, plz give me the sample code as well.
> > 
> > Here's sample code :)
> > 
> > (let ((strokes ()))
> >   (loop ;; or something else where you get your strokes
> >     (push (make-stroke ...) strokes)))
> 
> Yes, you are right. I should put those stroke structure into a list
> using PUSH. However, it is useful for only one object (shape) which
> includes multi-strokes. If I sketch a new object (B), then I have to
> store that structure with other name.
> 
> For example,
> 
> Object (S) - Object (A) - stroke
>            |            |
>            |            - stroke
>            |            |
>            |            - stroke
>            |            |
>            |            - stroke
>            |             ...
>            - Object (B) - stroke
>                         |
>                         - stroke
>                         |
>                         - stroke
>                         ...
> 
> These objects A and B could be child-element of other object
> hierarchically. So I still need a separated variable...

No, you still don't need seperate variable.

Here's some sample code:

(defclass shape ()
  ((strokes :initform () :initarg :strokes :accessor shape-strokes)))

When you get a list of strokes, you create an instance of SHAPE and
put it into shapes list (some more pseudo code as requested):

(let ((shapes ())
      (strokes ())
      (drawing nil)
      last-x last-y)
  (loop
    (event-case
      (:mouse-down (x y)
         (setq drawing t)
         (setq last-x x last-y y))
      (:mouse-move (x y)
         (when drawing
           (push (make-stroke :start-x last-x :start-y last-y
                              :end-x x :end-y y)
                 strokes)
           (setq last-x x last-y y)))
      (:mouse-up (x y)
         (when drawing
           (push (make-stroke :start-x last-x :start-y last-y
                              :end-x x :end-y y)
                 strokes)
           (push (make-instance 'shape :strokes (reverse strokes)) shapes)
           (setq strokes ())
           (setq drawing nil)))
      (... other event processing...))))

Now you could put all shapes in some other container (scene or
whatever you have there).

> > (let ((strokes ()))
> >   (loop ;; or something else where you get your strokes
> >     (push (make-stroke ...) strokes)))
> 
> Yes, this is good example for me, but still I need a method to
> incrementally change the name of 'strokes'.

And I still don't get why you want to keep stuff in different
variables where you don't even know how to access them...

-- 
Janis Dzerins

  If million people say a stupid thing it's still a stupid thing.
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011658587070%sungwoo@cad.strath.ac.uk>
In article <··············@asaka.latnet.lv>, Janis Dzerins
<·····@latnet.lv> wrote:

> No, you still don't need seperate variable.
> 
> Here's some sample code:
> 
> (defclass shape ()
>   ((strokes :initform () :initarg :strokes :accessor shape-strokes)))
> 
> When you get a list of strokes, you create an instance of SHAPE and
> put it into shapes list (some more pseudo code as requested):
> 
> (let ((shapes ())
>       (strokes ())
>       (drawing nil)
>       last-x last-y)
>   (loop
>     (event-case
>       (:mouse-down (x y)
>          (setq drawing t)
>          (setq last-x x last-y y))
>       (:mouse-move (x y)
>          (when drawing
>            (push (make-stroke :start-x last-x :start-y last-y
>                               :end-x x :end-y y)
>                  strokes)
>            (setq last-x x last-y y)))
>       (:mouse-up (x y)
>          (when drawing
>            (push (make-stroke :start-x last-x :start-y last-y
>                               :end-x x :end-y y)
>                  strokes)
>            (push (make-instance 'shape :strokes (reverse strokes)) shapes)
>            (setq strokes ())
>            (setq drawing nil)))
>       (... other event processing...))))
> 
> Now you could put all shapes in some other container (scene or
> whatever you have there).
> 
> > > (let ((strokes ()))
> > >   (loop ;; or something else where you get your strokes
> > >     (push (make-stroke ...) strokes)))
> > 
> > Yes, this is good example for me, but still I need a method to
> > incrementally change the name of 'strokes'.
> 
> And I still don't get why you want to keep stuff in different
> variables where you don't even know how to access them...

I see. Now I got some idea about that.
Thanks for your help. =)

Sungwoo
From: ···············@solibri.com
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <u7kzpxvfj.fsf@solibri.com>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> What I want to do is this...
> When I draw one stroke, I want to make one structure for it with a name
> 'st1'. Then when I draw next stroke, I want to make same structure with
> a name 'st2'.

I'd think it would be easier to store your structures in a vector, and
access it with aref. 

-- 
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011412194179%sungwoo@cad.strath.ac.uk>
In article <·············@solibri.com>, <···············@solibri.com>
wrote:

> I'd think it would be easier to store your structures in a vector, and
> access it with aref.

Oops... that easy... >.<
Thanks, =)

Sungwoo
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011435087126%sungwoo@cad.strath.ac.uk>
In article <·············@solibri.com>, <···············@solibri.com>
wrote:

> I'd think it would be easier to store your structures in a vector, and
> access it with aref.

Oh well... I confused.
Putting a bunch of information structure into a vector (or list) seems
good unless I draw another new object (which included multi-strokes).
Thus, I still need a method for incremental variable name...
Thanks anyway.

Sungwoo
From: Marco Antoniotti
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <y6c3dad17ok.fsf@octagon.mrl.nyu.edu>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> In article <·············@solibri.com>, <···············@solibri.com>
> wrote:
> 
> > I'd think it would be easier to store your structures in a vector, and
> > access it with aref.
> 
> Oh well... I confused.
> Putting a bunch of information structure into a vector (or list) seems
> good unless I draw another new object (which included multi-strokes).
> Thus, I still need a method for incremental variable name...

I see signs of TclPerlite here :)

Are you absolutely sure you need "variables" as opposed to "names"?

Cheers

-- 
Marco Antoniotti ========================================================
NYU Courant Bioinformatics Group	tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                 fax  +1 - 212 - 995 4122
New York, NY 10003, USA			http://bioinformatics.cat.nyu.edu
	       "Hello New York! We'll do what we can!"
			Bill Murray in `Ghostbusters'.
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011811279733%sungwoo@cad.strath.ac.uk>
In article <···············@octagon.mrl.nyu.edu>, Marco Antoniotti
<·······@cs.nyu.edu> wrote:

> Sungwoo Lim <·······@cad.strath.ac.uk> writes:
> 
> > In article <·············@solibri.com>, <···············@solibri.com>
> > wrote:
> > 
> > > I'd think it would be easier to store your structures in a vector, and
> > > access it with aref.
> > 
> > Oh well... I confused.
> > Putting a bunch of information structure into a vector (or list) seems
> > good unless I draw another new object (which included multi-strokes).
> > Thus, I still need a method for incremental variable name...
> 
> I see signs of TclPerlite here :)
> 
> Are you absolutely sure you need "variables" as opposed to "names"?
> 
> Cheers

Not any more. =)
Cheers
From: Hannah Schroeter
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <9dea81$84r$1@c3po.schlund.de>
Hello!

In article <··························@cad.strath.ac.uk>,
Sungwoo Lim  <·······@cad.strath.ac.uk> wrote:
>[...]

>Oh well... I confused.
>Putting a bunch of information structure into a vector (or list) seems
>good unless I draw another new object (which included multi-strokes).
>Thus, I still need a method for incremental variable name...
>Thanks anyway.

No.

(defvar *object-list* ())

(defun draw-one-object ()
  (let ((object-strokes ()))
    (loop ...
          do (push one-stroke object-strokes))
    (push object-strokes *object-list*)))

; *object-list* is a list of objects and
; an object is a list of single strokes.
; if the object consists of a single stroke, it's a one-element list.

Of course, you could use an adjustable array with fill-pointer if
you need constant time access to single objects or single strokes within
an object, or even different methods of retrieving objects, such as:
each object has a unique name (a string), so

(defvar *object-list* (make-hash-table :test 'equal))

and the strokes should be constant-time accessable, so

(defun draw-one-object ()
  (let ((object-strokes (make-array '(0) :adjustable t :fill-pointer t)))
    (loop ...
          do (vector-push-extend stroke object-strokes))
    (setf (gethash object-name *object-list*) object-strokes)))

Kind regards,

Hannah.
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011725574885%sungwoo@cad.strath.ac.uk>
In article <············@c3po.schlund.de>, Hannah Schroeter
<······@schlund.de> wrote:

> (defvar *object-list* ())
> 
> (defun draw-one-object ()
>   (let ((object-strokes ()))
>     (loop ...
>           do (push one-stroke object-strokes))
>     (push object-strokes *object-list*)))
> 
> ; *object-list* is a list of objects and
> ; an object is a list of single strokes.
> ; if the object consists of a single stroke, it's a one-element list.
> 
> Of course, you could use an adjustable array with fill-pointer if
> you need constant time access to single objects or single strokes within
> an object, or even different methods of retrieving objects, such as:
> each object has a unique name (a string), so
> 
> (defvar *object-list* (make-hash-table :test 'equal))
> 
> and the strokes should be constant-time accessable, so
> 
> (defun draw-one-object ()
>   (let ((object-strokes (make-array '(0) :adjustable t :fill-pointer t)))
>     (loop ...
>           do (vector-push-extend stroke object-strokes))
>     (setf (gethash object-name *object-list*) object-strokes)))
> 
> Kind regards,
> 
> Hannah.

Yeap yeap,
I got it. 
Thanks, =)

Sungwoo
From: ···············@solibri.com
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <u4rutxp2v.fsf@solibri.com>
Sungwoo Lim <·······@cad.strath.ac.uk> writes:

> In article <·············@solibri.com>, <···············@solibri.com>
> wrote:
> 
> > I'd think it would be easier to store your structures in a vector, and
> > access it with aref.
> 
> Oh well... I confused.
> Putting a bunch of information structure into a vector (or list) seems
> good unless I draw another new object (which included multi-strokes).
> Thus, I still need a method for incremental variable name...
> Thanks anyway.

So why not have a list of objects, each of which includes a vector of
your stroke structures stored in some convenient field? There are few
limits on how many levels of structure you can store anywhere. Think
about those Russian dolls within dolls within dolls within dolls
within ...

Generally, inventing names on the fly is a little cumbersome: OK, you
created a variable called st555 and stored something there. Now, how
does any other part of your program know of the existence of such a
name? It is often easier to put such stuff in a sequence which can be
accessed by an easily calculated index or stepped through from end to end.

On the other hand, if you really need those fresh names, what do you
need that you don't get from gensym or gentemp?

-- 
From: Sungwoo Lim
Subject: Re: [Q] incremental change of a variable name?
Date: 
Message-ID: <100520011529302769%sungwoo@cad.strath.ac.uk>
In article <·············@solibri.com>, <···············@solibri.com>
wrote:

> So why not have a list of objects, each of which includes a vector of
> your stroke structures stored in some convenient field? There are few
> limits on how many levels of structure you can store anywhere. Think
> about those Russian dolls within dolls within dolls within dolls
> within ...

Sounds complicated, but I understand that is easier.

> Generally, inventing names on the fly is a little cumbersome: OK, you
> created a variable called st555 and stored something there. Now, how
> does any other part of your program know of the existence of such a
> name? It is often easier to put such stuff in a sequence which can be
> accessed by an easily calculated index or stepped through from end to end.

I agree. 
Thanks again. =)

Sungwoo